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