Merge branch 'collectd-5.4' into collectd-5.5
[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 #include "common.h"
30 #include "plugin.h"
31
32 #define V1STRING "Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since\n"
33 #define V2STRING "HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t)\n"
34 #define V3STRING "HEADER CLIENT_LIST Common Name Real Address Virtual Address Bytes Received Bytes Sent Connected Since Connected Since (time_t)\n"
35 #define V4STRING "HEADER,CLIENT_LIST,Common Name,Real Address,Virtual Address,Bytes Received,Bytes Sent,Connected Since,Connected Since (time_t),Username\n"
36 #define VSSTRING "OpenVPN STATISTICS\n"
37
38
39 struct vpn_status_s
40 {
41         char *file;
42         enum
43         {
44                 MULTI1 = 1, /* status-version 1 */
45                 MULTI2,     /* status-version 2 */
46                 MULTI3,     /* status-version 3 */
47                 MULTI4,     /* status-version 4 */
48                 SINGLE = 10 /* currently no versions for single mode, maybe in the future */
49         } version;
50         char *name;
51 };
52 typedef struct vpn_status_s vpn_status_t;
53
54 static vpn_status_t **vpn_list = NULL;
55 static int vpn_num = 0;
56
57 static _Bool new_naming_schema = 0;
58 static _Bool collect_compression = 1;
59 static _Bool collect_user_count  = 0;
60 static _Bool collect_individual_users  = 1;
61
62 static const char *config_keys[] =
63 {
64         "StatusFile",
65         "Compression", /* old, deprecated name */
66         "ImprovedNamingSchema",
67         "CollectCompression",
68         "CollectUserCount",
69         "CollectIndividualUsers"
70 };
71 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
72
73
74 /* Helper function
75  * copy-n-pasted from common.c - changed delim to ","  */
76 static int openvpn_strsplit (char *string, char **fields, size_t size)
77 {
78         size_t i;
79         char *ptr;
80         char *saveptr;
81
82         i = 0;
83         ptr = string;
84         saveptr = NULL;
85         while ((fields[i] = strtok_r (ptr, ",", &saveptr)) != NULL)
86         {
87                 ptr = NULL;
88                 i++;
89
90                 if (i >= size)
91                         break;
92         }
93
94         return (i);
95 } /* int openvpn_strsplit */
96
97 /* dispatches number of users */
98 static void numusers_submit (char *pinst, char *tinst, gauge_t value)
99 {
100         value_t values[1];
101         value_list_t vl = VALUE_LIST_INIT;
102
103         values[0].gauge = value;
104
105         vl.values = values;
106         vl.values_len = STATIC_ARRAY_SIZE (values);
107         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
108         sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
109         sstrncpy (vl.type, "users", sizeof (vl.type));
110         if (pinst != NULL)
111                 sstrncpy (vl.plugin_instance, pinst, sizeof (vl.plugin_instance));
112         if (tinst != NULL)
113                 sstrncpy (vl.type_instance, tinst, sizeof (vl.type_instance));
114
115         plugin_dispatch_values (&vl);
116 } /* void numusers_submit */
117
118 /* dispatches stats about traffic (TCP or UDP) generated by the tunnel per single endpoint */
119 static void iostats_submit (char *pinst, char *tinst, derive_t rx, derive_t tx)
120 {
121         value_t values[2];
122         value_list_t vl = VALUE_LIST_INIT;
123
124         values[0].derive = rx;
125         values[1].derive = tx;
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.host, hostname_g, sizeof (vl.host));
136         sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
137         if (pinst != NULL)
138                 sstrncpy (vl.plugin_instance, pinst,
139                                 sizeof (vl.plugin_instance));
140         sstrncpy (vl.type, "if_octets", sizeof (vl.type));
141         if (tinst != NULL)
142                 sstrncpy (vl.type_instance, tinst, sizeof (vl.type_instance));
143
144         plugin_dispatch_values (&vl);
145 } /* void traffic_submit */
146
147 /* dispatches stats about data compression shown when in single mode */
148 static void compression_submit (char *pinst, char *tinst,
149                 derive_t uncompressed, derive_t compressed)
150 {
151         value_t values[2];
152         value_list_t vl = VALUE_LIST_INIT;
153
154         values[0].derive = uncompressed;
155         values[1].derive = compressed;
156
157         vl.values = values;
158         vl.values_len = STATIC_ARRAY_SIZE (values);
159         sstrncpy (vl.host, hostname_g, sizeof (vl.host));
160         sstrncpy (vl.plugin, "openvpn", sizeof (vl.plugin));
161         if (pinst != NULL)
162                 sstrncpy (vl.plugin_instance, pinst,
163                                 sizeof (vl.plugin_instance));
164         sstrncpy (vl.type, "compression", sizeof (vl.type));
165         if (tinst != NULL)
166                 sstrncpy (vl.type_instance, tinst, sizeof (vl.type_instance));
167
168         plugin_dispatch_values (&vl);
169 } /* void compression_submit */
170
171 static int single_read (char *name, FILE *fh)
172 {
173         char buffer[1024];
174         char *fields[4];
175         const int max_fields = STATIC_ARRAY_SIZE (fields);
176         int  fields_num, read = 0;
177
178         derive_t link_rx, link_tx;
179         derive_t tun_rx, tun_tx;
180         derive_t pre_compress, post_compress;
181         derive_t pre_decompress, post_decompress;
182         derive_t overhead_rx, overhead_tx;
183
184         link_rx = 0;
185         link_tx = 0;
186         tun_rx = 0;
187         tun_tx = 0;
188         pre_compress = 0;
189         post_compress = 0;
190         pre_decompress = 0;
191         post_decompress = 0;
192
193         while (fgets (buffer, sizeof (buffer), fh) != NULL)
194         {
195                 fields_num = openvpn_strsplit (buffer, fields, max_fields);
196
197                 /* status file is generated by openvpn/sig.c:print_status()
198                  * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/sig.c
199                  *
200                  * The line we're expecting has 2 fields. We ignore all lines
201                  *  with more or less fields.
202                  */
203                 if (fields_num != 2)
204                 {
205                         continue;
206                 }
207
208                 if (strcmp (fields[0], "TUN/TAP read bytes") == 0)
209                 {
210                         /* read from the system and sent over the tunnel */
211                         tun_tx = atoll (fields[1]);
212                 }
213                 else if (strcmp (fields[0], "TUN/TAP write bytes") == 0)
214                 {
215                         /* read from the tunnel and written in the system */
216                         tun_rx = atoll (fields[1]);
217                 }
218                 else if (strcmp (fields[0], "TCP/UDP read bytes") == 0)
219                 {
220                         link_rx = atoll (fields[1]);
221                 }
222                 else if (strcmp (fields[0], "TCP/UDP write bytes") == 0)
223                 {
224                         link_tx = atoll (fields[1]);
225                 }
226                 else if (strcmp (fields[0], "pre-compress bytes") == 0)
227                 {
228                         pre_compress = atoll (fields[1]);
229                 }
230                 else if (strcmp (fields[0], "post-compress bytes") == 0)
231                 {
232                         post_compress = atoll (fields[1]);
233                 }
234                 else if (strcmp (fields[0], "pre-decompress bytes") == 0)
235                 {
236                         pre_decompress = atoll (fields[1]);
237                 }
238                 else if (strcmp (fields[0], "post-decompress bytes") == 0)
239                 {
240                         post_decompress = atoll (fields[1]);
241                 }
242         }
243
244         iostats_submit (name, "traffic", link_rx, link_tx);
245
246         /* we need to force this order to avoid negative values with these unsigned */
247         overhead_rx = (((link_rx - pre_decompress) + post_decompress) - tun_rx);
248         overhead_tx = (((link_tx - post_compress) + pre_compress) - tun_tx);
249
250         iostats_submit (name, "overhead", overhead_rx, overhead_tx);
251
252         if (collect_compression)
253         {
254                 compression_submit (name, "data_in", post_decompress, pre_decompress);
255                 compression_submit (name, "data_out", pre_compress, post_compress);
256         }
257
258         read = 1;
259
260         return (read);
261 } /* int single_read */
262
263 /* for reading status version 1 */
264 static int multi1_read (char *name, FILE *fh)
265 {
266         char buffer[1024];
267         char *fields[10];
268         int  fields_num, found_header = 0;
269         long long sum_users = 0;
270
271         /* read the file until the "ROUTING TABLE" line is found (no more info after) */
272         while (fgets (buffer, sizeof (buffer), fh) != NULL)
273         {
274                 if (strcmp (buffer, "ROUTING TABLE\n") == 0)
275                         break;
276
277                 if (strcmp (buffer, V1STRING) == 0)
278                 {
279                         found_header = 1;
280                         continue;
281                 }
282
283                 /* skip the first lines until the client list section is found */
284                 if (found_header == 0)
285                         /* we can't start reading data until this string is found */
286                         continue;
287
288                 fields_num = openvpn_strsplit (buffer,
289                                 fields, STATIC_ARRAY_SIZE (fields));
290                 if (fields_num < 4)
291                         continue;
292
293                 if (collect_user_count)
294                         /* If so, sum all users, ignore the individuals*/
295                 {
296                         sum_users += 1;
297                 }
298                 if (collect_individual_users)
299                 {
300                         if (new_naming_schema)
301                         {
302                                 iostats_submit (name,               /* vpn instance */
303                                                 fields[0],          /* "Common Name" */
304                                                 atoll (fields[2]),  /* "Bytes Received" */
305                                                 atoll (fields[3])); /* "Bytes Sent" */
306                         }
307                         else
308                         {
309                                 iostats_submit (fields[0],          /* "Common Name" */
310                                                 NULL,               /* unused when in multimode */
311                                                 atoll (fields[2]),  /* "Bytes Received" */
312                                                 atoll (fields[3])); /* "Bytes Sent" */
313                         }
314                 }
315         }
316
317         if (ferror (fh))
318                 return (0);
319
320         if (collect_user_count)
321                 numusers_submit(name, name, sum_users);
322
323         return (1);
324 } /* int multi1_read */
325
326 /* for reading status version 2 */
327 static int multi2_read (char *name, FILE *fh)
328 {
329         char buffer[1024];
330         char *fields[10];
331         const int max_fields = STATIC_ARRAY_SIZE (fields);
332         int  fields_num, read = 0;
333         long long sum_users    = 0;
334
335         while (fgets (buffer, sizeof (buffer), fh) != NULL)
336         {
337                 fields_num = openvpn_strsplit (buffer, fields, max_fields);
338
339                 /* status file is generated by openvpn/multi.c:multi_print_status()
340                  * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
341                  *
342                  * The line we're expecting has 8 fields. We ignore all lines
343                  *  with more or less fields.
344                  */
345                 if (fields_num != 8)
346                         continue;
347
348                 if (strcmp (fields[0], "CLIENT_LIST") != 0)
349                         continue;
350
351                 if (collect_user_count)
352                         /* If so, sum all users, ignore the individuals*/
353                 {
354                         sum_users += 1;
355                 }
356                 if (collect_individual_users)
357                 {
358                         if (new_naming_schema)
359                         {
360                                 /* plugin inst = file name, type inst = fields[1] */
361                                 iostats_submit (name,               /* vpn instance */
362                                                 fields[1],          /* "Common Name" */
363                                                 atoll (fields[4]),  /* "Bytes Received" */
364                                                 atoll (fields[5])); /* "Bytes Sent" */
365                         }
366                         else
367                         {
368                                 /* plugin inst = fields[1], type inst = "" */
369                                 iostats_submit (fields[1],          /* "Common Name" */
370                                                 NULL,               /* unused when in multimode */
371                                                 atoll (fields[4]),  /* "Bytes Received" */
372                                                 atoll (fields[5])); /* "Bytes Sent" */
373                         }
374                 }
375
376                 read = 1;
377         }
378
379         if (collect_user_count)
380         {
381                 numusers_submit(name, name, sum_users);
382                 read = 1;
383         }
384
385         return (read);
386 } /* int multi2_read */
387
388 /* for reading status version 3 */
389 static int multi3_read (char *name, FILE *fh)
390 {
391         char buffer[1024];
392         char *fields[15];
393         const int max_fields = STATIC_ARRAY_SIZE (fields);
394         int  fields_num, read = 0;
395         long long sum_users    = 0;
396
397         while (fgets (buffer, sizeof (buffer), fh) != NULL)
398         {
399                 fields_num = strsplit (buffer, fields, max_fields);
400
401                 /* status file is generated by openvpn/multi.c:multi_print_status()
402                  * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
403                  *
404                  * The line we're expecting has 12 fields. We ignore all lines
405                  *  with more or less fields.
406                  */
407                 if (fields_num != 12)
408                 {
409                         continue;
410                 }
411                 else
412                 {
413                         if (strcmp (fields[0], "CLIENT_LIST") != 0)
414                                 continue;
415
416                         if (collect_user_count)
417                                 /* If so, sum all users, ignore the individuals*/
418                         {
419                                 sum_users += 1;
420                         }
421
422                         if (collect_individual_users)
423                         {
424                                 if (new_naming_schema)
425                                 {
426                                         iostats_submit (name,               /* vpn instance */
427                                                         fields[1],          /* "Common Name" */
428                                                         atoll (fields[4]),  /* "Bytes Received" */
429                                                         atoll (fields[5])); /* "Bytes Sent" */
430                                 }
431                                 else
432                                 {
433                                         iostats_submit (fields[1],          /* "Common Name" */
434                                                         NULL,               /* unused when in multimode */
435                                                         atoll (fields[4]),  /* "Bytes Received" */
436                                                         atoll (fields[5])); /* "Bytes Sent" */
437                                 }
438                         }
439
440                         read = 1;
441                 }
442         }
443
444         if (collect_user_count)
445         {
446                 numusers_submit(name, name, sum_users);
447                 read = 1;
448         }
449
450         return (read);
451 } /* int multi3_read */
452
453 /* for reading status version 4 */
454 static int multi4_read (char *name, FILE *fh)
455 {
456         char buffer[1024];
457         char *fields[11];
458         const int max_fields = STATIC_ARRAY_SIZE (fields);
459         int  fields_num, read = 0;
460         long long sum_users    = 0;
461
462         while (fgets (buffer, sizeof (buffer), fh) != NULL)
463         {
464                 fields_num = openvpn_strsplit (buffer, fields, max_fields);
465
466                 /* status file is generated by openvpn/multi.c:multi_print_status()
467                  * http://svn.openvpn.net/projects/openvpn/trunk/openvpn/multi.c
468                  *
469                  * The line we're expecting has 9 fields. We ignore all lines
470                  *  with more or less fields.
471                  */
472                 if (fields_num != 9)
473                         continue;
474
475
476                 if (strcmp (fields[0], "CLIENT_LIST") != 0)
477                         continue;
478
479
480                 if (collect_user_count)
481                         /* If so, sum all users, ignore the individuals*/
482                 {
483                         sum_users += 1;
484                 }
485                 if (collect_individual_users)
486                 {
487                         if (new_naming_schema)
488                         {
489                                 /* plugin inst = file name, type inst = fields[1] */
490                                 iostats_submit (name,               /* vpn instance */
491                                                 fields[1],          /* "Common Name" */
492                                                 atoll (fields[4]),  /* "Bytes Received" */
493                                                 atoll (fields[5])); /* "Bytes Sent" */
494                         }
495                         else
496                         {
497                                 /* plugin inst = fields[1], type inst = "" */
498                                 iostats_submit (fields[1],          /* "Common Name" */
499                                                 NULL,               /* unused when in multimode */
500                                                 atoll (fields[4]),  /* "Bytes Received" */
501                                                 atoll (fields[5])); /* "Bytes Sent" */
502                         }
503                 }
504
505                 read = 1;
506         }
507
508         if (collect_user_count)
509         {
510                 numusers_submit(name, name, sum_users);
511                 read = 1;
512         }
513
514         return (read);
515 } /* int multi4_read */
516
517 /* read callback */
518 static int openvpn_read (void)
519 {
520         FILE *fh;
521         int  i, read;
522
523         read = 0;
524
525         /* call the right read function for every status entry in the list */
526         for (i = 0; i < vpn_num; i++)
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, i;
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 (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 = (vpn_status_t *) malloc (sizeof (vpn_status_t));
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_list = (vpn_status_t **) realloc (vpn_list, (vpn_num + 1) * sizeof (vpn_status_t *));
711                 if (vpn_list == NULL)
712                 {
713                         char errbuf[1024];
714                         ERROR ("openvpn plugin: realloc failed: %s",
715                                         sstrerror (errno, errbuf, sizeof (errbuf)));
716
717                         sfree (temp->file);
718                         sfree (temp);
719                         return (1);
720                 }
721
722                 vpn_list[vpn_num] = temp;
723                 vpn_num++;
724
725                 DEBUG ("openvpn plugin: status file \"%s\" added", temp->file);
726
727         } /* if (strcasecmp ("StatusFile", key) == 0) */
728         else if ((strcasecmp ("CollectCompression", key) == 0)
729                 || (strcasecmp ("Compression", key) == 0)) /* old, deprecated name */
730         {
731                 if (IS_FALSE (value))
732                         collect_compression = 0;
733                 else
734                         collect_compression = 1;
735         } /* if (strcasecmp ("CollectCompression", key) == 0) */
736         else if (strcasecmp ("ImprovedNamingSchema", key) == 0)
737         {
738                 if (IS_TRUE (value))
739                 {
740                         DEBUG ("openvpn plugin: using the new naming schema");
741                         new_naming_schema = 1;
742                 }
743                 else
744                 {
745                         new_naming_schema = 0;
746                 }
747         } /* if (strcasecmp ("ImprovedNamingSchema", key) == 0) */
748         else if (strcasecmp("CollectUserCount", key) == 0)
749         {
750                 if (IS_TRUE(value))
751                         collect_user_count = 1;
752                 else
753                         collect_user_count = 0;
754         } /* if (strcasecmp("CollectUserCount", key) == 0) */
755         else if (strcasecmp("CollectIndividualUsers", key) == 0)
756         {
757                 if (IS_FALSE (value))
758                         collect_individual_users = 0;
759                 else
760                         collect_individual_users = 1;
761         } /* if (strcasecmp("CollectIndividualUsers", key) == 0) */
762         else
763         {
764                 return (-1);
765         }
766
767         return (0);
768 } /* int openvpn_config */
769
770 /* shutdown callback */
771 static int openvpn_shutdown (void)
772 {
773         int i;
774
775         for (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 : */