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