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