fix one typo spotted by Debian's lintian tool
[collectd.git] / src / openvpn.c
1 /**
2  * collectd - src/openvpn.c
3  * Copyright (C) 2008       Doug MacEachern
4  * Copyright (C) 2009,2010  Florian octo Forster
5  * Copyright (C) 2009       Marco Chiappero
6  * Copyright (C) 2009       Fabian Schuh
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation; only version 2 of the License is applicable.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  *
21  * Authors:
22  *   Doug MacEachern <dougm at hyperic.com>
23  *   Florian octo Forster <octo at collectd.org>
24  *   Marco Chiappero <marco at absence.it>
25  *   Fabian Schuh <mail at xeroc.org>
26  **/
27
28 #include "collectd.h"
29
30 #include "common.h"
31 #include "plugin.h"
32
33 #define V1STRING "Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since\n"
34 #define V2STRING "HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t)\n"
35 #define V3STRING "HEADER CLIENT_LIST Common Name Real Address Virtual Address Bytes Received Bytes Sent Connected Since Connected Since (time_t)\n"
36 #define V4STRING "HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username\n"
37 #define VSSTRING "OpenVPN STATISTICS\n"
38
39
40 struct vpn_status_s
41 {
42         char *file;
43         enum
44         {
45                 MULTI1 = 1, /* status-version 1 */
46                 MULTI2,     /* status-version 2 */
47                 MULTI3,     /* status-version 3 */
48                 MULTI4,     /* status-version 4 */
49                 SINGLE = 10 /* currently no versions for single mode, maybe in the future */
50         } version;
51         char *name;
52 };
53 typedef struct vpn_status_s vpn_status_t;
54
55 static vpn_status_t **vpn_list = NULL;
56 static int vpn_num = 0;
57
58 static _Bool new_naming_schema = 0;
59 static _Bool collect_compression = 1;
60 static _Bool collect_user_count  = 0;
61 static _Bool collect_individual_users  = 1;
62
63 static const char *config_keys[] =
64 {
65         "StatusFile",
66         "Compression", /* old, deprecated name */
67         "ImprovedNamingSchema",
68         "CollectCompression",
69         "CollectUserCount",
70         "CollectIndividualUsers"
71 };
72 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
73
74
75 /* Helper function
76  * copy-n-pasted from common.c - changed delim to ","  */
77 static int openvpn_strsplit (char *string, char **fields, size_t size)
78 {
79         size_t i;
80         char *ptr;
81         char *saveptr;
82
83         i = 0;
84         ptr = string;
85         saveptr = NULL;
86         while ((fields[i] = strtok_r (ptr, ",", &saveptr)) != NULL)
87         {
88                 ptr = NULL;
89                 i++;
90
91                 if (i >= size)
92                         break;
93         }
94
95         return (i);
96 } /* int openvpn_strsplit */
97
98 /* dispatches number of users */
99 static void numusers_submit (const char *pinst, const char *tinst,
100                 gauge_t value)
101 {
102         value_t values[1];
103         value_list_t vl = VALUE_LIST_INIT;
104
105         values[0].gauge = value;
106
107         vl.values = values;
108         vl.values_len = STATIC_ARRAY_SIZE (values);
109         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
110         sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
111         sstrncpy (vl.type, "users", sizeof (vl.type));
112         if (pinst != NULL)
113                 sstrncpy (vl.plugin_instance, pinst, sizeof (vl.plugin_instance));
114         if (tinst != NULL)
115                 sstrncpy (vl.type_instance, tinst, sizeof (vl.type_instance));
116
117         plugin_dispatch_values (&vl);
118 } /* void numusers_submit */
119
120 /* dispatches stats about traffic (TCP or UDP) generated by the tunnel
121  * per single endpoint */
122 static void iostats_submit (const char *pinst, const char *tinst,
123                 derive_t rx, derive_t tx)
124 {
125         value_t values[2];
126         value_list_t vl = VALUE_LIST_INIT;
127
128         values[0].derive = rx;
129         values[1].derive = tx;
130
131         /* NOTE ON THE NEW NAMING SCHEMA:
132          *       using plugin_instance to identify each vpn config (and
133          *       status) file; using type_instance to identify the endpoint
134          *       host when in multimode, traffic or overhead when in single.
135          */
136
137         vl.values = values;
138         vl.values_len = STATIC_ARRAY_SIZE (values);
139         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
140         sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
141         if (pinst != NULL)
142                 sstrncpy (vl.plugin_instance, pinst,
143                                 sizeof (vl.plugin_instance));
144         sstrncpy (vl.type, "if_octets", sizeof (vl.type));
145         if (tinst != NULL)
146                 sstrncpy (vl.type_instance, tinst, sizeof (vl.type_instance));
147
148         plugin_dispatch_values (&vl);
149 } /* void traffic_submit */
150
151 /* dispatches stats about data compression shown when in single mode */
152 static void compression_submit (const char *pinst, const char *tinst,
153                 derive_t uncompressed, derive_t compressed)
154 {
155         value_t values[2];
156         value_list_t vl = VALUE_LIST_INIT;
157
158         values[0].derive = uncompressed;
159         values[1].derive = compressed;
160
161         vl.values = values;
162         vl.values_len = STATIC_ARRAY_SIZE (values);
163         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
164         sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
165         if (pinst != NULL)
166                 sstrncpy (vl.plugin_instance, pinst,
167                                 sizeof (vl.plugin_instance));
168         sstrncpy (vl.type, "compression", sizeof (vl.type));
169         if (tinst != NULL)
170                 sstrncpy (vl.type_instance, tinst, sizeof (vl.type_instance));
171
172         plugin_dispatch_values (&vl);
173 } /* void compression_submit */
174
175 static int single_read (const char *name, FILE *fh)
176 {
177         char buffer[1024];
178         char *fields[4];
179         const int max_fields = STATIC_ARRAY_SIZE (fields);
180         int  fields_num, read = 0;
181
182         derive_t link_rx, link_tx;
183         derive_t tun_rx, tun_tx;
184         derive_t pre_compress, post_compress;
185         derive_t pre_decompress, post_decompress;
186         derive_t overhead_rx, overhead_tx;
187
188         link_rx = 0;
189         link_tx = 0;
190         tun_rx = 0;
191         tun_tx = 0;
192         pre_compress = 0;
193         post_compress = 0;
194         pre_decompress = 0;
195         post_decompress = 0;
196
197         while (fgets (buffer, sizeof (buffer), fh) != NULL)
198         {
199                 fields_num = openvpn_strsplit (buffer, fields, max_fields);
200
201                 /* status file is generated by openvpn/sig.c:print_status()
202                  * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/sig.c
203                  *
204                  * The line we're expecting has 2 fields. We ignore all lines
205                  *  with more or less fields.
206                  */
207                 if (fields_num != 2)
208                 {
209                         continue;
210                 }
211
212                 if (strcmp (fields[0], "TUN/TAP read bytes") == 0)
213                 {
214                         /* read from the system and sent over the tunnel */
215                         tun_tx = atoll (fields[1]);
216                 }
217                 else if (strcmp (fields[0], "TUN/TAP write bytes") == 0)
218                 {
219                         /* read from the tunnel and written in the system */
220                         tun_rx = atoll (fields[1]);
221                 }
222                 else if (strcmp (fields[0], "TCP/UDP read bytes") == 0)
223                 {
224                         link_rx = atoll (fields[1]);
225                 }
226                 else if (strcmp (fields[0], "TCP/UDP write bytes") == 0)
227                 {
228                         link_tx = atoll (fields[1]);
229                 }
230                 else if (strcmp (fields[0], "pre-compress bytes") == 0)
231                 {
232                         pre_compress = atoll (fields[1]);
233                 }
234                 else if (strcmp (fields[0], "post-compress bytes") == 0)
235                 {
236                         post_compress = atoll (fields[1]);
237                 }
238                 else if (strcmp (fields[0], "pre-decompress bytes") == 0)
239                 {
240                         pre_decompress = atoll (fields[1]);
241                 }
242                 else if (strcmp (fields[0], "post-decompress bytes") == 0)
243                 {
244                         post_decompress = atoll (fields[1]);
245                 }
246         }
247
248         iostats_submit (name, "traffic", link_rx, link_tx);
249
250         /* we need to force this order to avoid negative values with these unsigned */
251         overhead_rx = (((link_rx - pre_decompress) + post_decompress) - tun_rx);
252         overhead_tx = (((link_tx - post_compress) + pre_compress) - tun_tx);
253
254         iostats_submit (name, "overhead", overhead_rx, overhead_tx);
255
256         if (collect_compression)
257         {
258                 compression_submit (name, "data_in", post_decompress, pre_decompress);
259                 compression_submit (name, "data_out", pre_compress, post_compress);
260         }
261
262         read = 1;
263
264         return (read);
265 } /* int single_read */
266
267 /* for reading status version 1 */
268 static int multi1_read (const char *name, FILE *fh)
269 {
270         char buffer[1024];
271         char *fields[10];
272         int  fields_num, found_header = 0;
273         long long sum_users = 0;
274
275         /* read the file until the "ROUTING TABLE" line is found (no more info after) */
276         while (fgets (buffer, sizeof (buffer), fh) != NULL)
277         {
278                 if (strcmp (buffer, "ROUTING TABLE\n") == 0)
279                         break;
280
281                 if (strcmp (buffer, V1STRING) == 0)
282                 {
283                         found_header = 1;
284                         continue;
285                 }
286
287                 /* skip the first lines until the client list section is found */
288                 if (found_header == 0)
289                         /* we can't start reading data until this string is found */
290                         continue;
291
292                 fields_num = openvpn_strsplit (buffer,
293                                 fields, STATIC_ARRAY_SIZE (fields));
294                 if (fields_num < 4)
295                         continue;
296
297                 if (collect_user_count)
298                         /* If so, sum all users, ignore the individuals*/
299                 {
300                         sum_users += 1;
301                 }
302                 if (collect_individual_users)
303                 {
304                         if (new_naming_schema)
305                         {
306                                 iostats_submit (name,               /* vpn instance */
307                                                 fields[0],          /* "Common Name" */
308                                                 atoll (fields[2]),  /* "Bytes Received" */
309                                                 atoll (fields[3])); /* "Bytes Sent" */
310                         }
311                         else
312                         {
313                                 iostats_submit (fields[0],          /* "Common Name" */
314                                                 NULL,               /* unused when in multimode */
315                                                 atoll (fields[2]),  /* "Bytes Received" */
316                                                 atoll (fields[3])); /* "Bytes Sent" */
317                         }
318                 }
319         }
320
321         if (ferror (fh))
322                 return (0);
323
324         if (collect_user_count)
325                 numusers_submit(name, name, sum_users);
326
327         return (1);
328 } /* int multi1_read */
329
330 /* for reading status version 2 */
331 static int multi2_read (const char *name, FILE *fh)
332 {
333         char buffer[1024];
334         char *fields[10];
335         const int max_fields = STATIC_ARRAY_SIZE (fields);
336         int  fields_num, read = 0;
337         long long sum_users    = 0;
338
339         while (fgets (buffer, sizeof (buffer), fh) != NULL)
340         {
341                 fields_num = openvpn_strsplit (buffer, fields, max_fields);
342
343                 /* status file is generated by openvpn/multi.c:multi_print_status()
344                  * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
345                  *
346                  * The line we're expecting has 8 fields. We ignore all lines
347                  *  with more or less fields.
348                  */
349                 if (fields_num != 8)
350                         continue;
351
352                 if (strcmp (fields[0], "CLIENT_LIST") != 0)
353                         continue;
354
355                 if (collect_user_count)
356                         /* If so, sum all users, ignore the individuals*/
357                 {
358                         sum_users += 1;
359                 }
360                 if (collect_individual_users)
361                 {
362                         if (new_naming_schema)
363                         {
364                                 /* plugin inst = file name, type inst = fields[1] */
365                                 iostats_submit (name,               /* vpn instance */
366                                                 fields[1],          /* "Common Name" */
367                                                 atoll (fields[4]),  /* "Bytes Received" */
368                                                 atoll (fields[5])); /* "Bytes Sent" */
369                         }
370                         else
371                         {
372                                 /* plugin inst = fields[1], type inst = "" */
373                                 iostats_submit (fields[1],          /* "Common Name" */
374                                                 NULL,               /* unused when in multimode */
375                                                 atoll (fields[4]),  /* "Bytes Received" */
376                                                 atoll (fields[5])); /* "Bytes Sent" */
377                         }
378                 }
379
380                 read = 1;
381         }
382
383         if (collect_user_count)
384         {
385                 numusers_submit(name, name, sum_users);
386                 read = 1;
387         }
388
389         return (read);
390 } /* int multi2_read */
391
392 /* for reading status version 3 */
393 static int multi3_read (const char *name, FILE *fh)
394 {
395         char buffer[1024];
396         char *fields[15];
397         const int max_fields = STATIC_ARRAY_SIZE (fields);
398         int  fields_num, read = 0;
399         long long sum_users    = 0;
400
401         while (fgets (buffer, sizeof (buffer), fh) != NULL)
402         {
403                 fields_num = strsplit (buffer, fields, max_fields);
404
405                 /* status file is generated by openvpn/multi.c:multi_print_status()
406                  * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
407                  *
408                  * The line we're expecting has 12 fields. We ignore all lines
409                  *  with more or less fields.
410                  */
411                 if (fields_num != 12)
412                 {
413                         continue;
414                 }
415                 else
416                 {
417                         if (strcmp (fields[0], "CLIENT_LIST") != 0)
418                                 continue;
419
420                         if (collect_user_count)
421                                 /* If so, sum all users, ignore the individuals*/
422                         {
423                                 sum_users += 1;
424                         }
425
426                         if (collect_individual_users)
427                         {
428                                 if (new_naming_schema)
429                                 {
430                                         iostats_submit (name,               /* vpn instance */
431                                                         fields[1],          /* "Common Name" */
432                                                         atoll (fields[4]),  /* "Bytes Received" */
433                                                         atoll (fields[5])); /* "Bytes Sent" */
434                                 }
435                                 else
436                                 {
437                                         iostats_submit (fields[1],          /* "Common Name" */
438                                                         NULL,               /* unused when in multimode */
439                                                         atoll (fields[4]),  /* "Bytes Received" */
440                                                         atoll (fields[5])); /* "Bytes Sent" */
441                                 }
442                         }
443
444                         read = 1;
445                 }
446         }
447
448         if (collect_user_count)
449         {
450                 numusers_submit(name, name, sum_users);
451                 read = 1;
452         }
453
454         return (read);
455 } /* int multi3_read */
456
457 /* for reading status version 4 */
458 static int multi4_read (const char *name, FILE *fh)
459 {
460         char buffer[1024];
461         char *fields[11];
462         const int max_fields = STATIC_ARRAY_SIZE (fields);
463         int  fields_num, read = 0;
464         long long sum_users    = 0;
465
466         while (fgets (buffer, sizeof (buffer), fh) != NULL)
467         {
468                 fields_num = openvpn_strsplit (buffer, fields, max_fields);
469
470                 /* status file is generated by openvpn/multi.c:multi_print_status()
471                  * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
472                  *
473                  * The line we're expecting has 9 fields. We ignore all lines
474                  *  with more or less fields.
475                  */
476                 if (fields_num != 9)
477                         continue;
478
479
480                 if (strcmp (fields[0], "CLIENT_LIST") != 0)
481                         continue;
482
483
484                 if (collect_user_count)
485                         /* If so, sum all users, ignore the individuals*/
486                 {
487                         sum_users += 1;
488                 }
489                 if (collect_individual_users)
490                 {
491                         if (new_naming_schema)
492                         {
493                                 /* plugin inst = file name, type inst = fields[1] */
494                                 iostats_submit (name,               /* vpn instance */
495                                                 fields[1],          /* "Common Name" */
496                                                 atoll (fields[4]),  /* "Bytes Received" */
497                                                 atoll (fields[5])); /* "Bytes Sent" */
498                         }
499                         else
500                         {
501                                 /* plugin inst = fields[1], type inst = "" */
502                                 iostats_submit (fields[1],          /* "Common Name" */
503                                                 NULL,               /* unused when in multimode */
504                                                 atoll (fields[4]),  /* "Bytes Received" */
505                                                 atoll (fields[5])); /* "Bytes Sent" */
506                         }
507                 }
508
509                 read = 1;
510         }
511
512         if (collect_user_count)
513         {
514                 numusers_submit(name, name, sum_users);
515                 read = 1;
516         }
517
518         return (read);
519 } /* int multi4_read */
520
521 /* read callback */
522 static int openvpn_read (void)
523 {
524         FILE *fh;
525         int  read;
526
527         read = 0;
528
529         /* call the right read function for every status entry in the list */
530         for (int i = 0; i < vpn_num; i++)
531         {
532                 int vpn_read = 0;
533
534                 fh = fopen (vpn_list[i]->file, "r");
535                 if (fh == NULL)
536                 {
537                         char errbuf[1024];
538                         WARNING ("openvpn plugin: fopen(%s) failed: %s", vpn_list[i]->file,
539                                         sstrerror (errno, errbuf, sizeof (errbuf)));
540
541                         continue;
542                 }
543
544                 switch (vpn_list[i]->version)
545                 {
546                         case SINGLE:
547                                 vpn_read = single_read(vpn_list[i]->name, fh);
548                                 break;
549
550                         case MULTI1:
551                                 vpn_read = multi1_read(vpn_list[i]->name, fh);
552                                 break;
553
554                         case MULTI2:
555                                 vpn_read = multi2_read(vpn_list[i]->name, fh);
556                                 break;
557
558                         case MULTI3:
559                                 vpn_read = multi3_read(vpn_list[i]->name, fh);
560                                 break;
561
562                         case MULTI4:
563                                 vpn_read = multi4_read(vpn_list[i]->name, fh);
564                                 break;
565                 }
566
567                 fclose (fh);
568                 read += vpn_read;
569         }
570
571         return (read ? 0 : -1);
572 } /* int openvpn_read */
573
574 static int version_detect (const char *filename)
575 {
576         FILE *fh;
577         char buffer[1024];
578         int version = 0;
579
580         /* Sanity checking. We're called from the config handling routine, so
581          * better play it save. */
582         if ((filename == NULL) || (*filename == 0))
583                 return (0);
584
585         fh = fopen (filename, "r");
586         if (fh == NULL)
587         {
588                 char errbuf[1024];
589                 WARNING ("openvpn plugin: Unable to read \"%s\": %s", filename,
590                                 sstrerror (errno, errbuf, sizeof (errbuf)));
591                 return (0);
592         }
593
594         /* now search for the specific multimode data format */
595         while ((fgets (buffer, sizeof (buffer), fh)) != NULL)
596         {
597                 /* we look at the first line searching for SINGLE mode configuration */
598                 if (strcmp (buffer, VSSTRING) == 0)
599                 {
600                         DEBUG ("openvpn plugin: found status file version SINGLE");
601                         version = SINGLE;
602                         break;
603                 }
604                 /* searching for multi version 1 */
605                 else if (strcmp (buffer, V1STRING) == 0)
606                 {
607                         DEBUG ("openvpn plugin: found status file version MULTI1");
608                         version = MULTI1;
609                         break;
610                 }
611                 /* searching for multi version 2 */
612                 else if (strcmp (buffer, V2STRING) == 0)
613                 {
614                         DEBUG ("openvpn plugin: found status file version MULTI2");
615                         version = MULTI2;
616                         break;
617                 }
618                 /* searching for multi version 3 */
619                 else if (strcmp (buffer, V3STRING) == 0)
620                 {
621                         DEBUG ("openvpn plugin: found status file version MULTI3");
622                         version = MULTI3;
623                         break;
624                 }
625                 /* searching for multi version 4 */
626                 else if (strcmp (buffer, V4STRING) == 0)
627                 {
628                         DEBUG ("openvpn plugin: found status file version MULTI4");
629                         version = MULTI4;
630                         break;
631                 }
632         }
633
634         if (version == 0)
635         {
636                 /* This is only reached during configuration, so complaining to
637                  * the user is in order. */
638                 NOTICE ("openvpn plugin: %s: Unknown file format, please "
639                                 "report this as bug. Make sure to include "
640                                 "your status file, so the plugin can "
641                                 "be adapted.", filename);
642         }
643
644         fclose (fh);
645
646         return version;
647 } /* int version_detect */
648
649 static int openvpn_config (const char *key, const char *value)
650 {
651         if (strcasecmp ("StatusFile", key) == 0)
652         {
653                 char    *status_file, *status_name, *filename;
654                 int     status_version;
655                 vpn_status_t *temp;
656
657                 /* try to detect the status file format */
658                 status_version = version_detect (value);
659
660                 if (status_version == 0)
661                 {
662                         WARNING ("openvpn plugin: unable to detect status version, \
663                                         discarding status file \"%s\".", value);
664                         return (1);
665                 }
666
667                 status_file = sstrdup (value);
668                 if (status_file == NULL)
669                 {
670                         char errbuf[1024];
671                         WARNING ("openvpn plugin: sstrdup failed: %s",
672                                         sstrerror (errno, errbuf, sizeof (errbuf)));
673                         return (1);
674                 }
675
676                 /* it determines the file name as string starting at location filename + 1 */
677                 filename = strrchr (status_file, (int) '/');
678                 if (filename == NULL)
679                 {
680                         /* status_file is already the file name only */
681                         status_name = status_file;
682                 }
683                 else
684                 {
685                         /* doesn't waste memory, uses status_file starting at filename + 1 */
686                         status_name = filename + 1;
687                 }
688
689                 /* scan the list looking for a clone */
690                 for (int i = 0; i < vpn_num; i++)
691                 {
692                         if (strcasecmp (vpn_list[i]->name, status_name) == 0)
693                         {
694                                 WARNING ("openvpn plugin: status filename \"%s\" "
695                                                 "already used, please choose a "
696                                                 "different one.", status_name);
697                                 sfree (status_file);
698                                 return (1);
699                         }
700                 }
701
702                 /* create a new vpn element since file, version and name are ok */
703                 temp = malloc (sizeof (*temp));
704                 if (temp == NULL)
705                 {
706                         char errbuf[1024];
707                         ERROR ("openvpn plugin: malloc failed: %s",
708                                         sstrerror (errno, errbuf, sizeof (errbuf)));
709                         sfree (status_file);
710                         return (1);
711                 }
712                 temp->file = status_file;
713                 temp->version = status_version;
714                 temp->name = status_name;
715
716                 vpn_status_t **tmp_list = realloc (vpn_list, (vpn_num + 1) * sizeof (*vpn_list));
717                 if (tmp_list == NULL)
718                 {
719                         char errbuf[1024];
720                         ERROR ("openvpn plugin: realloc failed: %s",
721                                         sstrerror (errno, errbuf, sizeof (errbuf)));
722
723                         sfree (vpn_list);
724                         sfree (temp->file);
725                         sfree (temp);
726                         return (1);
727                 }
728                 vpn_list = tmp_list;
729
730                 vpn_list[vpn_num] = temp;
731                 vpn_num++;
732
733                 DEBUG ("openvpn plugin: status file \"%s\" added", temp->file);
734
735         } /* if (strcasecmp ("StatusFile", key) == 0) */
736         else if ((strcasecmp ("CollectCompression", key) == 0)
737                 || (strcasecmp ("Compression", key) == 0)) /* old, deprecated name */
738         {
739                 if (IS_FALSE (value))
740                         collect_compression = 0;
741                 else
742                         collect_compression = 1;
743         } /* if (strcasecmp ("CollectCompression", key) == 0) */
744         else if (strcasecmp ("ImprovedNamingSchema", key) == 0)
745         {
746                 if (IS_TRUE (value))
747                 {
748                         DEBUG ("openvpn plugin: using the new naming schema");
749                         new_naming_schema = 1;
750                 }
751                 else
752                 {
753                         new_naming_schema = 0;
754                 }
755         } /* if (strcasecmp ("ImprovedNamingSchema", key) == 0) */
756         else if (strcasecmp("CollectUserCount", key) == 0)
757         {
758                 if (IS_TRUE(value))
759                         collect_user_count = 1;
760                 else
761                         collect_user_count = 0;
762         } /* if (strcasecmp("CollectUserCount", key) == 0) */
763         else if (strcasecmp("CollectIndividualUsers", key) == 0)
764         {
765                 if (IS_FALSE (value))
766                         collect_individual_users = 0;
767                 else
768                         collect_individual_users = 1;
769         } /* if (strcasecmp("CollectIndividualUsers", key) == 0) */
770         else
771         {
772                 return (-1);
773         }
774
775         return (0);
776 } /* int openvpn_config */
777
778 /* shutdown callback */
779 static int openvpn_shutdown (void)
780 {
781         for (int i = 0; i < vpn_num; i++)
782         {
783                 sfree (vpn_list[i]->file);
784                 sfree (vpn_list[i]);
785         }
786
787         sfree (vpn_list);
788
789         return (0);
790 } /* int openvpn_shutdown */
791
792 static int openvpn_init (void)
793 {
794         if (!collect_individual_users
795                         && !collect_compression
796                         && !collect_user_count)
797         {
798                 WARNING ("OpenVPN plugin: Neither `CollectIndividualUsers', "
799                                 "`CollectCompression', nor `CollectUserCount' is true. There's no "
800                                 "data left to collect.");
801                 return (-1);
802         }
803
804         plugin_register_read ("openvpn", openvpn_read);
805         plugin_register_shutdown ("openvpn", openvpn_shutdown);
806
807         return (0);
808 } /* int openvpn_init */
809
810 void module_register (void)
811 {
812         plugin_register_config ("openvpn", openvpn_config,
813                         config_keys, config_keys_num);
814         plugin_register_init ("openvpn", openvpn_init);
815 } /* void module_register */
816
817 /* vim: set sw=2 ts=2 : */