Merge branch 'pull/master'
authorFlorian Forster <octo@huhu.verplant.org>
Mon, 21 Jan 2008 17:30:48 +0000 (18:30 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Mon, 21 Jan 2008 17:30:48 +0000 (18:30 +0100)
13 files changed:
.gitignore
TODO
src/Makefile.am
src/collectd-exec.pod
src/collectd-perl.pod
src/collectd-snmp.pod
src/collectd.c
src/collectd.conf.pod
src/collectd.pod
src/configfile.c
src/types.db.pod [new file with mode: 0644]
src/types_list.c
src/types_list.h

index 855e36b..5eb8974 100644 (file)
@@ -46,6 +46,7 @@ src/*.o
 src/collectd
 src/collectd*.1
 src/collectd*.5
+src/types.db.5
 src/config.h.in~
 src/liboconfig/.libs
 src/liboconfig/*.la
diff --git a/TODO b/TODO
index 9cec87b..2b9c8c3 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,15 +1,17 @@
+For version 4.3:
+* Add notification stuff to the network plugin
+* Add notification stuff to the unixsock plugin
+
 src/battery.c: commend not working code.
-general: build Darwin package
 
-Near future:
+Wishlist:
 * Update the RPM specfile to
   - build `collectd-apache'
   - be free of syntax erros.
-
-For version 3.*:
 * Port nfs module to solaris
 * Port tape module to Linux
 * Maybe look into porting the serial module
+* Build Darwin package
 
 http://developer.apple.com/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_IOKitLib_API/chapter_5_section_1.html
 http://developer.apple.com/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/index.html#//apple_ref/doc/uid/TP0000011
index 7f37fee..35d79c6 100644 (file)
@@ -633,7 +633,8 @@ endif
 
 dist_man_MANS = collectd.1 collectd-nagios.1 collectd.conf.5 \
                collectd-email.5 collectd-exec.5 collectd-perl.5 \
-               collectd-snmp.5 collectd-unixsock.5 collectdmon.1
+               collectd-snmp.5 collectd-unixsock.5 collectdmon.1 \
+               types.db.5
 
 #collectd_1_SOURCES = collectd.pod
 
@@ -641,7 +642,7 @@ EXTRA_DIST = types.db
 
 EXTRA_DIST += collectd-email.pod collectd-exec.pod collectd-nagios.pod \
        collectd-perl.pod collectd-snmp.pod collectd-unixsock.pod \
-       collectd.conf.pod collectd.pod collectdmon.pod
+       collectd.conf.pod collectd.pod collectdmon.pod types.db.pod
 
 .pod.1:
        pod2man --release=$(VERSION) --center=$(PACKAGE) $< >.pod2man.tmp 2>/dev/null && mv -f .pod2man.tmp $@ || true
index 29ff45b..1a91b7f 100644 (file)
@@ -10,20 +10,65 @@ collectd-exec - Documentation of collectd's C<exec plugin>
   <Plugin exec>
     Exec "myuser:mygroup" "myprog"
     Exec "otheruser" "/path/to/another/binary"
+    NotificationExec "user" "/usr/lib/collectd/exec/handle_notification"
+    NagiosExec "nagios:nagios" "/usr/lib/nagios/plugins/check_something"
   </Plugin>
 
 =head1 DESCRIPTION
 
-The C<exec plugin> forks of an executable and reads back values that it writes
-to C<STDOUT>. The executable is forked in a fashion similar to L<init>: It is
-forked once and not again until it exits. If it exited, it will be forked again
-after at most I<Interval> seconds. It is perfectly legal for the executable to
-run for a long time and continuously write values to C<STDOUT>.
+The C<exec plugin> forks of an executable either to receive values, to dispatch
+notifications to the outside world or to be able to use Nagios plugins.
 
 If you want/need better performance or more functionality you should take a
 long look at the C<perl plugin>, L<collectd-perl(5)>.
 
-=head1 DATA FORMAT
+=head1 EXECUTABLE TYPES
+
+There are currently three types of executables that can be executed by the
+C<exec plugin>:
+
+=over 4
+
+=item C<Exec>
+
+These programs are forked and values that it writes to C<STDOUT> are read back.
+The executable is forked in a fashion similar to L<init>: It is forked once and
+not again until it exits. If it exited, it will be forked again after at most
+I<Interval> seconds. It is perfectly legal for the executable to run for a long
+time and continuously write values to C<STDOUT>.
+
+See L<EXEC DATA FORMAT> below for a description of the output format expected
+from these programs.
+
+B<Warning:> If the executable only writes one value and then exits I will be
+executed every I<Interval> seconds. If I<Interval> is short (the default is 10
+seconds) this may result in serious system load.
+
+=item C<NotificationExec>
+
+The program is forked once for each notification that is handled by the daemon.
+The notification is passed to the program on C<STDIN> in a fashion similar to
+HTTP-headers. In contrast to programs specified with C<Exec> the execution of
+this program is not serialized, so that several instances of this program may
+run at once if multiple notifications are received.
+
+See L<NOTIFICATION DATA FORMAT> below for a description of the data passed to
+these programs.
+
+=item C<NagiosExec>
+
+The executable is treated as a Nagios plugin. That means that the first line
+printed to C<STDOUT> by this program is used as the text of a notification and
+the severity of the notification depends on the exit status of the executable
+only.
+
+For information on how to write Nagios plugins please refer to the Nagios
+documentation. If a plugin works with Nagios but not with collectd please
+complain on the collectd mailing list instead.
+
+=back
+
+=head1 EXEC DATA FORMAT
 
 The forked executable is expected to print values to C<STDOUT>. The expected
 format is as follows:
@@ -42,7 +87,12 @@ I<Value-List>, separated by a spaces. A description of these two parts follows:
 An I<Identifier> is of the form
 C<I<host>B</>I<plugin>B<->I<instance>B</>I<type>B<->I<instance>> with both
 I<instance>-parts being optional. If they're omitted the hyphen must be
-omitted, too.
+omitted, too. I<plugin> and each I<instance>-part may be chosen freely as long
+as the tuple (plugin, plugin instance, type instance) uniquely identifies the
+plugin within collectd. I<type> identifies the type and number of values
+(i.E<nbsp>e. data-set) passed to collectd. A large list of predefined
+data-sets is available in the B<types.db> file. See L<types.db(5)> for a
+description of the format of this file.
 
 The I<OptionList> is an optional list of I<Options>, where each option if a
 key-value-pair. A list of currently understood options can be found below, all
@@ -84,20 +134,56 @@ Since examples usually let one understand a lot better, here are some:
 When collectd exits it sends a B<SIGTERM> to all still running
 child-processes upon which they have to quit.
 
-=head1 CAVEATS
+=head1 NOTIFICATION DATA FORMAT
+
+The notification executables receive values rather than providing them. In
+fact, after the program is started C<STDOUT> is connected to C</dev/null>.
+
+The data is passed to the executables over C<STDIN> in a format very similar to
+HTTP-headers: There is one line per field. Every line consists of a field name,
+ended by a colon, and the associated value until end-of-line. The input is
+ended by two newlines immediately following another.
+
+The following is an example notification passed to a program:
+
+  Severity: FAILURE
+  Time: 1200928930
+  Host: myhost.mydomain.org
+  Message: This is a test notification to demonstrate the format
+  <newline>
+
+The following header files are currently used. Please note, however, that you
+should ignore unknown header files to be as forward-compatible as possible.
 
 =over 4
 
-=item
+=item B<Severity>
+
+Severity of the notification. May either be B<FAILURE>, B<WARNING>, or B<OKAY>.
+
+=item B<Time>
+
+The time in epoch, i.E<nbsp>e. as seconds since 1970-01-01 00:00:00 UTC.
+
+=item B<Host>
 
-If the executable only writes one value and then exits I will be executed every
-I<Interval> seconds. If I<Interval> is short (the default is 10 seconds) this
-may result in serious system load.
+Name of the host concerned.
+
+=item B<Message>
+
+Message of the notification. This message should be made accessible to the
+user somehow.
+
+=back
+
+=head1 CAVEATS
+
+=over 4
 
 =item
 
 The user, the binary is executed as, may not have root privileges, i.E<nbsp>e.
-must have an UID that is non-zero.
+must have an UID that is non-zero. This is for your own good.
 
 =back
 
index 00a1cbb..194aa54 100644 (file)
@@ -193,9 +193,10 @@ argument which simply tells B<plugin_register> what is being registered.)
 The last argument, I<data>, is either a function name or an array-reference.
 If I<type> is B<TYPE_DATASET>, then the I<data> argument must be an
 array-reference which points to an array of hashes. Each hash describes one
-data-source. For the exact layout see B<Data-Set> above. Please note that
+data-set. For the exact layout see B<Data-Set> above. Please note that
 there is a large number of predefined data-sets available in the B<types.db>
-file which are automatically registered with collectd.
+file which are automatically registered with collectd - see L<types.db(5)> for
+a description of the format of this file.
 
 If the I<type> argument is any of the other types (B<TYPE_INIT>, B<TYPE_READ>,
 ...) then I<data> is expected to be a function name. If the name is not
@@ -455,6 +456,7 @@ instead.
 L<collectd(1)>,
 L<collectd.conf(5)>,
 L<collectd-exec(5)>,
+L<types.db(5)>,
 L<perl(1)>,
 L<threads(3perl)>,
 L<threads::shared(3perl)>,
index ea49029..d0acc06 100644 (file)
@@ -85,7 +85,7 @@ queried. The following options can be set:
 collectd's type that is to be used, e.E<nbsp>g. "if_octets" for interface
 traffic or "users" for a user count. The types are read from the B<TypesDB>
 (see L<collectd.conf(5)>), so you may want to check for which types are
-defined.
+defined. See L<types.db(5)> for a description of the format of this file.
 
 =item B<Table> I<true|false>
 
index 70223b7..c9ae66d 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "plugin.h"
 #include "configfile.h"
-#include "types_list.h"
 
 /*
  * Global variables
@@ -260,7 +259,6 @@ static int do_init (void)
        }
 #endif
 
-       read_types_list ();
        plugin_init_all ();
 
        return (0);
index 021d193..4671ae1 100644 (file)
@@ -72,9 +72,10 @@ setting using the B<-P> command-line option.
 
 Path to the plugins (shared objects) of collectd.
 
-=item B<TypesDB> I<File>
+=item B<TypesDB> I<File> [I<File> ...]
 
-Set the file that contains the data-set descriptions.
+Set one or more files that contain the data-set descriptions. See
+L<types.db(5)> for a description of the format of this file.
 
 =item B<Interval> I<Seconds>
 
@@ -1144,6 +1145,7 @@ L<collectd(1)>,
 L<collectd-exec(5)>,
 L<collectd-perl(5)>,
 L<collectd-unixsock(5)>,
+L<types.db(5)>,
 L<hddtemp(8)>,
 L<kstat(3KSTAT)>,
 L<mbmon(1)>,
index e09fd84..2a326bb 100644 (file)
@@ -102,6 +102,7 @@ L<collectd-exec(5)>,
 L<collectd-perl(5)>,
 L<collectd-snmp(5)>,
 L<collectd-unixsock(5)>,
+L<types.db(5)>,
 L<http://collectd.org/>
 
 =head1 AUTHOR
index 867338d..706e2d1 100644 (file)
@@ -27,6 +27,7 @@
 #include "common.h"
 #include "plugin.h"
 #include "configfile.h"
+#include "types_list.h"
 #include "utils_threshold.h"
 
 #define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str))
@@ -66,6 +67,7 @@ typedef struct cf_global_option_s
 /*
  * Prototypes of callback functions
  */
+static int dispatch_value_typesdb (const oconfig_item_t *ci);
 static int dispatch_value_plugindir (const oconfig_item_t *ci);
 static int dispatch_value_loadplugin (const oconfig_item_t *ci);
 
@@ -77,6 +79,7 @@ static cf_complex_callback_t *complex_callback_head = NULL;
 
 static cf_value_map_t cf_value_map[] =
 {
+       {"TypesDB",    dispatch_value_typesdb},
        {"PluginDir",  dispatch_value_plugindir},
        {"LoadPlugin", dispatch_value_loadplugin}
 };
@@ -89,11 +92,12 @@ static cf_global_option_t cf_global_options[] =
        {"Hostname",    NULL, NULL},
        {"FQDNLookup",  NULL, "false"},
        {"Interval",    NULL, "10"},
-       {"ReadThreads", NULL, "5"},
-       {"TypesDB",     NULL, PLUGINDIR"/types.db"} /* FIXME: Configure path */
+       {"ReadThreads", NULL, "5"}
 };
 static int cf_global_options_num = STATIC_ARRAY_LEN (cf_global_options);
 
+static int cf_default_typesdb = 1;
+
 /*
  * Functions to handle register/unregister, search, and other plugin related
  * stuff
@@ -188,6 +192,27 @@ static int dispatch_global_option (const oconfig_item_t *ci)
        return (-1);
 } /* int dispatch_global_option */
 
+static int dispatch_value_typesdb (const oconfig_item_t *ci)
+{
+       int i = 0;
+
+       assert (strcasecmp (ci->key, "TypesDB") == 0);
+
+       cf_default_typesdb = 0;
+
+       if (ci->values_num < 1)
+               return (-1);
+
+       for (i = 0; i < ci->values_num; ++i)
+       {
+               if (OCONFIG_TYPE_STRING != ci->values[i].type)
+                       continue;
+
+               read_types_list (ci->values[i].value.string);
+       }
+       return (0);
+} /* int dispatch_value_typesdb */
+
 static int dispatch_value_plugindir (const oconfig_item_t *ci)
 {
        assert (strcasecmp (ci->key, "PluginDir") == 0);
@@ -593,5 +618,7 @@ int cf_read (char *filename)
                        dispatch_block (conf->children + i);
        }
 
+       if (cf_default_typesdb)
+               read_types_list (PLUGINDIR"/types.db"); /* FIXME: Configure path */
        return (0);
 } /* int cf_read */
diff --git a/src/types.db.pod b/src/types.db.pod
new file mode 100644 (file)
index 0000000..f0a49f6
--- /dev/null
@@ -0,0 +1,51 @@
+=head1 NAME
+
+types.db - Data-set specifications for the system statistics collection daemon
+B<collectd>
+
+=head1 SYNOPSIS
+
+  bitrate    value:GAUGE:0:4294967295
+  counter    value:COUNTER:U:U
+  if_octets  rx:COUNTER:0:4294967295, tx:COUNTER:0:4294967295
+
+=head1 DESCRIPTION
+
+The types.db file contains one line for each data-set specification. Each line
+consists of two fields delimited by spaces and/or horizontal tabs. The first
+field defines the name of the data-set, while the second field defines a list
+of data-source specifications, delimited by spaces and, optionally, a comma
+(",") right after each list-entry.
+
+The format of the data-source specification has been inspired by RRDtool's
+data-source specification. Each data-source is defined by a quadruple made up
+of the data-source name, type, minimal and maximal values, delimited by colons
+(":"): I<ds-name>:I<ds-type>:I<min>:I<max>. I<ds-type> may be either
+B<COUNTER> or B<GAUGE>. I<min> and I<max> define the range of valid values for
+data stored for this data-source. If B<U> is specified for either the min or
+max value, it will be set to unknown, meaning that no range checks will
+happen. See L<rrdcreate(1)> for more details.
+
+=head1 FILES
+
+The location of the types.db file is defined by the B<TypesDB> configuration
+option (see L<collectd.conf(5)>). If you want to specify custom data-sets, you
+should do so by using a custom file specified as an additional argument to the
+B<TypesDB> option.
+
+=head1 SEE ALSO
+
+L<collectd(1)>,
+L<collectd.conf(5)>,
+L<rrdcreate(1)>
+
+=head1 AUTHOR
+
+B<collectd> has been written by Florian Forster
+E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>.
+
+This manpage has been written by Sebastian Harl
+E<lt>shE<nbsp>atE<nbsp>tokkee.orgE<gt>.
+
+=cut
+
index 002761c..43e8790 100644 (file)
@@ -169,17 +169,12 @@ static void parse_file (FILE *fh)
   } /* while (fgets) */
 } /* void parse_file */
 
-int read_types_list (void)
+int read_types_list (const char *file)
 {
-  const char *file;
   FILE *fh;
 
-  file = global_option_get ("TypesDB");
   if (file == NULL)
-  {
-    ERROR ("global_option_get (\"TypesDB\") returned NULL.");
     return (-1);
-  }
 
   fh = fopen (file, "r");
   if (fh == NULL)
index c7e6aa0..8fe6ce8 100644 (file)
@@ -22,6 +22,6 @@
  *   Florian octo Forster <octo at verplant.org>
  **/
 
-int read_types_list (void);
+int read_types_list (const char *file);
 
 #endif /* TYPES_LIST_H */