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