author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 15 Jul 2008 15:12:21 +0000 (17:12 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 15 Jul 2008 15:12:21 +0000 (17:12 +0200) |
Conflicts:
src/snmp.c
src/snmp.c
88 files changed:
index 904e7c73a7692ed327a05418f211595e30d73cc9..97119ac5ef70336f31e484cc171f44120fe7705b 100644 (file)
--- a/README
+++ b/README
Network latency: Time to reach the default gateway or another given
host.
+ - postgresql
+ PostgreSQL database statistics: active server connections, transaction
+ numbers, block IO, table row manipulations.
+
- processes
Process counts: Number of running, sleeping, zombie, ... processes.
* Notifications can be handled by the following plugins:
+ - notify_desktop
+ Send a desktop notification to a notification daemon, as defined in
+ the Desktop Notification Specification. To actually display the
+ notifications, notification-daemon is required.
+ See http://www.galago-project.org/specs/notification/.
+
+ - notify_email
+ Send an E-mail with the notification message to the configured
+ recipients.
+
- exec
Execute a program or script to handle the notification.
See collectd-exec(5).
used and should be found in various implementations for hopefully all
platforms.
+ * CoreFoundation.framework and IOKit.framework (optional)
+ For compiling on Darwin in general and the `apple_sensors' plugin in
+ particular.
+
* libcurl (optional)
If you want to use the `apache', `ascent', or `nginx' plugin.
+ * libesmtp (optional)
+ For the `notify_email' plugin.
+
* libhal (optional)
If present, the uuid plugin will check for UUID from HAL.
* libnetsnmp (optional)
For the `snmp' plugin.
+ * libnotify (optional)
+ For the `notify_desktop' plugin.
+
* liboping (optional, if not found a version shipped with this distribution
can be used)
Used by the `ping' plugin to send and receive ICMP packets.
Obviously used by the `perl' plugin. The library has to be compiled with
ithread support (introduced in Perl 5.6.0).
+ * libpq (optional)
+ The PostgreSQL C client library used by the `postgresql' plugin.
+
* librrd (optional; headers and library; rrdtool 1.0 and 1.2 both work fine)
If built without `librrd' the resulting binary will be `client only', i.e.
will send its values via multicast and not create any RRD files itself.
Alternatively you can chose to write CSV-files (Comma Separated Values)
instead.
+ * librt, libsocket, libkstat, libdevinfo (optional)
+ Various standard Solaris libraries which provide system functions.
+
* libsensors (optional)
To read from `lm_sensors', see the `sensors' plugin.
- * libstatgrab may be used to collect statistics on systems other than Linux
- and/or Solaris. Note that CPU- and disk-statistics, while being provided
- by this library, are not supported in collectd right now..
+ * libstatgrab (optional) may be used to collect statistics on systems other
+ than Linux and/or Solaris. Note that CPU- and disk-statistics, while being
+ provided by this library, are not supported in collectd right now..
<http://www.i-scream.org/libstatgrab/>
* libupsclient/nut (optional)
For the `nut' plugin which queries nut's `upsd'.
- * libxmms (optional)
-
- * librt, libsocket, libkstat, libdevinfo
- Various standard Solaris libraries which provide system functions.
-
- * CoreFoundation.framework and IOKit.framework
- For compiling on Darwin in general and the `apple_sensors' plugin in
- particular.
-
* libvirt (optional)
Collect statistics from virtual machines.
* libxml2 (optional)
Parse XML data. This is needed for the `ascent' and `libvirt' plugins.
+ * libxmms (optional)
+
Configuring / Compiling / Installing
------------------------------------
index f21ebfe9f285dc83060ba114c94f70996f4a3980..af274a588e5eed3a8d7503b72326c318ae13eb1a 100644 (file)
return ($sock);
} # _create_socket
-=head1 VALUE IDENTIFIER
+=head1 VALUE IDENTIFIERS
The values in the collectd are identified using an five-tuple (host, plugin,
plugin-instance, type, type-instance) where only plugin-instance and
Submits a value-list to the daemon. If the B<time> argument is omitted
C<time()> is used. The required argument B<values> is a reference to an array
of values that is to be submitted. The number of values must match the number
-of values expected for the given B<type> (see L<VALUE IDENTIFIER>), though this
-is checked by the daemon, not the Perl module. Also, gauge data-sources
+of values expected for the given B<type> (see L<VALUE IDENTIFIERS>), though
+this is checked by the daemon, not the Perl module. Also, gauge data-sources
(e.E<nbsp>g. system-load) may be C<undef>. Returns true upon success and false
otherwise.
return;
} # putnotif
-=item I<$obj>-E<gt>B<flush> (B<timeout> =E<gt> I<$timeout>, B<plugins> =E<gt> [...]);
+=item I<$obj>-E<gt>B<flush> (B<timeout> =E<gt> I<$timeout>, B<plugins> =E<gt> [...], B<identifier> =E<gt> [...]);
Flush cached data.
=item B<plugins>
-If this option is specified, only the selected plugins will be flushed.
+If this option is specified, only the selected plugins will be flushed. The
+argument is a reference to an array of strings.
+
+=item B<identifier>
+
+If this option is specified, only the given identifier(s) will be flushed. The
+argument is a reference to an array of identifiers. Identifiers, in this case,
+are hash references and have the members as outlined in L<VALUE IDENTIFIERS>.
=back
my $status = 0;
my $msg = "FLUSH";
- if ($args{'timeout'})
+ if (defined ($args{'timeout'}))
{
$msg .= " timeout=" . $args{'timeout'};
}
}
}
+ if ($args{'identifier'})
+ {
+ for (@{$args{'identifier'}})
+ {
+ my $identifier = $_;
+ my $ident_str;
+
+ if (ref ($identifier) ne 'HASH')
+ {
+ cluck ("The argument of the `identifier' "
+ . "option must be an array reference "
+ . "of hash references.");
+ return;
+ }
+
+ $ident_str = _create_identifier ($identifier);
+ if (!$ident_str)
+ {
+ return;
+ }
+
+ $msg .= " identifier=$ident_str";
+ }
+ }
+
$msg .= "\n";
send ($fh, $msg, 0) or confess ("send: $!");
diff --git a/configure.in b/configure.in
index 41ee95555c9a5c419d44601f182cab0e8d962b61..2be53f65aeabc7f6f6f408a0cf79d1d9aff34fd6 100644 (file)
--- a/configure.in
+++ b/configure.in
AC_HEADER_SYS_WAIT
AC_HEADER_DIRENT
-AC_CHECK_HEADERS(stdint.h stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h)
+AC_CHECK_HEADERS(stdio.h stdint.h stdbool.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h)
# For ping library
AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
[Wether or not to use the pcap library])
AM_CONDITIONAL(BUILD_WITH_LIBPCAP, test "x$with_libpcap" = "xyes")
+AC_ARG_WITH(libesmtp, [AS_HELP_STRING([--with-libesmtp@<:@=PREFIX@:>@], [Path to libesmtp.])],
+[
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"
+ then
+ LDFLAGS="$LDFLAGS -L$withval/lib"
+ CPPFLAGS="$CPPFLAGS -I$withval/include -D_THREAD_SAFE"
+ with_libesmtp="yes"
+ else
+ with_libesmtp="$withval"
+ fi
+],
+[
+ with_libesmtp="yes"
+])
+if test "x$with_libesmtp" = "xyes"
+then
+ AC_CHECK_LIB(esmtp, smtp_create_session,
+ [
+ AC_DEFINE(HAVE_LIBESMTP, 1, [Define to 1 if you have the esmtp library (-lesmtp).])
+ ], [with_libesmtp="no (libesmtp not found)"])
+fi
+if test "x$with_libesmtp" = "xyes"
+then
+ AC_CHECK_HEADERS(libesmtp.h,
+ [
+ AC_DEFINE(HAVE_LIBESMTP_H, 1, [Define to 1 if you have the <libesmtp.h> header file.])
+ ], [with_libesmtp="no (libesmtp.h not found)"])
+fi
+if test "x$with_libesmtp" = "xyes"
+then
+ collect_libesmtp=1
+else
+ collect_libesmtp=0
+fi
+AC_DEFINE_UNQUOTED(COLLECT_LIBESMTP, [$collect_libesmtp],
+ [Wether or not to use the esmtp library])
+AM_CONDITIONAL(BUILD_WITH_LIBESMTP, test "x$with_libesmtp" = "xyes")
+
perl_interpreter="perl"
AC_ARG_WITH(libperl, [AS_HELP_STRING([--with-libperl@<:@=PREFIX@:>@], [Path to libperl.])],
[
fi
AM_CONDITIONAL(BUILD_WITH_LIBNETSNMP, test "x$with_libnetsnmp" = "xyes")
+PKG_CHECK_MODULES([LIBNOTIFY], [libnotify],
+ [with_libnotify="yes"],
+ [with_libnotify="no ($LIBNOTIFY_PKG_ERRORS)"])
+
with_libupsclient="no (pkg-config isn't available)"
with_libupsclient_cflags=""
with_libupsclient_libs=""
AC_SUBST(BUILD_WITH_OPENIPMI_LIBS)
fi
+dnl Check for libpq.
+with_pg_config="pg_config"
+with_libpq_includedir=""
+with_libpq_libdir=""
+with_libpq_cppflags=""
+with_libpq_ldflags=""
+AC_ARG_WITH(libpq, [AS_HELP_STRING([--with-libpq@<:@=PREFIX@:>@],
+ [Path to libpq.])],
+[
+ if test "x$withval" = "xno"
+ then
+ with_libpq="no"
+ else if test "x$withval" = "xyes"
+ then
+ with_libpq="yes"
+ else
+ if test -f "$withval" && test -x "$withval";
+ then
+ with_pg_config="$withval"
+ else if test -x "$withval/bin/pg_config"
+ then
+ with_pg_config="$withval/bin/pg_config"
+ fi; fi
+ with_libpq="yes"
+ fi; fi
+],
+[
+ with_libpq="yes"
+])
+if test "x$with_libpq" = "xyes"
+then
+ with_libpq_includedir=`$with_pg_config --includedir 2> /dev/null`
+ pg_config_status=$?
+
+ if test $pg_config_status -eq 0
+ then
+ if test -n "$with_libpq_includedir"; then
+ for dir in $with_libpq_includedir; do
+ with_libpq_cppflags="$with_libpq_cppflags -I$dir"
+ done
+ fi
+ else
+ AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
+ fi
+
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libpq_cppflags"
+
+ AC_CHECK_HEADERS(libpq-fe.h, [],
+ [with_libpq="no (libpq-fe.h not found)"], [])
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_libpq" = "xyes"
+then
+ with_libpq_libdir=`$with_pg_config --libdir 2> /dev/null`
+ pg_config_status=$?
+
+ if test $pg_config_status -eq 0
+ then
+ if test -n "$with_libpq_libdir"; then
+ for dir in $with_libpq_libdir; do
+ with_libpq_ldflags="$with_libpq_ldflags -L$dir"
+ done
+ fi
+ else
+ AC_MSG_WARN([$with_pg_config returned with status $pg_config_status])
+ fi
+
+ SAVE_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $with_libpq_ldflags"
+
+ AC_CHECK_LIB(pq, PQconnectdb,
+ [with_libpq="yes"],
+ [with_libpq="no (symbol 'PQconnectdb' not found)"])
+
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+if test "x$with_libpq" = "xyes"
+then
+ BUILD_WITH_LIBPQ_CPPFLAGS="$with_libpq_cppflags"
+ BUILD_WITH_LIBPQ_LDFLAGS="$with_libpq_ldflags"
+ AC_SUBST(BUILD_WITH_LIBPQ_CPPFLAGS)
+ AC_SUBST(BUILD_WITH_LIBPQ_LDFLAGS)
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBPQ, test "x$with_libpq" = "xyes")
+
dnl Check for libvirt and libxml2 libraries.
with_libxml2="no (pkg-config isn't available)"
with_libxml2_cflags=""
plugin_swap="no"
plugin_tape="no"
plugin_tcpconns="no"
+plugin_thermal="no"
plugin_users="no"
plugin_vmem="no"
plugin_vserver="no"
plugin_serial="yes"
plugin_swap="yes"
plugin_tcpconns="yes"
+ plugin_thermal="yes"
plugin_vmem="yes"
plugin_vserver="yes"
plugin_wireless="yes"
if test "x$with_libkvm" = "xyes"
then
+ plugin_processes="yes"
plugin_swap="yes"
fi
AC_PLUGIN([cpu], [$plugin_cpu], [CPU usage statistics])
AC_PLUGIN([cpufreq], [$plugin_cpufreq], [CPU frequency statistics])
AC_PLUGIN([csv], [yes], [CSV output plugin])
+AC_PLUGIN([notify_desktop], [$with_libnotify], [Desktop notifications])
AC_PLUGIN([df], [$plugin_df], [Filesystem usage statistics])
AC_PLUGIN([disk], [$plugin_disk], [Disk usage statistics])
AC_PLUGIN([dns], [$with_libpcap], [DNS traffic analysis])
AC_PLUGIN([network], [yes], [Network communication plugin])
AC_PLUGIN([nfs], [$plugin_nfs], [NFS statistics])
AC_PLUGIN([nginx], [$with_libcurl], [nginx statistics])
+AC_PLUGIN([notify_email], [$with_libesmtp], [Email notifier])
AC_PLUGIN([ntpd], [yes], [NTPd statistics])
AC_PLUGIN([nut], [$with_libupsclient], [Network UPS tools statistics])
AC_PLUGIN([perl], [$plugin_perl], [Embed a Perl interpreter])
AC_PLUGIN([ping], [$with_liboping], [Network latency statistics])
+AC_PLUGIN([postgresql], [$with_libpq], [PostgreSQL database statistics])
AC_PLUGIN([powerdns], [yes], [PowerDNS statistics])
AC_PLUGIN([processes], [$plugin_processes], [Process statistics])
+AC_PLUGIN([qmail], [yes], [QMail queue statistics])
AC_PLUGIN([rrdtool], [$with_rrdtool], [RRDTool output plugin])
AC_PLUGIN([sensors], [$with_lm_sensors], [lm_sensors statistics])
AC_PLUGIN([serial], [$plugin_serial], [serial port traffic])
AC_PLUGIN([tape], [$plugin_tape], [Tape drive statistics])
AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics])
AC_PLUGIN([teamspeak2], [yes], [TeamSpeak2 server statistics])
+AC_PLUGIN([thermal], [$plugin_thermal], [Linux ACPI thermal zone statistics])
AC_PLUGIN([unixsock], [yes], [Unixsock communication plugin])
AC_PLUGIN([users], [$plugin_users], [User statistics])
AC_PLUGIN([uuid], [yes], [UUID as hostname plugin])
Configuration:
Libraries:
- libcurl . . . . . . $with_libcurl
- libiokit . . . . . $with_libiokit
- libiptc . . . . . . $with_libiptc
- libkstat . . . . . $with_kstat
- libkvm . . . . . . $with_libkvm
- libmysql . . . . . $with_libmysql
- libnetlink . . . . $with_libnetlink
- libnetsnmp . . . . $with_libnetsnmp
- liboconfig . . . . $with_liboconfig
- libopenipmi . . . . $with_libopenipmipthread
- liboping . . . . . $with_liboping
- libpcap . . . . . . $with_libpcap
- libperl . . . . . . $with_libperl
- libpthread . . . . $with_libpthread
- librrd . . . . . . $with_rrdtool
- libsensors . . . . $with_lm_sensors
- libstatgrab . . . . $with_libstatgrab
- libupsclient . . . $with_libupsclient
- libvirt . . . . . . $with_libvirt
- libxml2 . . . . . . $with_libxml2
- libxmms . . . . . . $with_libxmms
+ libcurl . . . . . . . $with_libcurl
+ libesmtp . . . . . . $with_libesmtp
+ libiokit . . . . . . $with_libiokit
+ libiptc . . . . . . . $with_libiptc
+ libkstat . . . . . . $with_kstat
+ libkvm . . . . . . . $with_libkvm
+ libmysql . . . . . . $with_libmysql
+ libnetlink . . . . . $with_libnetlink
+ libnetsnmp . . . . . $with_libnetsnmp
+ libnotify . . . . . . $with_libnotify
+ liboconfig . . . . . $with_liboconfig
+ libopenipmi . . . . . $with_libopenipmipthread
+ liboping . . . . . . $with_liboping
+ libpcap . . . . . . . $with_libpcap
+ libperl . . . . . . . $with_libperl
+ libpthread . . . . . $with_libpthread
+ libpq . . . . . . . . $with_libpq
+ librrd . . . . . . . $with_rrdtool
+ libsensors . . . . . $with_lm_sensors
+ libstatgrab . . . . . $with_libstatgrab
+ libupsclient . . . . $with_libupsclient
+ libvirt . . . . . . . $with_libvirt
+ libxml2 . . . . . . . $with_libxml2
+ libxmms . . . . . . . $with_libxmms
Features:
- daemon mode . . . . $enable_daemon
- debug . . . . . . . $enable_debug
+ daemon mode . . . . . $enable_daemon
+ debug . . . . . . . . $enable_debug
Bindings:
- perl . . . . . . . $with_perl_bindings
+ perl . . . . . . . . $with_perl_bindings
Modules:
- apache . . . . . . $enable_apache
- apcups . . . . . . $enable_apcups
- apple_sensors . . . $enable_apple_sensors
- ascent . . . . . . $enable_ascent
- battery . . . . . . $enable_battery
- cpu . . . . . . . . $enable_cpu
- cpufreq . . . . . . $enable_cpufreq
- csv . . . . . . . . $enable_csv
- df . . . . . . . . $enable_df
- disk . . . . . . . $enable_disk
- dns . . . . . . . . $enable_dns
- email . . . . . . . $enable_email
- entropy . . . . . . $enable_entropy
- exec . . . . . . . $enable_exec
- hddtemp . . . . . . $enable_hddtemp
- interface . . . . . $enable_interface
- iptables . . . . . $enable_iptables
- ipmi . . . . . . . $enable_ipmi
- ipvs . . . . . . . $enable_ipvs
- irq . . . . . . . . $enable_irq
- libvirt . . . . . . $enable_libvirt
- load . . . . . . . $enable_load
- logfile . . . . . . $enable_logfile
- mbmon . . . . . . . $enable_mbmon
- memcached . . . . . $enable_memcached
- memory . . . . . . $enable_memory
- multimeter . . . . $enable_multimeter
- mysql . . . . . . . $enable_mysql
- netlink . . . . . . $enable_netlink
- network . . . . . . $enable_network
- nfs . . . . . . . . $enable_nfs
- nginx . . . . . . . $enable_nginx
- ntpd . . . . . . . $enable_ntpd
- nut . . . . . . . . $enable_nut
- perl . . . . . . . $enable_perl
- ping . . . . . . . $enable_ping
- powerdns . . . . . $enable_powerdns
- processes . . . . . $enable_processes
- rrdtool . . . . . . $enable_rrdtool
- sensors . . . . . . $enable_sensors
- serial . . . . . . $enable_serial
- snmp . . . . . . . $enable_snmp
- swap . . . . . . . $enable_swap
- syslog . . . . . . $enable_syslog
- tail . . . . . . . $enable_tail
- tape . . . . . . . $enable_tape
- tcpconns . . . . . $enable_tcpconns
- teamspeak2 . . . . $enable_teamspeak2
- unixsock . . . . . $enable_unixsock
- users . . . . . . . $enable_users
- uuid . . . . . . . $enable_uuid
- vmem . . . . . . . $enable_vmem
- vserver . . . . . . $enable_vserver
- wireless . . . . . $enable_wireless
- xmms . . . . . . . $enable_xmms
+ apache . . . . . . . $enable_apache
+ apcups . . . . . . . $enable_apcups
+ apple_sensors . . . . $enable_apple_sensors
+ ascent . . . . . . . $enable_ascent
+ battery . . . . . . . $enable_battery
+ cpu . . . . . . . . . $enable_cpu
+ cpufreq . . . . . . . $enable_cpufreq
+ csv . . . . . . . . . $enable_csv
+ df . . . . . . . . . $enable_df
+ disk . . . . . . . . $enable_disk
+ dns . . . . . . . . . $enable_dns
+ email . . . . . . . . $enable_email
+ entropy . . . . . . . $enable_entropy
+ exec . . . . . . . . $enable_exec
+ hddtemp . . . . . . . $enable_hddtemp
+ interface . . . . . . $enable_interface
+ iptables . . . . . . $enable_iptables
+ ipmi . . . . . . . . $enable_ipmi
+ ipvs . . . . . . . . $enable_ipvs
+ irq . . . . . . . . . $enable_irq
+ libvirt . . . . . . . $enable_libvirt
+ load . . . . . . . . $enable_load
+ logfile . . . . . . . $enable_logfile
+ mbmon . . . . . . . . $enable_mbmon
+ memcached . . . . . . $enable_memcached
+ memory . . . . . . . $enable_memory
+ multimeter . . . . . $enable_multimeter
+ mysql . . . . . . . . $enable_mysql
+ netlink . . . . . . . $enable_netlink
+ network . . . . . . . $enable_network
+ nfs . . . . . . . . . $enable_nfs
+ nginx . . . . . . . . $enable_nginx
+ notify_desktop . . . $enable_notify_desktop
+ notify_email . . . . $enable_notify_email
+ ntpd . . . . . . . . $enable_ntpd
+ nut . . . . . . . . . $enable_nut
+ perl . . . . . . . . $enable_perl
+ ping . . . . . . . . $enable_ping
+ postgresql . . . . . $enable_postgresql
+ powerdns . . . . . . $enable_powerdns
+ processes . . . . . . $enable_processes
+ qmail . . . . . . . . $enable_qmail
+ rrdtool . . . . . . . $enable_rrdtool
+ sensors . . . . . . . $enable_sensors
+ serial . . . . . . . $enable_serial
+ snmp . . . . . . . . $enable_snmp
+ swap . . . . . . . . $enable_swap
+ syslog . . . . . . . $enable_syslog
+ tail . . . . . . . . $enable_tail
+ tape . . . . . . . . $enable_tape
+ tcpconns . . . . . . $enable_tcpconns
+ teamspeak2 . . . . . $enable_teamspeak2
+ thermal . . . . . . . $enable_thermal
+ unixsock . . . . . . $enable_unixsock
+ users . . . . . . . . $enable_users
+ uuid . . . . . . . . $enable_uuid
+ vmem . . . . . . . . $enable_vmem
+ vserver . . . . . . . $enable_vserver
+ wireless . . . . . . $enable_wireless
+ xmms . . . . . . . . $enable_xmms
EOF
diff --git a/contrib/collection.cgi b/contrib/collection.cgi
index b8a08130b22c5bcd3fa28ddd743c369f19a6f146..cab7543f0e844d32b1c60861bd19ce893d180f97 100755 (executable)
--- a/contrib/collection.cgi
+++ b/contrib/collection.cgi
'GPRINT:ping_avg:AVERAGE:%4.1lf ms Avg,',
'GPRINT:ping_max:MAX:%4.1lf ms Max,',
'GPRINT:ping_avg:LAST:%4.1lf ms Last'],
+ pg_blks => ['DEF:pg_blks_avg={file}:value:AVERAGE',
+ 'DEF:pg_blks_min={file}:value:MIN',
+ 'DEF:pg_blks_max={file}:value:MAX',
+ "AREA:pg_blks_max#$HalfBlue",
+ "AREA:pg_blks_min#$Canvas",
+ "LINE1:pg_blks_avg#$FullBlue:Blocks",
+ 'GPRINT:pg_blks_min:MIN:%4.1lf%s Min,',
+ 'GPRINT:pg_blks_avg:AVERAGE:%4.1lf%s Avg,',
+ 'GPRINT:pg_blks_max:MAX:%4.1lf%s Max,',
+ 'GPRINT:pg_blks_avg:LAST:%4.1lf%s Last'],
+ pg_n_tup_c => ['DEF:pg_n_tup_avg={file}:value:AVERAGE',
+ 'DEF:pg_n_tup_min={file}:value:MIN',
+ 'DEF:pg_n_tup_max={file}:value:MAX',
+ "AREA:pg_n_tup_max#$HalfBlue",
+ "AREA:pg_n_tup_min#$Canvas",
+ "LINE1:pg_n_tup_avg#$FullBlue:Tuples",
+ 'GPRINT:pg_n_tup_min:MIN:%4.1lf%s Min,',
+ 'GPRINT:pg_n_tup_avg:AVERAGE:%4.1lf%s Avg,',
+ 'GPRINT:pg_n_tup_max:MAX:%4.1lf%s Max,',
+ 'GPRINT:pg_n_tup_avg:LAST:%4.1lf%s Last'],
+ pg_n_tup_g => ['DEF:pg_n_tup_avg={file}:value:AVERAGE',
+ 'DEF:pg_n_tup_min={file}:value:MIN',
+ 'DEF:pg_n_tup_max={file}:value:MAX',
+ "AREA:pg_n_tup_max#$HalfBlue",
+ "AREA:pg_n_tup_min#$Canvas",
+ "LINE1:pg_n_tup_avg#$FullBlue:Tuples",
+ 'GPRINT:pg_n_tup_min:MIN:%4.1lf%s Min,',
+ 'GPRINT:pg_n_tup_avg:AVERAGE:%4.1lf%s Avg,',
+ 'GPRINT:pg_n_tup_max:MAX:%4.1lf%s Max,',
+ 'GPRINT:pg_n_tup_avg:LAST:%4.1lf%s Last'],
+ pg_numbackends => ['DEF:pg_numbackends_avg={file}:value:AVERAGE',
+ 'DEF:pg_numbackends_min={file}:value:MIN',
+ 'DEF:pg_numbackends_max={file}:value:MAX',
+ "AREA:pg_numbackends_max#$HalfBlue",
+ "AREA:pg_numbackends_min#$Canvas",
+ "LINE1:pg_numbackends_avg#$FullBlue:Backends",
+ 'GPRINT:pg_numbackends_min:MIN:%4.1lf%s Min,',
+ 'GPRINT:pg_numbackends_avg:AVERAGE:%4.1lf%s Avg,',
+ 'GPRINT:pg_numbackends_max:MAX:%4.1lf%s Max,',
+ 'GPRINT:pg_numbackends_avg:LAST:%4.1lf%s Last'],
+ pg_scan => ['DEF:pg_scan_avg={file}:value:AVERAGE',
+ 'DEF:pg_scan_min={file}:value:MIN',
+ 'DEF:pg_scan_max={file}:value:MAX',
+ "AREA:pg_scan_max#$HalfBlue",
+ "AREA:pg_scan_min#$Canvas",
+ "LINE1:pg_scan_avg#$FullBlue:Scans",
+ 'GPRINT:pg_scan_min:MIN:%4.1lf%s Min,',
+ 'GPRINT:pg_scan_avg:AVERAGE:%4.1lf%s Avg,',
+ 'GPRINT:pg_scan_max:MAX:%4.1lf%s Max,',
+ 'GPRINT:pg_scan_avg:LAST:%4.1lf%s Last'],
+ pg_xact => ['DEF:pg_xact_avg={file}:value:AVERAGE',
+ 'DEF:pg_xact_min={file}:value:MIN',
+ 'DEF:pg_xact_max={file}:value:MAX',
+ "AREA:pg_xact_max#$HalfBlue",
+ "AREA:pg_xact_min#$Canvas",
+ "LINE1:pg_xact_avg#$FullBlue:Transactions",
+ 'GPRINT:pg_xact_min:MIN:%4.1lf%s Min,',
+ 'GPRINT:pg_xact_avg:AVERAGE:%4.1lf%s Avg,',
+ 'GPRINT:pg_xact_max:MAX:%4.1lf%s Max,',
+ 'GPRINT:pg_xact_avg:LAST:%4.1lf%s Last'],
power => ['-v', 'Watt',
'DEF:avg={file}:value:AVERAGE',
'DEF:min={file}:value:MIN',
diff --git a/contrib/cussh.pl b/contrib/cussh.pl
index f95d54d2010eac76bd1e0a134d17b23fdd9fe383..2ec6308bd90ae130be1de8907cb163139c55de67 100755 (executable)
--- a/contrib/cussh.pl
+++ b/contrib/cussh.pl
elsif ($option eq "timeout") {
$args{"timeout"} = $value;
}
+ elsif ($option eq "identifier") {
+ my $id = getid (\$value);
+ if (!$id)
+ {
+ print STDERR "Not a valid identifier: \"$value\"\n";
+ next;
+ }
+ push @{$args{"identifier"}}, $id;
+ }
else {
print STDERR "Invalid option \"$option\".\n";
return;
diff --git a/src/Makefile.am b/src/Makefile.am
index 21022493ca74d5e8473f8a1cf1dbc0bd66aa4904..2be8cb3ba9d71e366b22923061b8669ccb4ac6b0 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
plugin.c plugin.h \
utils_avltree.c utils_avltree.h \
utils_cache.c utils_cache.h \
+ utils_complain.c utils_complain.h \
utils_ignorelist.c utils_ignorelist.h \
utils_llist.c utils_llist.h \
utils_tail_match.c utils_tail_match.h \
types_list.c types_list.h
collectd_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
-collectd_CFLAGS =
+collectd_CFLAGS = $(AM_CFLAGS)
collectd_LDFLAGS = -export-dynamic
collectd_LDADD =
collectd_DEPENDENCIES =
pkglib_LTLIBRARIES += apache.la
apache_la_SOURCES = apache.c
apache_la_LDFLAGS = -module -avoid-version
-apache_la_CFLAGS =
+apache_la_CFLAGS = $(AM_CFLAGS)
apache_la_LIBADD =
collectd_LDADD += "-dlopen" apache.la
if BUILD_WITH_LIBCURL
pkglib_LTLIBRARIES += ascent.la
ascent_la_SOURCES = ascent.c
ascent_la_LDFLAGS = -module -avoid-version
-ascent_la_CFLAGS = $(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
+ascent_la_CFLAGS = $(AM_CFLAGS) \
+ $(BUILD_WITH_LIBCURL_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
ascent_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
collectd_LDADD += "-dlopen" apache.la
collectd_DEPENDENCIES += ascent.la
if BUILD_PLUGIN_CPU
pkglib_LTLIBRARIES += cpu.la
cpu_la_SOURCES = cpu.c
-cpu_la_CFLAGS =
+cpu_la_CFLAGS = $(AM_CFLAGS)
cpu_la_LDFLAGS = -module -avoid-version
cpu_la_LIBADD =
if BUILD_WITH_LIBKSTAT
if BUILD_PLUGIN_DISK
pkglib_LTLIBRARIES += disk.la
disk_la_SOURCES = disk.c
-disk_la_CFLAGS =
+disk_la_CFLAGS = $(AM_CFLAGS)
disk_la_LDFLAGS = -module -avoid-version
disk_la_LIBADD =
if BUILD_WITH_LIBKSTAT
if BUILD_PLUGIN_INTERFACE
pkglib_LTLIBRARIES += interface.la
interface_la_SOURCES = interface.c
-interface_la_CFLAGS =
+interface_la_CFLAGS = $(AM_CFLAGS)
interface_la_LDFLAGS = -module -avoid-version
interface_la_LIBADD =
collectd_LDADD += "-dlopen" interface.la
if BUILD_PLUGIN_IPMI
pkglib_LTLIBRARIES += ipmi.la
ipmi_la_SOURCES = ipmi.c
-ipmi_la_CFLAGS = $(BUILD_WITH_OPENIPMI_CFLAGS)
+ipmi_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_OPENIPMI_CFLAGS)
ipmi_la_LDFLAGS = -module -avoid-version
ipmi_la_LIBADD = $(BUILD_WITH_OPENIPMI_LIBS)
collectd_LDADD += "-dlopen" ipmi.la
if BUILD_PLUGIN_LIBVIRT
pkglib_LTLIBRARIES += libvirt.la
libvirt_la_SOURCES = libvirt.c
-libvirt_la_CFLAGS = $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
+libvirt_la_CFLAGS = $(AM_CFLAGS) \
+ $(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
libvirt_la_LIBADD = $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
libvirt_la_LDFLAGS = -module -avoid-version
collectd_LDADD += "-dlopen" libvirt.la
if BUILD_PLUGIN_LOAD
pkglib_LTLIBRARIES += load.la
load_la_SOURCES = load.c
-load_la_CFLAGS =
+load_la_CFLAGS = $(AM_CFLAGS)
load_la_LDFLAGS = -module -avoid-version
load_la_LIBADD =
collectd_LDADD += "-dlopen" load.la
pkglib_LTLIBRARIES += memcached.la
memcached_la_SOURCES = memcached.c
memcached_la_LDFLAGS = -module -avoid-version
-memcached_la_CFLAGS =
memcached_la_LIBADD =
if BUILD_WITH_LIBSOCKET
memcached_la_LDFLAGS += -lsocket
if BUILD_PLUGIN_MEMORY
pkglib_LTLIBRARIES += memory.la
memory_la_SOURCES = memory.c
-memory_la_CFLAGS =
+memory_la_CFLAGS = $(AM_CFLAGS)
memory_la_LDFLAGS = -module -avoid-version
memory_la_LIBADD =
collectd_LDADD += "-dlopen" memory.la
pkglib_LTLIBRARIES += mysql.la
mysql_la_SOURCES = mysql.c
mysql_la_LDFLAGS = -module -avoid-version
-mysql_la_CFLAGS =
+mysql_la_CFLAGS = $(AM_CFLAGS)
mysql_la_LIBADD =
collectd_LDADD += "-dlopen" mysql.la
if BUILD_WITH_LIBMYSQL
pkglib_LTLIBRARIES += netlink.la
netlink_la_SOURCES = netlink.c
netlink_la_LDFLAGS = -module -avoid-version
-netlink_la_CFLAGS = $(BUILD_WITH_LIBNETLINK_CFLAGS)
+netlink_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBNETLINK_CFLAGS)
netlink_la_LIBADD = $(BUILD_WITH_LIBNETLINK_LIBS)
collectd_LDADD += "-dlopen" netlink.la
collectd_DEPENDENCIES += netlink.la
collectd_DEPENDENCIES += nginx.la
endif
+if BUILD_PLUGIN_NOTIFY_DESKTOP
+pkglib_LTLIBRARIES += notify_desktop.la
+notify_desktop_la_SOURCES = notify_desktop.c
+notify_desktop_la_CFLAGS = $(AM_CFLAGS) $(LIBNOTIFY_CFLAGS)
+notify_desktop_la_LDFLAGS = -module -avoid-version $(LIBNOTIFY_LIBS)
+collectd_LDADD += "-dlopen" notify_desktop.la
+collectd_DEPENDENCIES += notify_desktop.la
+endif
+
+if BUILD_PLUGIN_NOTIFY_EMAIL
+pkglib_LTLIBRARIES += notify_email.la
+notify_email_la_SOURCES = notify_email.c
+notify_email_la_LDFLAGS = -L/usr/local/lib -lesmtp -lssl -lcrypto -pthread -module -avoid-version
+collectd_LDADD += "-dlopen" notify_email.la
+collectd_DEPENDENCIES += notify_email.la
+endif
+
if BUILD_PLUGIN_NTPD
pkglib_LTLIBRARIES += ntpd.la
ntpd_la_SOURCES = ntpd.c
if BUILD_PLUGIN_PERL
pkglib_LTLIBRARIES += perl.la
perl_la_SOURCES = perl.c
+# Despite C99 providing the "bool" type thru stdbool.h, Perl defines its own
+# version of that type if HAS_BOOL is not defined... *sigh*
+perl_la_CPPFLAGS = $(AM_CPPFLAGS) -DHAS_BOOL=1
perl_la_CFLAGS = $(AM_CFLAGS) \
- $(PERL_CFLAGS) \
- -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
+ $(PERL_CFLAGS) \
+ -DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
perl_la_LDFLAGS = -module -avoid-version \
- $(PERL_LDFLAGS)
+ $(PERL_LDFLAGS)
collectd_LDADD += "-dlopen" perl.la
collectd_DEPENDENCIES += perl.la
endif
collectd_DEPENDENCIES += ping.la
endif
+if BUILD_PLUGIN_POSTGRESQL
+pkglib_LTLIBRARIES += postgresql.la
+postgresql_la_SOURCES = postgresql.c
+postgresql_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBPQ_CPPFLAGS)
+postgresql_la_LDFLAGS = -module -avoid-version \
+ $(BUILD_WITH_LIBPQ_LDFLAGS) -lpq
+collectd_LDADD += "-dlopen" postgresql.la
+collectd_DEPENDENCIES += postgresql.la
+endif
+
if BUILD_PLUGIN_POWERDNS
pkglib_LTLIBRARIES += powerdns.la
powerdns_la_SOURCES = powerdns.c
collectd_DEPENDENCIES += processes.la
endif
+if BUILD_PLUGIN_QMAIL
+pkglib_LTLIBRARIES += qmail.la
+qmail_la_SOURCES = qmail.c
+qmail_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" qmail.la
+collectd_DEPENDENCIES += qmail.la
+endif
+
if BUILD_PLUGIN_RRDTOOL
pkglib_LTLIBRARIES += rrdtool.la
rrdtool_la_SOURCES = rrdtool.c
rrdtool_la_LDFLAGS = -module -avoid-version
-rrdtool_la_CFLAGS = $(BUILD_WITH_LIBRRD_CFLAGS)
+rrdtool_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBRRD_CFLAGS)
rrdtool_la_LIBADD = $(BUILD_WITH_LIBRRD_LDFLAGS)
collectd_LDADD += "-dlopen" rrdtool.la
collectd_DEPENDENCIES += rrdtool.la
if BUILD_PLUGIN_SENSORS
pkglib_LTLIBRARIES += sensors.la
sensors_la_SOURCES = sensors.c
-sensors_la_CFLAGS = $(BUILD_WITH_LIBSENSORS_CFLAGS)
+sensors_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSENSORS_CFLAGS)
sensors_la_LDFLAGS = -module -avoid-version $(BUILD_WITH_LIBSENSORS_LDFLAGS)
sensors_la_LIBADD = -lsensors
collectd_LDADD += "-dlopen" sensors.la
pkglib_LTLIBRARIES += snmp.la
snmp_la_SOURCES = snmp.c
snmp_la_LDFLAGS = -module -avoid-version
-snmp_la_CFLAGS =
+snmp_la_CFLAGS = $(AM_CFLAGS)
snmp_la_LIBADD =
if BUILD_WITH_LIBNETSNMP
snmp_la_CFLAGS += $(BUILD_WITH_LIBSNMP_CFLAGS)
if BUILD_PLUGIN_SWAP
pkglib_LTLIBRARIES += swap.la
swap_la_SOURCES = swap.c
-swap_la_CFLAGS =
+swap_la_CFLAGS = $(AM_CFLAGS)
swap_la_LDFLAGS = -module -avoid-version
swap_la_LIBADD =
collectd_LDADD += "-dlopen" swap.la
collectd_DEPENDENCIES += teamspeak2.la
endif
+if BUILD_PLUGIN_THERMAL
+pkglib_LTLIBRARIES += thermal.la
+thermal_la_SOURCES = thermal.c
+thermal_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" thermal.la
+collectd_DEPENDENCIES += thermal.la
+endif
+
if BUILD_PLUGIN_UNIXSOCK
pkglib_LTLIBRARIES += unixsock.la
unixsock_la_SOURCES = unixsock.c \
if BUILD_PLUGIN_USERS
pkglib_LTLIBRARIES += users.la
users_la_SOURCES = users.c
-users_la_CFLAGS =
+users_la_CFLAGS = $(AM_CFLAGS)
users_la_LDFLAGS = -module -avoid-version
users_la_LIBADD =
if BUILD_WITH_LIBSTATGRAB
diff --git a/src/apache.c b/src/apache.c
index a2f41f4bdab52f017827073d5373ae64c08ea5ca..c6bf8addfed4d6918c7345e5839b3a92105a4c3f 100644 (file)
--- a/src/apache.c
+++ b/src/apache.c
{
int status;
- status = snprintf (credentials, sizeof (credentials), "%s:%s",
+ status = ssnprintf (credentials, sizeof (credentials), "%s:%s",
user, (pass == NULL) ? "" : pass);
if (status >= sizeof (credentials))
{
"truncated.");
return (-1);
}
- credentials[sizeof (credentials) - 1] = '\0';
curl_easy_setopt (curl, CURLOPT_USERPWD, credentials);
}
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "apache", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
- {
- strncpy (vl.type_instance, type_instance,
+ sstrncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
- }
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void submit_counter */
static void submit_gauge (const char *type, const char *type_instance,
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "apache", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
- {
- strncpy (vl.type_instance, type_instance,
+ sstrncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
- }
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void submit_counter */
static void submit_scoreboard (char *buf)
diff --git a/src/apcups.c b/src/apcups.c
index c948f5a165b8b5f14d298601de99c90a4cc045e2..227c703c558fef41b8b338079c27321b281f5f48 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
assert ((port > 0x00000000) && (port <= 0x0000FFFF));
/* Convert the port to a string */
- snprintf (port_str, 8, "%i", port);
- port_str[7] = '\0';
+ ssnprintf (port_str, sizeof (port_str), "%i", port);
/* Resolve name */
memset ((void *) &ai_hints, '\0', sizeof (ai_hints));
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "apcups", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
- strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
}
static void apc_submit (struct apc_detail_s *apcups_detail)
diff --git a/src/apple_sensors.c b/src/apple_sensors.c
index 5e957b6f88a9e9b302634b6aa0f053118c6db020..629633589bc0b086b3918d167090512b2bba33d2 100644 (file)
--- a/src/apple_sensors.c
+++ b/src/apple_sensors.c
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "apple_sensors", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type))
sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
}
static int as_read (void)
if (CFGetTypeID (property) != CFStringGetTypeID ())
continue;
if (!CFStringGetCString (property,
- type, 128,
+ type, sizeof (type),
kCFStringEncodingASCII))
continue;
- type[127] = '\0';
+ type[sizeof (type) - 1] = '\0';
/* Copy the sensor location. This will be used as `instance'. */
property = NULL;
if (CFGetTypeID (property) != CFStringGetTypeID ())
continue;
if (!CFStringGetCString (property,
- inst, 128,
+ inst, sizeof (inst),
kCFStringEncodingASCII))
continue;
- inst[127] = '\0';
+ inst[sizeof (inst) - 1] = '\0';
for (i = 0; i < 128; i++)
{
if (inst[i] == '\0')
diff --git a/src/ascent.c b/src/ascent.c
index 8c0bbec600152aee448cd34a7008eae4dadabcc0..2ad641dfede55d98b9a3cf92ebd288dd20881ed4 100644 (file)
--- a/src/ascent.c
+++ b/src/ascent.c
typedef struct player_info_s player_info_t;
#define PLAYER_INFO_STATIC_INIT { -1, -1, -1, -1, -1 }
-static char *url = NULL;
-static char *user = NULL;
-static char *pass = NULL;
-static char *cacert = NULL;
+static char *url = NULL;
+static char *user = NULL;
+static char *pass = NULL;
+static char *verify_peer = NULL;
+static char *verify_host = NULL;
+static char *cacert = NULL;
static CURL *curl = NULL;
"URL",
"User",
"Password",
+ "VerifyPeer",
+ "VerifyHost",
"CACert"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+
if (type_instance != NULL)
sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
return (0);
} /* }}} int ascent_submit_gauge */
return (config_set (&user, value));
else if (strcasecmp (key, "Password") == 0)
return (config_set (&pass, value));
+ else if (strcasecmp (key, "VerifyPeer") == 0)
+ return (config_set (&verify_peer, value));
+ else if (strcasecmp (key, "VerifyHost") == 0)
+ return (config_set (&verify_host, value));
else if (strcasecmp (key, "CACert") == 0)
return (config_set (&cacert, value));
else
{
int status;
- status = snprintf (credentials, sizeof (credentials), "%s:%s",
+ status = ssnprintf (credentials, sizeof (credentials), "%s:%s",
user, (pass == NULL) ? "" : pass);
if (status >= sizeof (credentials))
{
"credentials have been truncated.");
return (-1);
}
- credentials[sizeof (credentials) - 1] = '\0';
curl_easy_setopt (curl, CURLOPT_USERPWD, credentials);
}
curl_easy_setopt (curl, CURLOPT_URL, url);
+ if ((verify_peer == NULL) || (strcmp (verify_peer, "true") == 0))
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 1);
+ else
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, 0);
+
+ if ((verify_host == NULL) || (strcmp (verify_host, "true") == 0))
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 2);
+ else
+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST, 0);
+
if (cacert != NULL)
curl_easy_setopt (curl, CURLOPT_CAINFO, cacert);
diff --git a/src/battery.c b/src/battery.c
index badd8e752f47717df72b63cb5360e441b0c203f8..9f1bee654e014812f254070a458f2be5a60508d3 100644 (file)
--- a/src/battery.c
+++ b/src/battery.c
#elif KERNEL_LINUX
static int battery_pmu_num = 0;
static char *battery_pmu_file = "/proc/pmu/battery_%i";
+static const char *battery_acpi_dir = "/proc/acpi/battery";
#endif /* KERNEL_LINUX */
static int battery_init (void)
for (battery_pmu_num = 0; ; battery_pmu_num++)
{
- len = snprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num);
+ len = ssnprintf (filename, sizeof (filename), battery_pmu_file, battery_pmu_num);
if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
break;
@@ -101,8 +102,9 @@ static void battery_submit (const char *plugin_instance, const char *type, doubl
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "battery", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void battery_submit */
#if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H
}
#endif /* HAVE_IOKIT_IOKITLIB_H */
+#if KERNEL_LINUX
+static int battery_read_acpi (const char *name)
+{
+ double current = INVALID_VALUE;
+ double voltage = INVALID_VALUE;
+ double charge = INVALID_VALUE;
+ double *valptr = NULL;
+ int charging = 0;
+
+ char filename[256];
+ FILE *fh;
+
+ char buffer[1024];
+ char *fields[8];
+ int numfields;
+ char *endptr;
+ int len;
+
+ len = ssnprintf (filename, sizeof (filename), "%s/%s/state", battery_acpi_dir, name);
+
+ if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
+ return -1;
+
+ if ((fh = fopen (filename, "r")) == NULL) {
+ char errbuf[1024];
+ ERROR ("Cannot open `%s': %s", filename,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return -1;
+ }
+
+ /*
+ * [11:00] <@tokkee> $ cat /proc/acpi/battery/BAT1/state
+ * [11:00] <@tokkee> present: yes
+ * [11:00] <@tokkee> capacity state: ok
+ * [11:00] <@tokkee> charging state: charging
+ * [11:00] <@tokkee> present rate: 1724 mA
+ * [11:00] <@tokkee> remaining capacity: 4136 mAh
+ * [11:00] <@tokkee> present voltage: 12428 mV
+ */
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ {
+ numfields = strsplit (buffer, fields, 8);
+
+ if (numfields < 3)
+ continue;
+
+ if ((strcmp (fields[0], "charging") == 0)
+ && (strcmp (fields[1], "state:") == 0))
+ {
+ if (strcmp (fields[2], "charging") == 0)
+ charging = 1;
+ else
+ charging = 0;
+ continue;
+ }
+
+ if ((strcmp (fields[0], "present") == 0)
+ && (strcmp (fields[1], "rate:") == 0))
+ valptr = ¤t;
+ else if ((strcmp (fields[0], "remaining") == 0)
+ && (strcmp (fields[1], "capacity:") == 0))
+ valptr = &charge;
+ else if ((strcmp (fields[0], "present") == 0)
+ && (strcmp (fields[1], "voltage:") == 0))
+ valptr = &voltage;
+ else
+ continue;
+
+ endptr = NULL;
+ errno = 0;
+ *valptr = strtod (fields[2], &endptr) / 1000.0;
+
+ if ((fields[2] == endptr) || (errno != 0))
+ *valptr = INVALID_VALUE;
+ } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
+
+ fclose (fh);
+
+ if ((current != INVALID_VALUE) && (charging == 0))
+ current *= -1;
+
+ if (charge != INVALID_VALUE)
+ battery_submit ("0", "charge", charge);
+ if (current != INVALID_VALUE)
+ battery_submit ("0", "current", current);
+ if (voltage != INVALID_VALUE)
+ battery_submit ("0", "voltage", voltage);
+
+ return 0;
+}
+#endif /* KERNEL_LINUX */
+
+
static int battery_read (void)
{
#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H
double charge = INVALID_VALUE;
double *valptr = NULL;
- len = snprintf (filename, sizeof (filename), battery_pmu_file, i);
+ len = ssnprintf (filename, sizeof (filename), battery_pmu_file, i);
if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
continue;
- len = snprintf (batnum_str, sizeof (batnum_str), "%i", i);
+ len = ssnprintf (batnum_str, sizeof (batnum_str), "%i", i);
if ((len < 0) || ((unsigned int)len >= sizeof (batnum_str)))
continue;
battery_submit ("0", "voltage", voltage);
}
- if (access ("/proc/acpi/battery", R_OK | X_OK) == 0)
- {
- double current = INVALID_VALUE;
- double voltage = INVALID_VALUE;
- double charge = INVALID_VALUE;
- double *valptr = NULL;
- int charging = 0;
-
- struct dirent *ent;
- DIR *dh;
+ walk_directory (battery_acpi_dir, battery_read_acpi);
- if ((dh = opendir ("/proc/acpi/battery")) == NULL)
- {
- char errbuf[1024];
- ERROR ("Cannot open `/proc/acpi/battery': %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
- }
-
- while ((ent = readdir (dh)) != NULL)
- {
- if (ent->d_name[0] == '.')
- continue;
-
- len = snprintf (filename, sizeof (filename),
- "/proc/acpi/battery/%s/state",
- ent->d_name);
- if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
- continue;
-
- if ((fh = fopen (filename, "r")) == NULL)
- {
- char errbuf[1024];
- ERROR ("Cannot open `%s': %s", filename,
- sstrerror (errno, errbuf,
- sizeof (errbuf)));
- continue;
- }
-
- /*
- * [11:00] <@tokkee> $ cat /proc/acpi/battery/BAT1/state
- * [11:00] <@tokkee> present: yes
- * [11:00] <@tokkee> capacity state: ok
- * [11:00] <@tokkee> charging state: charging
- * [11:00] <@tokkee> present rate: 1724 mA
- * [11:00] <@tokkee> remaining capacity: 4136 mAh
- * [11:00] <@tokkee> present voltage: 12428 mV
- */
- while (fgets (buffer, sizeof (buffer), fh) != NULL)
- {
- numfields = strsplit (buffer, fields, 8);
-
- if (numfields < 3)
- continue;
-
- if ((strcmp (fields[0], "present") == 0)
- && (strcmp (fields[1], "rate:") == 0))
- valptr = ¤t;
- else if ((strcmp (fields[0], "remaining") == 0)
- && (strcmp (fields[1], "capacity:") == 0))
- valptr = &charge;
- else if ((strcmp (fields[0], "present") == 0)
- && (strcmp (fields[1], "voltage:") == 0))
- valptr = &voltage;
- else
- valptr = NULL;
-
- if ((strcmp (fields[0], "charging") == 0)
- && (strcmp (fields[1], "state:") == 0))
- {
- if (strcmp (fields[2], "charging") == 0)
- charging = 1;
- else
- charging = 0;
- }
-
- if (valptr != NULL)
- {
- char *endptr;
-
- endptr = NULL;
- errno = 0;
-
- *valptr = strtod (fields[2], &endptr) / 1000.0;
-
- if ((fields[2] == endptr) || (errno != 0))
- *valptr = INVALID_VALUE;
- }
- } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
-
- fclose (fh);
-
- if ((current != INVALID_VALUE) && (charging == 0))
- current *= -1;
-
- if (charge != INVALID_VALUE)
- battery_submit ("0", "charge", charge);
- if (current != INVALID_VALUE)
- battery_submit ("0", "current", current);
- if (voltage != INVALID_VALUE)
- battery_submit ("0", "voltage", voltage);
- }
-
- closedir (dh);
- }
#endif /* KERNEL_LINUX */
return (0);
diff --git a/src/collectd-perl.pod b/src/collectd-perl.pod
index 8cdf08bb3b6807229bb4a985a5b01f74771f8378..b7ae9cace9c89f636172c1d27e5ccc5fbd4b3c9c 100644 (file)
--- a/src/collectd-perl.pod
+++ b/src/collectd-perl.pod
time => time (),
host => $hostname_g,
plugin => 'myplugin',
+ type => 'myplugin',
plugin_instance => '',
type_instance => ''
}
Removes a callback or data-set from collectd's internal list of
functionsE<nbsp>/ datasets.
-=item B<plugin_dispatch_values> (I<type>, I<value-list>)
+=item B<plugin_dispatch_values> (I<value-list>)
-Submits a I<value-list> of type I<type> to the daemon. If the data-set I<type>
+Submits a I<value-list> to the daemon. If the data-set identified by
+I<value-list>->{I<type>}
is found (and the number of values matches the number of data-sources) then the
type, data-set and value-list is passed to all write-callbacks that are
registered with the daemon.
+B<Note>: Prior to version 4.4 of collectd, the data-set type used to be passed
+as the first argument to B<plugin_register>. This syntax is still supported
+for backwards compatibility but has been deprecated and will be removed in
+some future version of collectd.
+
=item B<plugin_flush> ([B<timeout> => I<timeout>,] [B<plugins> => I<...>])
Flush one or more plugins. I<timeout> is passed on to the registered
index 971cb36dc0a138a9c826d5148178714e57078b91..1e00baf3d118ea1839f0d03208aeca127b08dca4 100644 (file)
-> | PUTNOTIF type=temperature severity=warning time=1201094702 message=The roof is on fire!
<- | 0 Success
-=item B<FLUSH> [B<timeout=>I<Timeout>] [B<plugin=>I<Plugin> [...]]
+=item B<FLUSH> [B<timeout=>I<Timeout>] [B<plugin=>I<Plugin> [...]] [B<identifier=>I<Ident> [...]]
Flushes all cached data older than I<Timeout> seconds. If no timeout has been
-specified, it defaults to -1 which causes all data to be flushed. B<timeout>
-may be specified multiple times - each occurrence applies to plugins listed
-afterwards.
+specified, it defaults to -1 which causes all data to be flushed.
-If specified, only specific plugins are flushed. Otherwise all plugins
-providing a flush callback are flushed.
+If the B<plugin> option has been specified, only the I<Plugin> plugin will be
+flushed. You can have multiple B<plugin> options to flush multiple plugins in
+one go. If the B<plugin> option is not given all plugins providing a flush
+callback will be flushed.
+
+If the B<identifier> option is given only the specified values will be flushed.
+This is meant to be used by graphing or displaying frontends which want to have
+the lastest values for a specific graph. Again, you can specify the
+B<identifier> option multiple times to flush several values. If this option is
+not specified at all, all values will be flushed.
Example:
- -> | FLUSH
- <- | 0 Done
+ -> | FLUSH plugin=rrdtool identifier=localhost/df/df-root identifier=localhost/df/df-var
+ <- | 0 Done: 2 successful, 0 errors
=back
diff --git a/src/collectd.c b/src/collectd.c
index a3f63b48007336bc48621fa366cbf90a96ccff4c..5484322f16eb5feabe8dce1039db7fcda56932cf 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
str = global_option_get ("Hostname");
if (str != NULL)
{
- strncpy (hostname_g, str, sizeof (hostname_g));
- hostname_g[sizeof (hostname_g) - 1] = '\0';
+ sstrncpy (hostname_g, str, sizeof (hostname_g));
return (0);
}
if (ai_ptr->ai_canonname == NULL)
continue;
- strncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g));
- hostname_g[sizeof (hostname_g) - 1] = '\0';
+ sstrncpy (hostname_g, ai_ptr->ai_canonname, sizeof (hostname_g));
break;
}
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index f4e04d34515964e2f698383256bdf090fc40db31..7c36643256ff1d17be67e48c0abb2f79af836c3f 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
@BUILD_PLUGIN_NETWORK_TRUE@LoadPlugin network
@BUILD_PLUGIN_NFS_TRUE@LoadPlugin nfs
@BUILD_PLUGIN_NGINX_TRUE@LoadPlugin nginx
+@BUILD_PLUGIN_NOTIFY_DESKTOP_TRUE@LoadPlugin notify_desktop
+@BUILD_PLUGIN_NOTIFY_EMAIL_TRUE@LoadPlugin notify_email
@BUILD_PLUGIN_NTPD_TRUE@LoadPlugin ntpd
@BUILD_PLUGIN_NUT_TRUE@LoadPlugin nut
@BUILD_PLUGIN_PERL_TRUE@LoadPlugin perl
@BUILD_PLUGIN_PING_TRUE@LoadPlugin ping
+@BUILD_PLUGIN_POSTGRESQL_TRUE@LoadPlugin postgresql
@BUILD_PLUGIN_POWERDNS_TRUE@LoadPlugin powerdns
@BUILD_PLUGIN_PROCESSES_TRUE@LoadPlugin processes
@BUILD_PLUGIN_RRDTOOL_TRUE@LoadPlugin rrdtool
@BUILD_PLUGIN_TAPE_TRUE@LoadPlugin tape
@BUILD_PLUGIN_TCPCONNS_TRUE@LoadPlugin tcpconns
@BUILD_PLUGIN_TEAMSPEAK2_TRUE@LoadPlugin teamspeak2
+@BUILD_PLUGIN_THERMAL_TRUE@LoadPlugin thermal
@BUILD_PLUGIN_UNIXSOCK_TRUE@LoadPlugin unixsock
@BUILD_PLUGIN_USERS_TRUE@LoadPlugin users
@BUILD_PLUGIN_UUID_TRUE@LoadPlugin uuid
# CACert "/etc/ssl/ca.crt"
#</Plugin>
+#<Plugin notify_desktop>
+# OkayTimeout 1000
+# WarningTimeout 5000
+# FailureTimeout 0
+#</Plugin>
+
+#<Plugin notify_email>
+# SMTPServer "localhost"
+# SMTPPort 25
+# SMTPUser "my-username"
+# SMTPPassword "my-password"
+# From "collectd@main0server.com"
+# # <WARNING/FAILURE/OK> on <hostname>. beware! do not use not more than two %s in this string!!!
+# Subject "Aaaaaa!! %s on %s!!!!!"
+# Recipient "email1@domain1.net"
+# Recipient "email2@domain2.com"
+#</Plugin>
+
#<Plugin ntpd>
# Host "localhost"
# Port 123
# TTL 255
#</Plugin>
+#<Plugin postgresql>
+# <Database foo>
+# Host "hostname"
+# Port 5432
+# User "username"
+# Password "secret"
+#
+# SSLMode "prefer"
+# KRBSrvName "kerberos_service_name"
+# </Database>
+#
+# <Database bar>
+# Service "service_name"
+# </Database>
+#</Plugin>
+
#<Plugin powerdns>
# <Server "server_name">
# Collect "latency"
# Server "8767"
#</Plugin>
+#<Plugin thermal>
+# ForceUseProcfs false
+# Device "THRM"
+# IgnoreSelected false
+#</Plugin>
+
#<Plugin unixsock>
# SocketFile "@prefix@/var/run/@PACKAGE_NAME@-unixsock"
# SocketGroup "collectd"
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index afa05711bfe0de4459bc35cc51a784939915befc..f20f42e3f41ee3d01fc7877bed4585f0fa9bfd27 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
ignored. Values are either string, enclosed in double-quotes,
(floating-point-)numbers or a boolean expression, i.E<nbsp>e. either B<true> or
B<false>. String containing of only alphanumeric characters and underscores do
-not need to be quoted.
+not need to be quoted. Lines may be wrapped by using `\' as the last character
+before the newline. This allows long lines to be split into multiple lines.
+Quoted strings may be wrapped as well. However, those are treated special in
+that whitespace at the beginning of the following lines will be ignored, which
+allows for nicely indenting the wrapped lines.
The configuration is read and processed in order, i.E<nbsp>e. from top to
bottom. So the plugins are loaded in the order listed in this config file. It
Optional password needed for authentication.
+=item B<VerifyPeer> B<true|false>
+
+Enable or disable peer SSL certificate verification. See
+L<http://curl.haxx.se/docs/sslcerts.html> for details. Enabled by default.
+
+=item B<VerifyHost> B<true|false>
+
+Enable or disable peer host name verification. If enabled, the plugin checks
+if the C<Common Name> or a C<Subject Alternate Name> field of the SSL
+certificate matches the host name provided by the B<URL> option. If this
+identity check fails, the connection is aborted. Obviously, only works when
+connecting to a SSL enabled server. Enabled by default.
+
=item B<CACert> I<File>
File that holds one or more SSL certificates. If you want to use HTTPS you will
=back
+=head2 Plugin C<notify_desktop>
+
+This plugin sends a desktop notification to a notification daemon, as defined
+in the Desktop Notification Specification. To actually display the
+notifications, B<notification-daemon> is required and B<collectd> has to be
+able to access the X server.
+
+The Desktop Notification Specification can be found at
+L<http://www.galago-project.org/specs/notification/>.
+
+=over 4
+
+=item B<OkayTimeout> I<timeout>
+
+=item B<WarningTimeout> I<timeout>
+
+=item B<FailureTimeout> I<timeout>
+
+Set the I<timeout>, in milliseconds, after which to expire the notification
+for C<OKAY>, C<WARNING> and C<FAILURE> severities respectively. If zero has
+been specified, the displayed notification will not be closed at all - the
+user has to do so herself. These options default to 5000. If a negative number
+has been specified, the default is used as well.
+
+=back
+
=head2 Plugin C<ntpd>
=over 4
=back
+=head2 Plugin C<postgresql>
+
+The C<postgresql> plugin queries statistics from PostgreSQL databases. It
+keeps a persistent connection to all configured databases and tries to
+reconnect if the connection has been interrupted. The statistics are collected
+from PostgreSQL's B<statistics collector> which thus has to be enabled for
+this plugin to work correctly. This should usually be the case by default.
+See the section "The Statistics Collector" of the B<PostgreSQL Documentation>
+for details.
+
+The B<PostgreSQL Documentation> manual can be found at
+L<http://www.postgresql.org/docs/manuals/>.
+
+ <Plugin postgresql>
+ <Database foo>
+ Host "hostname"
+ Port "5432"
+ User "username"
+ Password "secret"
+ SSLMode "prefer"
+ KRBSrvName "kerberos_service_name"
+ </Database>
+ <Database bar>
+ Service "service_name"
+ </Database>
+ </Plugin>
+
+=over 4
+
+=item B<Database> block
+
+The B<Database> block defines one PostgreSQL database for which to collect
+statistics. It accepts a single mandatory argument which specifies the
+database name. None of the other options are required. PostgreSQL will use
+default values as documented in the section "CONNECTING TO A DATABASE" in the
+L<psql(1)> manpage. However, be aware that those defaults may be influenced by
+the user collectd is run as and special environment variables. See the manpage
+for details.
+
+=item B<Host> I<hostname>
+
+Specify the hostname or IP of the PostgreSQL server to connect to. If the
+value begins with a slash, it is interpreted as the directory name in which to
+look for the UNIX domain socket.
+
+This option is also used to determine the hostname that is associated with a
+collected data set. If it has been omitted or either begins with with a slash
+or equals B<localhost> it will be replaced with the global hostname definition
+of collectd. Any other value will be passed literally to collectd when
+dispatching values. Also see the global B<Hostname> and B<FQDNLookup> options.
+
+=item B<Port> I<port>
+
+Specify the TCP port or the local UNIX domain socket file extension of the
+server.
+
+=item B<User> I<username>
+
+Specify the username to be used when connecting to the server.
+
+=item B<Password> I<password>
+
+Specify the password to be used when connecting to the server.
+
+=item B<SSLMode> I<disable>|I<allow>|I<prefer>|I<require>
+
+Specify whether to use an SSL connection when contacting the server. The
+following modes are supported:
+
+=over 4
+
+=item I<disable>
+
+Do not use SSL at all.
+
+=item I<allow>
+
+First, try to connect without using SSL. If that fails, try using SSL.
+
+=item I<prefer> (default)
+
+First, try to connect using SSL. If that fails, try without using SSL.
+
+=item I<require>
+
+Use SSL only.
+
+=back
+
+=item B<KRBSrvName> I<kerberos_service_name>
+
+Specify the Kerberos service name to use when authenticating with Kerberos 5
+or GSSAPI. See the sections "Kerberos authentication" and "GSSAPI" of the
+B<PostgreSQL Documentation> for details.
+
+=item B<Service> I<service_name>
+
+Specify the PostgreSQL service name to use for additional parameters. That
+service has to be defined in F<pg_service.conf> and holds additional
+connection parameters. See the section "The Connection Service File" in the
+B<PostgreSQL Documentation> for details.
+
+=back
+
=head2 Plugin C<powerdns>
The C<powerdns> plugin queries statistics from an authoritative PowerDNS
=back
+=head2 Plugin C<thermal>
+
+=over 4
+
+=item B<ForceUseProcfs> I<true>|I<false>
+
+By default, the C<thermal> plugin tries to read the statistics from the Linux
+C<sysfs> interface. If that is not available, the plugin falls back to the
+C<procfs> interface. By setting this option to I<true>, you can force the
+plugin to use the latter. This option defaults to I<false>.
+
+=item B<Device> I<Device>
+
+Selects the name of the thermal device that you want to collect or ignore,
+depending on the value of the B<IgnoreSelected> option. This option may be
+used multiple times to specify a list of devices.
+
+=item B<IgnoreSelected> I<true>|I<false>
+
+Invert the selection: If set to true, all devices B<except> the ones that
+match the device names specified by the B<Device> option are collected. By
+default only selected devices are collected if a selection is made. If no
+selection is configured at all, B<all> devices are selected.
+
+=back
+
=head2 Plugin C<unixsock>
=over 4
L<hddtemp(8)>,
L<kstat(3KSTAT)>,
L<mbmon(1)>,
+L<psql(1)>,
L<rrdtool(1)>,
L<sensors(1)>
diff --git a/src/collectd.h b/src/collectd.h
index eece4203894b1a51786446b6787fba77f152d944..a262bf1d1fc99621e07b9aea7619351bc736d809 100644 (file)
--- a/src/collectd.h
+++ b/src/collectd.h
#if HAVE_STDINT_H
# include <stdint.h>
#endif
+#if HAVE_STDBOOL_H
+# include <stdbool.h>
+#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
diff --git a/src/common.c b/src/common.c
index 82b4aaae87745b0e6afb5ca4e1004d9c2de8647a..fd7c19938e7119f1a9f8347059b9c4d85d86d04c 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (dest);
} /* char *sstrncpy */
+int ssnprintf (char *dest, size_t n, const char *format, ...)
+{
+ int ret = 0;
+ va_list ap;
+
+ va_start (ap, format);
+ ret = vsnprintf (dest, n, format, ap);
+ dest[n - 1] = '\0';
+ va_end (ap);
+
+ return (ret);
+} /* int ssnprintf */
+
char *sstrdup (const char *s)
{
char *r;
pthread_mutex_lock (&strerror_r_lock);
temp = strerror (errnum);
- strncpy (buf, temp, buflen);
+ sstrncpy (buf, temp, buflen);
pthread_mutex_unlock (&strerror_r_lock);
}
if (buf[0] == '\0')
{
if ((temp != NULL) && (temp != buf) && (temp[0] != '\0'))
- strncpy (buf, temp, buflen);
+ sstrncpy (buf, temp, buflen);
else
- strncpy (buf, "strerror_r did not return "
+ sstrncpy (buf, "strerror_r did not return "
"an error message", buflen);
}
}
#else
if (strerror_r (errnum, buf, buflen) != 0)
{
- snprintf (buf, buflen, "Error #%i; "
+ ssnprintf (buf, buflen, "Error #%i; "
"Additionally, strerror_r failed.",
errnum);
}
#endif /* STRERROR_R_CHAR_P */
- buf[buflen - 1] = '\0';
return (buf);
} /* char *sstrerror */
if ((len = strlen (file_orig)) < 1)
return (-1);
- else if (len >= 512)
+ else if (len >= sizeof (file_copy))
return (-1);
/*
/*
* Create a copy for `strtok_r' to destroy
*/
- strncpy (file_copy, file_orig, 512);
- file_copy[511] = '\0';
+ sstrncpy (file_copy, file_orig, sizeof (file_copy));
/*
* Break into components. This will eat up several slashes in a row and
if (kc == NULL)
return (-1);
- snprintf (ident, 128, "%s,%i,%s", module, instance, name);
- ident[127] = '\0';
+ ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name);
if (*ksp_ptr == NULL)
{
if ((plugin_instance == NULL) || (strlen (plugin_instance) == 0))
{
if ((type_instance == NULL) || (strlen (type_instance) == 0))
- status = snprintf (ret, ret_len, "%s/%s/%s",
+ status = ssnprintf (ret, ret_len, "%s/%s/%s",
hostname, plugin, type);
else
- status = snprintf (ret, ret_len, "%s/%s/%s-%s",
+ status = ssnprintf (ret, ret_len, "%s/%s/%s-%s",
hostname, plugin, type,
type_instance);
}
else
{
if ((type_instance == NULL) || (strlen (type_instance) == 0))
- status = snprintf (ret, ret_len, "%s/%s-%s/%s",
+ status = ssnprintf (ret, ret_len, "%s/%s-%s/%s",
hostname, plugin, plugin_instance,
type);
else
- status = snprintf (ret, ret_len, "%s/%s-%s/%s-%s",
+ status = ssnprintf (ret, ret_len, "%s/%s-%s/%s-%s",
hostname, plugin, plugin_instance,
type, type_instance);
}
n->severity = severity;
if (message != NULL)
- strncpy (n->message, message, sizeof (n->message));
+ sstrncpy (n->message, message, sizeof (n->message));
if (host != NULL)
- strncpy (n->host, host, sizeof (n->host));
+ sstrncpy (n->host, host, sizeof (n->host));
if (plugin != NULL)
- strncpy (n->plugin, plugin, sizeof (n->plugin));
+ sstrncpy (n->plugin, plugin, sizeof (n->plugin));
if (plugin_instance != NULL)
- strncpy (n->plugin_instance, plugin_instance,
+ sstrncpy (n->plugin_instance, plugin_instance,
sizeof (n->plugin_instance));
if (type != NULL)
- strncpy (n->type, type, sizeof (n->type));
+ sstrncpy (n->type, type, sizeof (n->type));
if (type_instance != NULL)
- strncpy (n->type_instance, type_instance,
+ sstrncpy (n->type_instance, type_instance,
sizeof (n->type_instance));
- n->message[sizeof (n->message) - 1] = '\0';
- n->host[sizeof (n->host) - 1] = '\0';
- n->plugin[sizeof (n->plugin) - 1] = '\0';
- n->plugin_instance[sizeof (n->plugin_instance) - 1] = '\0';
- n->type[sizeof (n->type) - 1] = '\0';
- n->type_instance[sizeof (n->type_instance) - 1] = '\0';
-
return (0);
} /* int notification_init */
+
+int walk_directory (const char *dir, dirwalk_callback_f callback)
+{
+ struct dirent *ent;
+ DIR *dh;
+ int ok = 0;
+
+ if ((dh = opendir (dir)) == NULL)
+ {
+ char errbuf[1024];
+ ERROR ("Cannot open '%s': %s", dir,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return -1;
+ }
+
+ while ((ent = readdir (dh)) != NULL)
+ {
+ if (ent->d_name[0] == '.')
+ continue;
+
+ if (!callback(ent->d_name))
+ ++ok;
+ }
+
+ closedir (dh);
+
+ return ok ? 0 : -1;
+}
+
+int read_file_contents (const char *filename, char *buf, int bufsize)
+{
+ FILE *fh;
+ int n;
+
+ if ((fh = fopen (filename, "r")) == NULL)
+ return -1;
+
+ n = fread(buf, 1, bufsize, fh);
+ fclose(fh);
+
+ return n;
+}
+
+
diff --git a/src/common.h b/src/common.h
index e99aea697e45f854b30a50d0b089b8cf20ddf406..a5e2167b6c1e3565a96d2e399aee0616923f3133 100644 (file)
--- a/src/common.h
+++ b/src/common.h
#define STATIC_ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a)))
char *sstrncpy (char *dest, const char *src, size_t n);
+int ssnprintf (char *dest, size_t n, const char *format, ...);
char *sstrdup(const char *s);
void *smalloc(size_t size);
char *sstrerror (int errnum, char *buf, size_t buflen);
notification_init (n, NOTIF_FAILURE, NULL, \
(vl)->host, (vl)->plugin, (vl)->plugin_instance, \
(ds)->type, (vl)->type_instance)
+
+typedef int (*dirwalk_callback_f)(const char *filename);
+int walk_directory (const char *dir, dirwalk_callback_f callback);
+int read_file_contents (const char *filename, char *buf, int bufsize);
+
#endif /* COMMON_H */
diff --git a/src/configfile.c b/src/configfile.c
index 1df911195df20c358e89e6f4012f9e6ac5e82a0b..d483032af71b398d10a44c808c65285e55e805e8 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
else if (ci->values[0].type == OCONFIG_TYPE_NUMBER)
{
char tmp[128];
- snprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number);
- tmp[127] = '\0';
+ ssnprintf (tmp, sizeof (tmp), "%lf", ci->values[0].value.number);
return (global_option_set (ci->key, tmp));
}
else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN)
int status = -1;
if (ci->values[i].type == OCONFIG_TYPE_STRING)
- status = snprintf (buffer_ptr, buffer_free, " %s",
+ status = ssnprintf (buffer_ptr, buffer_free, " %s",
ci->values[i].value.string);
else if (ci->values[i].type == OCONFIG_TYPE_NUMBER)
- status = snprintf (buffer_ptr, buffer_free, " %lf",
+ status = ssnprintf (buffer_ptr, buffer_free, " %lf",
ci->values[i].value.number);
else if (ci->values[i].type == OCONFIG_TYPE_BOOLEAN)
- status = snprintf (buffer_ptr, buffer_free, " %s",
+ status = ssnprintf (buffer_ptr, buffer_free, " %s",
ci->values[i].value.boolean
? "true" : "false");
if ((de->d_name[0] == '.') || (de->d_name[0] == '\0'))
continue;
- status = snprintf (name, sizeof (name), "%s/%s",
+ status = ssnprintf (name, sizeof (name), "%s/%s",
dir, de->d_name);
if (status >= sizeof (name))
{
diff --git a/src/cpu.c b/src/cpu.c
index 0fadc06458d2fbb5ace382a731bb6bcf19283bb3..e9ab78320d4523848274f726eb42e2bb87eb030f 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "cpu", sizeof (vl.plugin));
- snprintf (vl.plugin_instance, sizeof (vl.type_instance),
+ ssnprintf (vl.plugin_instance, sizeof (vl.type_instance),
"%i", cpu_num);
- vl.plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0';
+ sstrncpy (vl.type, "cpu", sizeof (vl.type));
sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values ("cpu", &vl);
+ plugin_dispatch_values (&vl);
}
static int cpu_read (void)
diff --git a/src/cpufreq.c b/src/cpufreq.c
index 74e542b49745c151020ac4d849ff86815bc49339..3738b54c2f450eb8f3f4e52994f9180b369d3850 100644 (file)
--- a/src/cpufreq.c
+++ b/src/cpufreq.c
while (1)
{
- status = snprintf (filename, sizeof (filename),
+ status = ssnprintf (filename, sizeof (filename),
"/sys/devices/system/cpu/cpu%d/cpufreq/"
"scaling_cur_freq", num_cpu);
if ((status < 1) || ((unsigned int)status >= sizeof (filename)))
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "cpufreq", sizeof (vl.plugin));
- snprintf (vl.type_instance, sizeof (vl.type_instance),
+ sstrncpy (vl.type, "cpufreq", sizeof (vl.type));
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance),
"%i", cpu_num);
- plugin_dispatch_values ("cpufreq", &vl);
+ plugin_dispatch_values (&vl);
}
static int cpufreq_read (void)
for (i = 0; i < num_cpu; i++)
{
- status = snprintf (filename, sizeof (filename),
+ status = ssnprintf (filename, sizeof (filename),
"/sys/devices/system/cpu/cpu%d/cpufreq/"
"scaling_cur_freq", i);
if ((status < 1) || ((unsigned int)status >= sizeof (filename)))
diff --git a/src/csv.c b/src/csv.c
index ff59f91c006e81511b6aeec738000398ed945bdc..a94b7001025419602961980efa993506e9755b33 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
int i;
gauge_t *rates = NULL;
+ assert (0 == strcmp (ds->type, vl->type));
+
memset (buffer, '\0', buffer_len);
- status = snprintf (buffer, buffer_len, "%u", (unsigned int) vl->time);
+ status = ssnprintf (buffer, buffer_len, "%u", (unsigned int) vl->time);
if ((status < 1) || (status >= buffer_len))
return (-1);
offset = status;
{
if (store_rates == 0)
{
- status = snprintf (buffer + offset,
+ status = ssnprintf (buffer + offset,
buffer_len - offset,
",%llu",
vl->values[i].counter);
"uc_get_rate failed.");
return (-1);
}
- status = snprintf (buffer + offset,
+ status = ssnprintf (buffer + offset,
buffer_len - offset,
",%lf", rates[i]);
}
}
else /* if (ds->ds[i].type == DS_TYPE_GAUGE) */
{
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
",%lf", vl->values[i].gauge);
}
int offset = 0;
int status;
+ assert (0 == strcmp (ds->type, vl->type));
+
if (datadir != NULL)
{
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
"%s/", datadir);
if ((status < 1) || (status >= buffer_len - offset))
return (-1);
offset += status;
}
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
"%s/", vl->host);
if ((status < 1) || (status >= buffer_len - offset))
return (-1);
offset += status;
if (strlen (vl->plugin_instance) > 0)
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
"%s-%s/", vl->plugin, vl->plugin_instance);
else
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
"%s/", vl->plugin);
if ((status < 1) || (status >= buffer_len - offset))
return (-1);
offset += status;
if (strlen (vl->type_instance) > 0)
- status = snprintf (buffer + offset, buffer_len - offset,
- "%s-%s", ds->type, vl->type_instance);
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ "%s-%s", vl->type, vl->type_instance);
else
- status = snprintf (buffer + offset, buffer_len - offset,
- "%s", ds->type);
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ "%s", vl->type);
if ((status < 1) || (status >= buffer_len - offset))
return (-1);
offset += status;
struct flock fl;
int status;
+ if (0 != strcmp (ds->type, vl->type)) {
+ ERROR ("csv plugin: DS type does not match value list type");
+ return -1;
+ }
+
if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0)
return (-1);
diff --git a/src/df.c b/src/df.c
index 6bd92500834c1659c2066c11d124bea27dbab5d1..26d23826fccf32c81420f417192956737f64bdc8 100644 (file)
--- a/src/df.c
+++ b/src/df.c
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "df", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
- strncpy (vl.type_instance, df_name, sizeof (vl.type_instance));
+ sstrncpy (vl.type, "df", sizeof (vl.host));
+ sstrncpy (vl.type_instance, df_name, sizeof (vl.type_instance));
- plugin_dispatch_values ("df", &vl);
+ plugin_dispatch_values (&vl);
} /* void df_submit */
static int df_read (void)
if (strcmp (mnt_ptr->dir, "/") == 0)
{
- strncpy (mnt_name, "root", sizeof (mnt_name));
+ sstrncpy (mnt_name, "root", sizeof (mnt_name));
}
else
{
int i, len;
- strncpy (mnt_name, mnt_ptr->dir + 1, sizeof (mnt_name));
+ sstrncpy (mnt_name, mnt_ptr->dir + 1, sizeof (mnt_name));
len = strlen (mnt_name);
for (i = 0; i < len; i++)
diff --git a/src/disk.c b/src/disk.c
index 20afd30b602fca4b10e9ccfe1b8a9ecfbf22a15c..29aa979018b42bc9621d5b011a73daf0ae12722c 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "disk", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, plugin_instance,
+ sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void disk_submit */
#if HAVE_IOKIT_IOKITLIB_H
write_tme = dict_get_value (stats_dict,
kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
- if (snprintf (disk_name, 64, "%i-%i", disk_major, disk_minor) >= 64)
+ if (ssnprintf (disk_name, sizeof (disk_name),
+ "%i-%i", disk_major, disk_minor) >= sizeof (disk_name))
{
DEBUG ("snprintf (major, minor) failed.");
CFRelease (child_dict);
diff --git a/src/dns.c b/src/dns.c
index 69cb1922c3fd26ca8306f6c91fa1882ed4ccf364..c04169fec8a4809cb9e7b5516b5011e8d49a6e3a 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "dns", sizeof (vl.plugin));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void submit_counter */
static void submit_octets (counter_t queries, counter_t responses)
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "dns", sizeof (vl.plugin));
+ sstrncpy (vl.type, "dns_octets", sizeof (vl.type));
- plugin_dispatch_values ("dns_octets", &vl);
+ plugin_dispatch_values (&vl);
} /* void submit_counter */
static int dns_read (void)
diff --git a/src/email.c b/src/email.c
index 0882ad46299b5d118494c0407c7f4a9a0f17a9cb..e208f13049f168cbc08775366d5e01f7523c1982 100644 (file)
--- a/src/email.c
+++ b/src/email.c
}
addr.sun_family = AF_UNIX;
-
- strncpy (addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1));
- addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
+ sstrncpy (addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1));
errno = 0;
if (-1 == bind (connector_socket, (struct sockaddr *)&addr,
@@ -655,9 +653,10 @@ static void email_submit (const char *type, const char *type_instance, gauge_t v
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "email", sizeof (vl.plugin));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void email_submit */
/* Copy list l1 to list l2. l2 may partly exist already, but it is assumed
diff --git a/src/entropy.c b/src/entropy.c
index 69ce3142bc7f4e412ded5f0483be4c793f3cb7d6..2e20a67c08661dbdebd4e66e276184e17d97983b 100644 (file)
--- a/src/entropy.c
+++ b/src/entropy.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "entropy", sizeof (vl.plugin));
- sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
- sstrncpy (vl.type_instance, "", sizeof (vl.type_instance));
+ sstrncpy (vl.type, "entropy", sizeof (vl.type));
- plugin_dispatch_values ("entropy", &vl);
+ plugin_dispatch_values (&vl);
}
static int entropy_read (void)
diff --git a/src/exec.c b/src/exec.c
index 07c35c9bcf36d0e307ebbc48a93fb1e7fafa57e1..a80de1e7a321b452b0971e2263ab0c1be9c2abf2 100644 (file)
--- a/src/exec.c
+++ b/src/exec.c
{
char *tmp = strrchr (ci->values[1].value.string, '/');
if (tmp == NULL)
- strncpy (buffer, ci->values[1].value.string, sizeof (buffer));
+ sstrncpy (buffer, ci->values[1].value.string, sizeof (buffer));
else
- strncpy (buffer, tmp + 1, sizeof (buffer));
- buffer[sizeof (buffer) - 1] = '\0';
+ sstrncpy (buffer, tmp + 1, sizeof (buffer));
}
pl->argv[0] = strdup (buffer);
if (pl->argv[0] == NULL)
{
if (ci->values[i + 1].type == OCONFIG_TYPE_NUMBER)
{
- snprintf (buffer, sizeof (buffer), "%lf",
+ ssnprintf (buffer, sizeof (buffer), "%lf",
ci->values[i + 1].value.number);
}
else
{
if (ci->values[i + 1].value.boolean)
- strncpy (buffer, "true", sizeof (buffer));
+ sstrncpy (buffer, "true", sizeof (buffer));
else
- strncpy (buffer, "false", sizeof (buffer));
+ sstrncpy (buffer, "false", sizeof (buffer));
}
- buffer[sizeof (buffer) - 1] = '\0';
pl->argv[i] = strdup (buffer);
}
static void *exec_notification_one (void *arg) /* {{{ */
{
program_list_t *pl = ((program_list_and_notification_t *) arg)->pl;
- const notification_t *n = &((program_list_and_notification_t *) arg)->n;
+ notification_t *n = &((program_list_and_notification_t *) arg)->n;
+ notification_meta_t *meta;
int fd;
FILE *fh;
int pid;
if (strlen (n->type_instance) > 0)
fprintf (fh, "TypeInstance: %s\n", n->type_instance);
+ for (meta = n->meta; meta != NULL; meta = meta->next)
+ {
+ if (meta->type == NM_TYPE_STRING)
+ fprintf (fh, "%s: %s\n", meta->name, meta->value_string);
+ else if (meta->type == NM_TYPE_SIGNED_INT)
+ fprintf (fh, "%s: %"PRIi64"\n", meta->name, meta->value_signed_int);
+ else if (meta->type == NM_TYPE_UNSIGNED_INT)
+ fprintf (fh, "%s: %"PRIu64"\n", meta->name, meta->value_unsigned_int);
+ else if (meta->type == NM_TYPE_DOUBLE)
+ fprintf (fh, "%s: %e\n", meta->name, meta->value_double);
+ else if (meta->type == NM_TYPE_BOOLEAN)
+ fprintf (fh, "%s: %s\n", meta->name,
+ meta->value_boolean ? "true" : "false");
+ }
+
fprintf (fh, "\n%s\n", n->message);
fflush (fh);
DEBUG ("exec plugin: Child %i exited with status %i.",
pid, status);
+ plugin_notification_meta_free (n);
sfree (arg);
pthread_exit ((void *) 0);
return (NULL);
pln->pl = pl;
memcpy (&pln->n, n, sizeof (notification_t));
+ /* Set the `meta' member to NULL, otherwise `plugin_notification_meta_copy'
+ * will run into an endless loop. */
+ pln->n.meta = NULL;
+ plugin_notification_meta_copy (&pln->n, n);
+
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
pthread_create (&t, &attr, exec_notification_one, (void *) pln);
diff --git a/src/hddtemp.c b/src/hddtemp.c
index cb49577057f9e277c1777e9710dc351775483be9..9f4a7254feede2d27d057bdf5750bb1ee3f73ba2 100644 (file)
--- a/src/hddtemp.c
+++ b/src/hddtemp.c
{
int port = (int) (atof (value));
if ((port > 0) && (port <= 65535))
- snprintf (hddtemp_port, sizeof (hddtemp_port),
+ ssnprintf (hddtemp_port, sizeof (hddtemp_port),
"%i", port);
else
- strncpy (hddtemp_port, value, sizeof (hddtemp_port));
- hddtemp_port[sizeof (hddtemp_port) - 1] = '\0';
+ sstrncpy (hddtemp_port, value, sizeof (hddtemp_port));
}
else if (strcasecmp (key, "TranslateDevicename") == 0)
{
if ((ret = (char *) malloc (128 * sizeof (char))) == NULL)
return (NULL);
- if (snprintf (ret, 128, "%i-%i", list->major, list->minor) >= 128)
+ if (ssnprintf (ret, 128, "%i-%i", list->major, list->minor) >= 128)
{
free (ret);
return (NULL);
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "hddtemp", sizeof (vl.plugin));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type, "temperature", sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values ("temperature", &vl);
+ plugin_dispatch_values (&vl);
}
static int hddtemp_read (void)
diff --git a/src/interface.c b/src/interface.c
index 2add89d750004b163c85da9536ede49443dbb400..806a336dfde09c814c9ab9f204e5770758251893 100644 (file)
--- a/src/interface.c
+++ b/src/interface.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "interface", sizeof (vl.plugin));
- strncpy (vl.type_instance, dev, sizeof (vl.type_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, dev, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void if_submit */
static int interface_read (void)
diff --git a/src/ipmi.c b/src/ipmi.c
index 956aaf44c25cc3bf659e02e7768bca6268449f24..b9cfa1960b1a6b2c045ca03318769b42036c9e7c 100644 (file)
--- a/src/ipmi.c
+++ b/src/ipmi.c
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ipmi", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
sstrncpy (vl.type_instance, sensor_name_ptr, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void sensor_read_handler */
static int sensor_list_add (ipmi_sensor_t *sensor)
diff --git a/src/iptables.c b/src/iptables.c
index ea8c65e9008916c6004d4ce0b9e41f24f78cba64..4d15c6e0896ac62e15b3082fb6c622403c4add2d 100644 (file)
--- a/src/iptables.c
+++ b/src/iptables.c
free (value_copy);
return (1);
}
- strncpy (temp.table, table, table_len);
- temp.table[table_len] = '\0';
+ sstrncpy (temp.table, table, table_len);
chain_len = strlen (chain);
if ((unsigned int)chain_len >= sizeof(temp.chain))
free (value_copy);
return (1);
}
- strncpy (temp.chain, chain, chain_len);
- temp.chain[chain_len] = '\0';
+ sstrncpy (temp.chain, chain, chain_len);
if (fields_num >= 3)
{
}
if (fields_num >= 4)
- strncpy (temp.name, fields[3], sizeof (temp.name) - 1);
+ sstrncpy (temp.name, fields[3], sizeof (temp.name));
free (value_copy);
value_copy = NULL;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "iptables", sizeof (vl.plugin));
- status = snprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
+ status = ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
"%s-%s", chain->table, chain->chain);
if ((status < 1) || ((unsigned int)status >= sizeof (vl.plugin_instance)))
return (0);
if (chain->name[0] != '\0')
{
- strncpy (vl.type_instance, chain->name, sizeof (vl.type_instance));
+ sstrncpy (vl.type_instance, chain->name, sizeof (vl.type_instance));
}
else
{
if (chain->rule_type == RTYPE_NUM)
- snprintf (vl.type_instance, sizeof (vl.type_instance),
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance),
"%i", chain->rule.num);
else
- strncpy (vl.type_instance, (char *) match->data,
+ sstrncpy (vl.type_instance, (char *) match->data,
sizeof (vl.type_instance));
}
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ sstrncpy (vl.type, "ipt_bytes", sizeof (vl.type));
values[0].counter = (counter_t) entry->counters.bcnt;
- plugin_dispatch_values ("ipt_bytes", &vl);
+ plugin_dispatch_values (&vl);
+ sstrncpy (vl.type, "ipt_packets", sizeof (vl.type));
values[0].counter = (counter_t) entry->counters.pcnt;
- plugin_dispatch_values ("ipt_packets", &vl);
+ plugin_dispatch_values (&vl);
return (0);
} /* void submit_match */
diff --git a/src/ipvs.c b/src/ipvs.c
index 31e9741562ac46427a8ccc171f302b8d27934b92..10c4d1517415cb7bf0b57a216f5cd4f3a8c22513 100644 (file)
--- a/src/ipvs.c
+++ b/src/ipvs.c
/* inet_ntoa() returns a pointer to a statically allocated buffer
* I hope non-glibc systems behave the same */
- len = snprintf (pi, size, "%s_%s%u", inet_ntoa (addr),
+ len = ssnprintf (pi, size, "%s_%s%u", inet_ntoa (addr),
(se->protocol == IPPROTO_TCP) ? "TCP" : "UDP",
ntohs (se->port));
/* inet_ntoa() returns a pointer to a statically allocated buffer
* I hope non-glibc systems behave the same */
- len = snprintf (ti, size, "%s_%u", inet_ntoa (addr),
+ len = ssnprintf (ti, size, "%s_%u", inet_ntoa (addr),
ntohs (de->port));
if ((0 > len) || (size <= len)) {
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance));
- sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", sizeof (vl.type_instance));
+ sstrncpy (vl.type, "connections", sizeof (vl.type));
+ sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total",
+ sizeof (vl.type_instance));
- plugin_dispatch_values ("connections", &vl);
+ plugin_dispatch_values (&vl);
return;
} /* cipvs_submit_connections */
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance));
- sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total", sizeof (vl.type_instance));
+ sstrncpy (vl.type, t, sizeof (vl.type));
+ sstrncpy (vl.type_instance, (NULL != ti) ? ti : "total",
+ sizeof (vl.type_instance));
- plugin_dispatch_values (t, &vl);
+ plugin_dispatch_values (&vl);
return;
} /* cipvs_submit_if */
diff --git a/src/irq.c b/src/irq.c
index 93c6076ba0429396131650a90766f2f075938142..9b7e61877d8c62bafc009e91e1f792c43024e63e 100644 (file)
--- a/src/irq.c
+++ b/src/irq.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "irq", sizeof (vl.plugin));
+ sstrncpy (vl.type, "irq", sizeof (vl.type));
- status = snprintf (vl.type_instance, sizeof (vl.type_instance),
+ status = ssnprintf (vl.type_instance, sizeof (vl.type_instance),
"%u", irq);
if ((status < 1) || ((unsigned int)status >= sizeof (vl.type_instance)))
return;
- plugin_dispatch_values ("irq", &vl);
+ plugin_dispatch_values (&vl);
} /* void irq_submit */
static int irq_read (void)
index 4d9fc3de811bce2f7b79da20b566e65171d9baa0..b559e863179ebfebaf1acc4219baa24522897e5d 100644 (file)
--- a/src/liboconfig/scanner.l
+++ b/src/liboconfig/scanner.l
/**
* oconfig - src/scanner.l
* Copyright (C) 2007 Florian octo Forster <octo at verplant.org>
+ * Copyright (C) 2008 Sebastian tokkee Harl <sh at tokkee.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
#include "oconfig.h"
#include "aux_types.h"
#include "parser.h"
+
+/* multiline string buffer */
+static char *ml_buffer = NULL;
+static int ml_pos = 0;
+static int ml_len = 0;
+
+#define ml_free (ml_len - ml_pos)
+
+static void ml_append (char *);
+
+#ifdef yyterminate
+# undef yyterminate
+#endif
+#define yyterminate() \
+ do { free (ml_buffer); ml_buffer = NULL; ml_pos = 0; ml_len = 0; \
+ return YY_NULL; } while (0)
%}
%option yylineno
%option noyywrap
+%x ML
WHITE_SPACE [\ \t\b]
-QUOTED_STRING \"([^\\"]+|\\.)*\"
+NON_WHITE_SPACE [^\ \t\b]
+EOL (\r\n|\n)
+QUOTED_STRING ([^\\"]+|\\.)*
UNQUOTED_STRING [0-9A-Za-z_]+
HEX_NUMBER 0[xX][0-9a-fA-F]+
OCT_NUMBER 0[0-7]+
{WHITE_SPACE} |
{COMMENT} {/* ignore */}
-\n {return (EOL);}
+\\{EOL} {/* continue line */}
+
+{EOL} {return (EOL);}
"/" {return (SLASH);}
"<" {return (OPENBRAC);}
">" {return (CLOSEBRAC);}
{NUMBER} {yylval.number = strtod (yytext, NULL); return (NUMBER);}
-{QUOTED_STRING} {yylval.string = yytext; return (QUOTED_STRING);}
+\"{QUOTED_STRING}\" {yylval.string = yytext; return (QUOTED_STRING);}
{UNQUOTED_STRING} {yylval.string = yytext; return (UNQUOTED_STRING);}
+
+\"{QUOTED_STRING}\\{EOL} {
+ int len = strlen (yytext);
+
+ ml_pos = 0;
+
+ /* remove "\\<EOL>" */
+ if ('\r' == yytext[len - 2])
+ len -= 3;
+ else
+ len -= 2;
+ yytext[len] = '\0';
+
+ ml_append (yytext);
+ BEGIN (ML);
+}
+<ML>^{WHITE_SPACE}+ {/* remove leading white-space */}
+<ML>{NON_WHITE_SPACE}{QUOTED_STRING}\\{EOL} {
+ int len = strlen (yytext);
+
+ /* remove "\\<EOL>" */
+ if ('\r' == yytext[len - 2])
+ len -= 3;
+ else
+ len -= 2;
+ yytext[len] = '\0';
+
+ ml_append(yytext);
+}
+<ML>{NON_WHITE_SPACE}{QUOTED_STRING}\" {
+ ml_append(yytext);
+ yylval.string = ml_buffer;
+
+ BEGIN (INITIAL);
+ return (QUOTED_STRING);
+}
%%
+static void ml_append (char *string)
+{
+ int len = strlen (string);
+ int s;
+
+ if (ml_free <= len) {
+ ml_len += len - ml_free + 1;
+ ml_buffer = (char *)realloc (ml_buffer, ml_len);
+ if (NULL == ml_buffer)
+ YY_FATAL_ERROR ("out of dynamic memory in ml_append");
+ }
+
+ s = snprintf (ml_buffer + ml_pos, ml_free, "%s", string);
+ if ((0 > s) || (ml_free <= s))
+ YY_FATAL_ERROR ("failed to write to multiline buffer");
+
+ ml_pos += s;
+ return;
+} /* ml_append */
+
diff --git a/src/libvirt.c b/src/libvirt.c
index 81d7f1cd3012cdeb478961918ce9397db7a6cd58..5acff29a578cd609dff2ba7de65bab1e13c4fc3b 100644 (file)
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -634,7 +634,7 @@ ignore_device_match (ignorelist_t *il, const char *domname, const char *devpath)
ERROR ("libvirt plugin: malloc failed.");
return 0;
}
- snprintf (name, n, "%s:%s", domname, devpath);
+ ssnprintf (name, n, "%s:%s", domname, devpath);
r = ignorelist_match (il, name);
free (name);
return r;
vl->time = t;
vl->interval = interval_g;
- strncpy (vl->plugin, "libvirt", sizeof (vl->plugin));
- vl->plugin[sizeof (vl->plugin) - 1] = '\0';
+ sstrncpy (vl->plugin, "libvirt", sizeof (vl->plugin));
vl->host[0] = '\0';
host_ptr = vl->host;
vl.values = values;
vl.values_len = 1;
- plugin_dispatch_values (type, &vl);
+ sstrncpy (vl.type, type, sizeof (vl.type));
+
+ plugin_dispatch_values (&vl);
}
static void
vl.values = values;
vl.values_len = 1;
- snprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr);
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr);
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
}
static void
vl.values = values;
vl.values_len = 2;
- strncpy (vl.type_instance, devname, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, devname, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void submit_counter2 */
static int
diff --git a/src/load.c b/src/load.c
index e0e0c0ed87942a04afdeb03fa0338bc08446e64e..72c7756a34b27d325b82fcc084e3afdb77f02dc8 100644 (file)
--- a/src/load.c
+++ b/src/load.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "load", sizeof (vl.plugin));
+ sstrncpy (vl.type, "load", sizeof (vl.type));
- plugin_dispatch_values ("load", &vl);
+ plugin_dispatch_values (&vl);
}
static int load_read (void)
diff --git a/src/logfile.c b/src/logfile.c
index 36ac58d711ee8a1764fd19ec72fefc9afffeafc5..382386b75552fa0915d9ade6ded18bc5b9954f3d 100644 (file)
--- a/src/logfile.c
+++ b/src/logfile.c
int buf_len = sizeof (buf);
int status;
- status = snprintf (buf_ptr, buf_len, "Notification: severity = %s",
+ status = ssnprintf (buf_ptr, buf_len, "Notification: severity = %s",
(n->severity == NOTIF_FAILURE) ? "FAILURE"
: ((n->severity == NOTIF_WARNING) ? "WARNING"
: ((n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN")));
#define APPEND(bufptr, buflen, key, value) \
if ((buflen > 0) && (strlen (value) > 0)) { \
- int status = snprintf (bufptr, buflen, ", %s = %s", key, value); \
+ int status = ssnprintf (bufptr, buflen, ", %s = %s", key, value); \
if (status > 0) { \
bufptr += status; \
buflen -= status; \
diff --git a/src/mbmon.c b/src/mbmon.c
index 22a26da5e613ef884d3b5c92331b574d85e1d5ff..344caddffd91f286b94b96721d065b4c2751f652 100644 (file)
--- a/src/mbmon.c
+++ b/src/mbmon.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "mbmon", sizeof (vl.plugin));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void mbmon_submit */
/* Trim trailing whitespace from a string. */
diff --git a/src/memcached.c b/src/memcached.c
index c830598d273c89dca7631c38bc8614a2a81caa72..ddea2ea2f0926874775c1d20cc1ac5bce6a2c74d 100644 (file)
--- a/src/memcached.c
+++ b/src/memcached.c
} else if (strcasecmp (key, "Port") == 0) {
int port = (int) (atof (value));
if ((port > 0) && (port <= 65535)) {
- snprintf (memcached_port, sizeof (memcached_port), "%i", port);
+ ssnprintf (memcached_port, sizeof (memcached_port), "%i", port);
} else {
- strncpy (memcached_port, value, sizeof (memcached_port));
+ sstrncpy (memcached_port, value, sizeof (memcached_port));
}
- memcached_port[sizeof (memcached_port) - 1] = '\0';
} else {
return -1;
}
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_inst != NULL)
- {
- strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
- }
+ sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void memcached_submit_cmd */
/* }}} */
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_inst != NULL)
- {
- strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
- }
+ sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void memcached_submit_cmd */
/* }}} */
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_inst != NULL)
- {
- strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
- }
+ sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
}
/* }}} */
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_inst != NULL)
- {
- strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
- }
+ sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
}
/* }}} */
diff --git a/src/memory.c b/src/memory.c
index 583f71a2041b1eff7f34de985ae85d4d2537ce04..c1564c86caf1840465ef5cecc14487d2e63a5eee 100644 (file)
--- a/src/memory.c
+++ b/src/memory.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "memory", sizeof (vl.plugin));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ sstrncpy (vl.type, "memory", sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values ("memory", &vl);
+ plugin_dispatch_values (&vl);
}
static int memory_read (void)
diff --git a/src/multimeter.c b/src/multimeter.c
index c6b070a035691a2cbabd3c816231444448892ea5..994747f94f4167c352febc69c8ca4eb884c28650 100644 (file)
--- a/src/multimeter.c
+++ b/src/multimeter.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "multimeter", sizeof (vl.plugin));
+ sstrncpy (vl.type, "multimeter", sizeof (vl.type));
- plugin_dispatch_values ("multimeter", &vl);
+ plugin_dispatch_values (&vl);
}
static int multimeter_read (void)
diff --git a/src/mysql.c b/src/mysql.c
index aa585d6554eb88ddedffb8f38f5286b386deeba6..312a819e4980190a13bbabd957b30ca6efcea599 100644 (file)
--- a/src/mysql.c
+++ b/src/mysql.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void counter_submit */
static void qcache_submit (counter_t hits, counter_t inserts,
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+ sstrncpy (vl.type, "mysql_qcache", sizeof (vl.type));
- plugin_dispatch_values ("mysql_qcache", &vl);
+ plugin_dispatch_values (&vl);
} /* void qcache_submit */
static void threads_submit (gauge_t running, gauge_t connected, gauge_t cached,
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+ sstrncpy (vl.type, "mysql_threads", sizeof (vl.type));
- plugin_dispatch_values ("mysql_threads", &vl);
+ plugin_dispatch_values (&vl);
} /* void threads_submit */
static void traffic_submit (counter_t rx, counter_t tx)
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
+ sstrncpy (vl.type, "mysql_octets", sizeof (vl.type));
- plugin_dispatch_values ("mysql_octets", &vl);
+ plugin_dispatch_values (&vl);
} /* void traffic_submit */
static int mysql_read (void)
diff --git a/src/netlink.c b/src/netlink.c
index e54365d0587b55447ff50fb76dffa8085db8ef76..c2e4c9b46bfa2d23fe92dcf04c4434794d5c6310 100644 (file)
--- a/src/netlink.c
+++ b/src/netlink.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "netlink", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
+ sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void submit_one */
static void submit_two (const char *dev, const char *type,
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "netlink", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
+ sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void submit_two */
static int link_filter (const struct sockaddr_nl *sa,
- const struct nlmsghdr *nmh, void *args)
+ struct nlmsghdr *nmh, void *args)
{
struct ifinfomsg *msg;
int msg_len;
} /* int link_filter */
static int qos_filter (const struct sockaddr_nl *sa,
- const struct nlmsghdr *nmh, void *args)
+ struct nlmsghdr *nmh, void *args)
{
struct tcmsg *msg;
int msg_len;
if (strcmp (tc_type, "filter") == 0)
numberic_id = msg->tcm_parent;
- snprintf (tc_inst, sizeof (tc_inst), "%s-%x:%x",
+ ssnprintf (tc_inst, sizeof (tc_inst), "%s-%x:%x",
(const char *) RTA_DATA (attrs[TCA_KIND]),
numberic_id >> 16,
numberic_id & 0x0000FFFF);
- tc_inst[sizeof (tc_inst) - 1] = '\0';
}
DEBUG ("netlink plugin: qos_filter: got %s for %s (%i).",
struct gnet_stats_basic bs;
char type_instance[DATA_MAX_NAME_LEN];
- snprintf (type_instance, sizeof (type_instance), "%s-%s",
+ ssnprintf (type_instance, sizeof (type_instance), "%s-%s",
tc_type, tc_inst);
- type_instance[sizeof (type_instance) - 1] = '\0';
memset (&bs, '\0', sizeof (bs));
memcpy (&bs, RTA_DATA (attrs_stats[TCA_STATS_BASIC]),
struct tc_stats ts;
char type_instance[DATA_MAX_NAME_LEN];
- snprintf (type_instance, sizeof (type_instance), "%s-%s",
+ ssnprintf (type_instance, sizeof (type_instance), "%s-%s",
tc_type, tc_inst);
- type_instance[sizeof (type_instance) - 1] = '\0';
memset(&ts, '\0', sizeof (ts));
memcpy(&ts, RTA_DATA (attrs[TCA_STATS]),
diff --git a/src/network.c b/src/network.c
index 0f558ca921dcbfbb66a523ba140de1c6576e9f6f..39069aa751a551eef139b92e9ecd467bb8e5b27a 100644 (file)
--- a/src/network.c
+++ b/src/network.c
return (0);
} /* int cache_flush */
-static int cache_check (const char *type, const value_list_t *vl)
+static int cache_check (const value_list_t *vl)
{
char key[1024];
time_t *value = NULL;
return (-1);
if (format_name (key, sizeof (key), vl->host, vl->plugin,
- vl->plugin_instance, type, vl->type_instance))
+ vl->plugin_instance, vl->type, vl->type_instance))
return (-1);
pthread_mutex_lock (&cache_lock);
int status;
value_list_t vl = VALUE_LIST_INIT;
- char type[DATA_MAX_NAME_LEN];
notification_t n;
DEBUG ("network plugin: parse_packet: buffer = %p; buffer_len = %i;",
buffer, buffer_len);
memset (&vl, '\0', sizeof (vl));
- memset (&type, '\0', sizeof (type));
memset (&n, '\0', sizeof (n));
status = 0;
if ((vl.time > 0)
&& (strlen (vl.host) > 0)
&& (strlen (vl.plugin) > 0)
- && (strlen (type) > 0)
- && (cache_check (type, &vl) == 0))
+ && (strlen (vl.type) > 0)
+ && (cache_check (&vl) == 0))
{
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
}
else
{
else if (pkg_type == TYPE_TYPE)
{
status = parse_part_string (&buffer, &buffer_len,
- type, sizeof (type));
+ vl.type, sizeof (vl.type));
if (status == 0)
- sstrncpy (n.type, type, sizeof (n.type));
+ sstrncpy (n.type, vl.type, sizeof (n.type));
}
else if (pkg_type == TYPE_TYPE_INSTANCE)
{
sstrncpy (vl_def->plugin_instance, vl->plugin_instance, sizeof (vl_def->plugin_instance));
}
- if (strcmp (type_def, ds->type) != 0)
+ if (strcmp (type_def, vl->type) != 0)
{
if (write_part_string (&buffer, &buffer_size, TYPE_TYPE,
- ds->type, strlen (ds->type)) != 0)
+ vl->type, strlen (vl->type)) != 0)
return (-1);
- sstrncpy (type_def, ds->type, sizeof (type_def));
+ sstrncpy (type_def, vl->type, sizeof (type_def));
}
if (strcmp (vl_def->type_instance, vl->type_instance) != 0)
/* If the value is already in the cache, we have received it via the
* network. We write it again if forwarding is activated. It's then in
* the cache and should we receive it again we will ignore it. */
- status = cache_check (ds->type, vl);
+ status = cache_check (vl);
if ((network_config_forward == 0)
&& (status != 0))
return (0);
return (0);
} /* int network_init */
-static int network_flush (int timeout)
+/*
+ * The flush option of the network plugin cannot flush individual identifiers.
+ * All the values are added to a buffer and sent when the buffer is full, the
+ * requested value may or may not be in there, it's not worth finding out. We
+ * just send the buffer if `flush' is called - if the requested value was in
+ * there, good. If not, well, then there is nothing to flush.. -octo
+ */
+static int network_flush (int timeout, const char *identifier)
{
pthread_mutex_lock (&send_buffer_lock);
diff --git a/src/nfs.c b/src/nfs.c
index 91e6788631acba20630a3da4434444cde9e5f4f1..f2db895a00d484bf647e1c2a9a7688dd106ca31e 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "nfs", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, plugin_instance,
+ sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, "nfs_procedure", sizeof (vl.type));
for (i = 0; i < len; i++)
{
values[0].counter = val[i];
- strncpy (vl.type_instance, names[i],
+ sstrncpy (vl.type_instance, names[i],
sizeof (vl.type_instance));
DEBUG ("%s-%s/nfs_procedure-%s = %llu",
vl.plugin, vl.plugin_instance,
vl.type_instance, val[i]);
- plugin_dispatch_values ("nfs_procedure", &vl);
+ plugin_dispatch_values (&vl);
}
} /* void nfs_procedures_submit */
continue;
}
- snprintf (plugin_instance, sizeof (plugin_instance),
+ ssnprintf (plugin_instance, sizeof (plugin_instance),
"v2%s", inst);
- plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0';
values = (unsigned long long *) malloc (nfs2_procedures_names_num * sizeof (unsigned long long));
if (values == NULL)
continue;
}
- snprintf (plugin_instance, sizeof (plugin_instance),
+ ssnprintf (plugin_instance, sizeof (plugin_instance),
"v3%s", inst);
- plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0';
values = (unsigned long long *) malloc (nfs3_procedures_names_num * sizeof (unsigned long long));
if (values == NULL)
diff --git a/src/nginx.c b/src/nginx.c
index 283e8f6f3fa85ae2568aab63c45a170ed8ba35ca..91bcf75404927bfcd708e16faf71b5b7606fe304 100644 (file)
--- a/src/nginx.c
+++ b/src/nginx.c
if (user != NULL)
{
- if (snprintf (credentials, 1024, "%s:%s", user, pass == NULL ? "" : pass) >= 1024)
+ if (ssnprintf (credentials, sizeof (credentials),
+ "%s:%s", user, pass == NULL ? "" : pass) >= sizeof (credentials))
{
ERROR ("nginx plugin: Credentials would have been truncated.");
return (-1);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "nginx", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (inst != NULL)
- {
- strncpy (vl.type_instance, inst, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
- }
+ sstrncpy (vl.type_instance, inst, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void submit */
static int nginx_read (void)
diff --git a/src/notify_desktop.c b/src/notify_desktop.c
--- /dev/null
+++ b/src/notify_desktop.c
@@ -0,0 +1,161 @@
+/**
+ * collectd - src/notify_desktop.c
+ * Copyright (C) 2008 Sebastian Harl
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Sebastian Harl <sh at tokkee.org>
+ **/
+
+/*
+ * This plugin sends desktop notifications to a notification daemon.
+ */
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+
+#include <glib.h>
+#include <libnotify/notify.h>
+
+#define log_info(...) INFO ("notify_desktop: " __VA_ARGS__)
+#define log_warn(...) WARNING ("notify_desktop: " __VA_ARGS__)
+#define log_err(...) ERROR ("notify_desktop: " __VA_ARGS__)
+
+#define DEFAULT_TIMEOUT 5000
+
+static int okay_timeout = DEFAULT_TIMEOUT;
+static int warn_timeout = DEFAULT_TIMEOUT;
+static int fail_timeout = DEFAULT_TIMEOUT;
+
+static int set_timeout (oconfig_item_t *ci, int *timeout)
+{
+ if ((0 != ci->children_num) || (1 != ci->values_num)
+ || (OCONFIG_TYPE_NUMBER != ci->values[0].type)) {
+ log_err ("%s expects a single number argument.", ci->key);
+ return 1;
+ }
+
+ *timeout = (int)ci->values[0].value.number;
+ if (0 > *timeout)
+ *timeout = DEFAULT_TIMEOUT;
+ return 0;
+} /* set_timeout */
+
+static int c_notify_config (oconfig_item_t *ci)
+{
+ int i = 0;
+
+ for (i = 0; i < ci->children_num; ++i) {
+ oconfig_item_t *c = ci->children + i;
+
+ if (0 == strcasecmp (c->key, "OkayTimeout"))
+ set_timeout (c, &okay_timeout);
+ else if (0 == strcasecmp (c->key, "WarningTimeout"))
+ set_timeout (c, &warn_timeout);
+ else if (0 == strcasecmp (c->key, "FailureTimeout"))
+ set_timeout (c, &fail_timeout);
+ }
+ return 0;
+} /* c_notify_config */
+
+static int c_notify (const notification_t *n)
+{
+ NotifyNotification *notification = NULL;
+ NotifyUrgency urgency = NOTIFY_URGENCY_LOW;
+ int timeout = okay_timeout;
+
+ char summary[1024];
+
+ if (NOTIF_WARNING == n->severity) {
+ urgency = NOTIFY_URGENCY_NORMAL;
+ timeout = warn_timeout;
+ }
+ else if (NOTIF_FAILURE == n->severity) {
+ urgency = NOTIFY_URGENCY_CRITICAL;
+ timeout = fail_timeout;
+ }
+
+ ssnprintf (summary, sizeof (summary), "collectd %s notification",
+ (NOTIF_FAILURE == n->severity) ? "FAILURE"
+ : (NOTIF_WARNING == n->severity) ? "WARNING"
+ : (NOTIF_OKAY == n->severity) ? "OKAY" : "UNKNOWN");
+
+ notification = notify_notification_new (summary, n->message, NULL, NULL);
+ if (NULL == notification) {
+ log_err ("Failed to create a new notification.");
+ return -1;
+ }
+
+ notify_notification_set_urgency (notification, urgency);
+ notify_notification_set_timeout (notification, timeout);
+
+ if (! notify_notification_show (notification, NULL))
+ log_err ("Failed to display notification.");
+
+ g_object_unref (G_OBJECT (notification));
+ return 0;
+} /* c_notify */
+
+static int c_notify_shutdown (void)
+{
+ plugin_unregister_init ("notify_desktop");
+ plugin_unregister_notification ("notify_desktop");
+ plugin_unregister_shutdown ("notify_desktop");
+
+ if (notify_is_initted ())
+ notify_uninit ();
+ return 0;
+} /* c_notify_shutdown */
+
+static int c_notify_init (void)
+{
+ char *name = NULL;
+ char *vendor = NULL;
+ char *version = NULL;
+ char *spec_version = NULL;
+
+ if (! notify_init (PACKAGE_STRING)) {
+ log_err ("Failed to initialize libnotify.");
+ return -1;
+ }
+
+ if (! notify_get_server_info (&name, &vendor, &version, &spec_version))
+ log_warn ("Failed to get the notification server info. "
+ "Check if you have a notification daemon running.");
+ else {
+ log_info ("Found notification daemon: %s (%s) %s (spec version %s)",
+ name, vendor, version, spec_version);
+ free (name);
+ free (vendor);
+ free (version);
+ free (spec_version);
+ }
+
+ plugin_register_notification ("notify_desktop", c_notify);
+ plugin_register_shutdown ("notify_desktop", c_notify_shutdown);
+ return 0;
+} /* c_notify_init */
+
+void module_register (void)
+{
+ plugin_register_complex_config ("notify_desktop", c_notify_config);
+ plugin_register_init ("notify_desktop", c_notify_init);
+ return;
+} /* module_register */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/notify_email.c b/src/notify_email.c
--- /dev/null
+++ b/src/notify_email.c
@@ -0,0 +1,287 @@
+/**
+ * collectd - src/notify_email.c
+ * Copyright (C) 2008 Oleg King
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Oleg King <king2 at kaluga.ru>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <auth-client.h>
+#include <libesmtp.h>
+
+#define MAXSTRING 256
+
+static const char *config_keys[] =
+{
+ "SMTPServer",
+ "SMTPPort",
+ "SMTPUser",
+ "SMTPPassword",
+ "From",
+ "Recipient",
+ "Subject"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static char **recipients;
+static int recipients_len = 0;
+
+static smtp_session_t session;
+static smtp_message_t message;
+static auth_context_t authctx = NULL;
+
+static int smtp_port = 25;
+static char *smtp_host = NULL;
+static char *smtp_user = NULL;
+static char *smtp_password = NULL;
+static char *email_from = NULL;
+static char *email_subject = NULL;
+
+#define DEFAULT_SMTP_HOST "localhost"
+#define DEFAULT_SMTP_FROM "root@localhost"
+#define DEFAULT_SMTP_SUBJECT "Collectd notify: %s@%s"
+
+/* Callback to get username and password */
+static int authinteract (auth_client_request_t request, char **result,
+ int fields, void *arg)
+{
+ int i;
+ for (i = 0; i < fields; i++)
+ {
+ if (request[i].flags & AUTH_USER)
+ result[i] = smtp_user;
+ else if (request[i].flags & AUTH_PASS)
+ result[i] = smtp_password;
+ else
+ return 0;
+ }
+ return 1;
+} /* int authinteract */
+
+/* Callback to print the recipient status */
+static void print_recipient_status (smtp_recipient_t recipient,
+ const char *mailbox, void *arg)
+{
+ const smtp_status_t *status;
+
+ status = smtp_recipient_status (recipient);
+ if (status->text[strlen(status->text) - 2] == '\r')
+ status->text[strlen(status->text) - 2] = 0;
+ INFO ("notify_email: notify sent to %s: %d %s", mailbox, status->code,
+ status->text);
+} /* void print_recipient_status */
+
+/* Callback to monitor SMTP activity */
+static void monitor_cb (const char *buf, int buflen, int writing, void *arg)
+{
+ char log_str[MAXSTRING];
+
+ sstrncpy (log_str, buf, sizeof (log_str));
+ if (buflen > 2)
+ log_str[buflen - 2] = 0; /* replace \n with \0 */
+
+ if (writing == SMTP_CB_HEADERS) {
+ DEBUG ("notify_email plugin: SMTP --- H: %s", log_str);
+ return;
+ }
+ DEBUG (writing
+ ? "notify_email plugin: SMTP >>> C: %s"
+ : "notify_email plugin: SMTP <<< S: %s",
+ log_str);
+} /* void monitor_cb */
+
+static int notify_email_init (void)
+{
+ char server[MAXSTRING];
+
+ auth_client_init();
+ if (!(session = smtp_create_session ())) {
+ ERROR ("notify_email plugin: cannot create SMTP session");
+ return (-1);
+ }
+
+ smtp_set_monitorcb (session, monitor_cb, NULL, 1);
+ smtp_set_hostname (session, hostname_g);
+ ssnprintf(server, sizeof (server), "%s:%i",
+ (smtp_host == NULL) ? DEFAULT_SMTP_HOST : smtp_host,
+ smtp_port);
+ smtp_set_server (session, server);
+
+ if (smtp_user && smtp_password) {
+ authctx = auth_create_context ();
+ auth_set_mechanism_flags (authctx, AUTH_PLUGIN_PLAIN, 0);
+ auth_set_interact_cb (authctx, authinteract, NULL);
+ }
+
+ if ( !smtp_auth_set_context (session, authctx)) {
+ ERROR ("notify_email plugin: cannot set SMTP auth context");
+ return (-1);
+ }
+
+ return (0);
+} /* int notify_email_init */
+
+static int notify_email_shutdown (void)
+{
+ smtp_destroy_session (session);
+ auth_destroy_context (authctx);
+ auth_client_exit();
+ return (0);
+} /* int notify_email_shutdown */
+
+static int notify_email_config (const char *key, const char *value)
+{
+ if (strcasecmp (key, "Recipient") == 0)
+ {
+ char **tmp;
+
+ tmp = (char **) realloc ((void *) recipients, (recipients_len + 1) * sizeof (char *));
+ if (tmp == NULL) {
+ ERROR ("notify_email: realloc failed.");
+ return (-1);
+ }
+
+ recipients = tmp;
+ recipients[recipients_len] = strdup (value);
+ if (recipients[recipients_len] == NULL) {
+ ERROR ("notify_email: strdup failed.");
+ return (-1);
+ }
+ recipients_len++;
+ }
+ else if (0 == strcasecmp (key, "SMTPServer")) {
+ sfree (smtp_host);
+ smtp_host = strdup (value);
+ }
+ else if (0 == strcasecmp (key, "SMTPPort")) {
+ int port_tmp = atoi (value);
+ if (port_tmp < 1 || port_tmp > 65535)
+ {
+ WARNING ("notify_email plugin: Invalid SMTP port: %i", port_tmp);
+ return (1);
+ }
+ smtp_port = port_tmp;
+ }
+ else if (0 == strcasecmp (key, "SMTPUser")) {
+ sfree (smtp_user);
+ smtp_user = strdup (value);
+ }
+ else if (0 == strcasecmp (key, "SMTPPassword")) {
+ sfree (smtp_password);
+ smtp_password = strdup (value);
+ }
+ else if (0 == strcasecmp (key, "From")) {
+ sfree (email_from);
+ email_from = strdup (value);
+ }
+ else if (0 == strcasecmp (key, "Subject")) {
+ sfree (email_subject);
+ email_subject = strdup (value);
+ }
+ else {
+ return -1;
+ }
+ return 0;
+} /* int notify_email_config (const char *, const char *) */
+
+static int notify_email_notification (const notification_t *n)
+{
+ smtp_recipient_t recipient;
+
+ struct tm timestamp_tm;
+ char timestamp_str[64];
+
+ char severity[32];
+ char subject[MAXSTRING];
+
+ char buf[4096] = "";
+ int buf_len = sizeof (buf);
+ int i;
+
+ ssnprintf (severity, sizeof (severity), "%s",
+ (n->severity == NOTIF_FAILURE) ? "FAILURE"
+ : ((n->severity == NOTIF_WARNING) ? "WARNING"
+ : ((n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN")));
+
+ ssnprintf (subject, sizeof (subject),
+ (email_subject == NULL) ? DEFAULT_SMTP_SUBJECT : email_subject,
+ severity, n->host);
+
+ localtime_r (&n->time, ×tamp_tm);
+ strftime (timestamp_str, sizeof (timestamp_str), "%Y-%m-%d %H:%M:%S",
+ ×tamp_tm);
+ timestamp_str[sizeof (timestamp_str) - 1] = '\0';
+
+ /* Let's make RFC822 message text with \r\n EOLs */
+ ssnprintf (buf, buf_len,
+ "MIME-Version: 1.0\r\n"
+ "Content-Type: text/plain;\r\n"
+ "Content-Transfer-Encoding: 8bit\r\n"
+ "Subject: %s\r\n"
+ "\r\n"
+ "%s - %s@%s\r\n"
+ "\r\n"
+ "Message: %s",
+ subject,
+ timestamp_str,
+ severity,
+ n->host,
+ n->message);
+
+ if (!(message = smtp_add_message (session))) {
+ ERROR ("notify_email plugin: cannot set SMTP message");
+ return (-1);
+ }
+ smtp_set_reverse_path (message, email_from);
+ smtp_set_header (message, "To", NULL, NULL);
+ smtp_set_message_str (message, buf);
+
+ for (i = 0; i < recipients_len; i++)
+ recipient = smtp_add_recipient (message, recipients[i]);
+
+ /* Initiate a connection to the SMTP server and transfer the message. */
+ if (!smtp_start_session (session)) {
+ char buf[MAXSTRING];
+ ERROR ("notify_email plugin: SMTP server problem: %s",
+ smtp_strerror (smtp_errno (), buf, sizeof buf));
+ return (-1);
+ } else {
+ const smtp_status_t *status;
+ /* Report on the success or otherwise of the mail transfer. */
+ status = smtp_message_transfer_status (message);
+ DEBUG ("notify_email plugin: SMTP server report: %d %s",
+ status->code, (status->text != NULL) ? status->text : "\n");
+ smtp_enumerate_recipients (message, print_recipient_status, NULL);
+ }
+
+ return (0);
+} /* int notify_email_notification */
+
+void module_register (void)
+{
+ plugin_register_init ("notify_email", notify_email_init);
+ plugin_register_shutdown ("notify_email", notify_email_shutdown);
+ plugin_register_config ("notify_email", notify_email_config,
+ config_keys, config_keys_num);
+ plugin_register_notification ("notify_email", notify_email_notification);
+} /* void module_register (void) */
+
+/* vim: set sw=2 sts=2 ts=8 et : */
diff --git a/src/ntpd.c b/src/ntpd.c
index a7ef0fa3fd13fd0efbbce605688efa72eb93b7d8..44964bb5a8dbd936d23ef2e828e4d05b2561c543 100644 (file)
--- a/src/ntpd.c
+++ b/src/ntpd.c
{
int port = (int) (atof (value));
if ((port > 0) && (port <= 65535))
- snprintf (ntpd_port, sizeof (ntpd_port),
+ ssnprintf (ntpd_port, sizeof (ntpd_port),
"%i", port);
else
- strncpy (ntpd_port, value, sizeof (ntpd_port));
- ntpd_port[sizeof (ntpd_port) - 1] = '\0';
+ sstrncpy (ntpd_port, value, sizeof (ntpd_port));
}
else if (strcasecmp (key, "ReverseLookups") == 0)
{
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ntpd", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
- strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
}
/* returns `tv0 - tv1' in milliseconds or 0 if `tv1 > tv0' */
if (refclock_id < refclock_names_num)
{
- strncpy (peername, refclock_names[refclock_id],
+ sstrncpy (peername, refclock_names[refclock_id],
sizeof (peername));
}
else
addr_obj.s_addr = ptr->srcadr;
addr_str = inet_ntoa (addr_obj);
- strncpy (peername, addr_str, sizeof (peername));
+ sstrncpy (peername, addr_str, sizeof (peername));
}
}
else /* Normal network host. */
diff --git a/src/nut.c b/src/nut.c
index 695d93b5aa574a7f1c3469f8272e14983d29789c..8796d5873377cb6fbb61c51a65f011616f235c76 100644 (file)
--- a/src/nut.c
+++ b/src/nut.c
vl.values = values;
vl.values_len = STATIC_ARRAY_SIZE (values);
vl.time = time (NULL);
- strncpy (vl.host,
+ sstrncpy (vl.host,
(strcasecmp (ups->hostname, "localhost") == 0)
? hostname_g
: ups->hostname,
sizeof (vl.host));
sstrncpy (vl.plugin, "nut", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, ups->upsname, sizeof (vl.plugin_instance));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.plugin_instance, ups->upsname, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- vl.host[sizeof (vl.host) - 1] = '\0';
- vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0';
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
-
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void nut_submit */
static int nut_read_one (nut_ups_t *ups)
diff --git a/src/perl.c b/src/perl.c
index cb61be52b3fe260f67dd99cff418ba672a05022c..268e1d1428968b5d0eb4f9269ec7e2a004615bcc 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
return -1;
if (NULL != (tmp = hv_fetch (hash, "name", 4, 0))) {
- strncpy (ds->name, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
- ds->name[DATA_MAX_NAME_LEN - 1] = '\0';
+ sstrncpy (ds->name, SvPV_nolen (*tmp), sizeof (ds->name));
}
else {
log_err ("hv2data_source: No DS name given.");
newSVpv (vl->plugin_instance, 0), 0))
return -1;
+ if ('\0' != vl->type[0])
+ if (NULL == hv_store (hash, "type", 4, newSVpv (vl->type, 0), 0))
+ return -1;
+
if ('\0' != vl->type_instance[0])
if (NULL == hv_store (hash, "type_instance", 13,
newSVpv (vl->type_instance, 0), 0))
static char *get_module_name (char *buf, size_t buf_len, const char *module) {
int status = 0;
if (base_name[0] == '\0')
- status = snprintf (buf, buf_len, "%s", module);
+ status = ssnprintf (buf, buf_len, "%s", module);
else
- status = snprintf (buf, buf_len, "%s::%s", base_name, module);
+ status = ssnprintf (buf, buf_len, "%s::%s", base_name, module);
if ((status < 0) || ((unsigned int)status >= buf_len))
return (NULL);
- buf[buf_len - 1] = '\0';
return (buf);
} /* char *get_module_name */
ds[i].name, ds[i].type, ds[i].min, ds[i].max);
}
- strncpy (set->type, name, DATA_MAX_NAME_LEN);
- set->type[DATA_MAX_NAME_LEN - 1] = '\0';
+ sstrncpy (set->type, name, sizeof (set->type));
set->ds_num = len + 1;
set->ds = ds;
* type_instance => $tinstance,
* }
*/
-static int pplugin_dispatch_values (pTHX_ char *name, HV *values)
+static int pplugin_dispatch_values (pTHX_ HV *values)
{
value_list_t list = VALUE_LIST_INIT;
value_t *val = NULL;
int ret = 0;
- if ((NULL == name) || (NULL == values))
+ if (NULL == values)
+ return -1;
+
+ if (NULL == (tmp = hv_fetch (values, "type", 4, 0))) {
+ log_err ("pplugin_dispatch_values: No type given.");
return -1;
+ }
+
+ sstrncpy (list.type, SvPV_nolen (*tmp), sizeof (list.type));
if ((NULL == (tmp = hv_fetch (values, "values", 6, 0)))
|| (! (SvROK (*tmp) && (SVt_PVAV == SvTYPE (SvRV (*tmp)))))) {
val = (value_t *)smalloc (len * sizeof (value_t));
- list.values_len = av2value (aTHX_ name, (AV *)SvRV (*tmp), val, len);
+ list.values_len = av2value (aTHX_ list.type, (AV *)SvRV (*tmp),
+ val, len);
list.values = val;
if (-1 == list.values_len) {
}
if (NULL != (tmp = hv_fetch (values, "host", 4, 0))) {
- strncpy (list.host, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
- list.host[DATA_MAX_NAME_LEN - 1] = '\0';
+ sstrncpy (list.host, SvPV_nolen (*tmp), sizeof (list.host));
}
else {
sstrncpy (list.host, hostname_g, sizeof (list.host));
}
- if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0))) {
- strncpy (list.plugin, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
- list.plugin[DATA_MAX_NAME_LEN - 1] = '\0';
- }
+ if (NULL != (tmp = hv_fetch (values, "plugin", 6, 0)))
+ sstrncpy (list.plugin, SvPV_nolen (*tmp), sizeof (list.plugin));
- if (NULL != (tmp = hv_fetch (values, "plugin_instance", 15, 0))) {
- strncpy (list.plugin_instance, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
- list.plugin_instance[DATA_MAX_NAME_LEN - 1] = '\0';
- }
+ if (NULL != (tmp = hv_fetch (values, "plugin_instance", 15, 0)))
+ sstrncpy (list.plugin_instance, SvPV_nolen (*tmp),
+ sizeof (list.plugin_instance));
- if (NULL != (tmp = hv_fetch (values, "type_instance", 13, 0))) {
- strncpy (list.type_instance, SvPV_nolen (*tmp), DATA_MAX_NAME_LEN);
- list.type_instance[DATA_MAX_NAME_LEN - 1] = '\0';
- }
+ if (NULL != (tmp = hv_fetch (values, "type_instance", 13, 0)))
+ sstrncpy (list.type_instance, SvPV_nolen (*tmp),
+ sizeof (list.type_instance));
- ret = plugin_dispatch_values (name, &list);
+ ret = plugin_dispatch_values (&list);
sfree (val);
return ret;
n.time = time (NULL);
if (NULL != (tmp = hv_fetch (notif, "message", 7, 0)))
- strncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message));
- n.message[sizeof (n.message) - 1] = '\0';
+ sstrncpy (n.message, SvPV_nolen (*tmp), sizeof (n.message));
if (NULL != (tmp = hv_fetch (notif, "host", 4, 0)))
- strncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host));
+ sstrncpy (n.host, SvPV_nolen (*tmp), sizeof (n.host));
else
- strncpy (n.host, hostname_g, sizeof (n.host));
- n.host[sizeof (n.host) - 1] = '\0';
+ sstrncpy (n.host, hostname_g, sizeof (n.host));
if (NULL != (tmp = hv_fetch (notif, "plugin", 6, 0)))
- strncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin));
- n.plugin[sizeof (n.plugin) - 1] = '\0';
+ sstrncpy (n.plugin, SvPV_nolen (*tmp), sizeof (n.plugin));
if (NULL != (tmp = hv_fetch (notif, "plugin_instance", 15, 0)))
- strncpy (n.plugin_instance, SvPV_nolen (*tmp),
+ sstrncpy (n.plugin_instance, SvPV_nolen (*tmp),
sizeof (n.plugin_instance));
- n.plugin_instance[sizeof (n.plugin_instance) - 1] = '\0';
if (NULL != (tmp = hv_fetch (notif, "type", 4, 0)))
- strncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type));
- n.type[sizeof (n.type) - 1] = '\0';
+ sstrncpy (n.type, SvPV_nolen (*tmp), sizeof (n.type));
if (NULL != (tmp = hv_fetch (notif, "type_instance", 13, 0)))
- strncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance));
- n.type_instance[sizeof (n.type_instance) - 1] = '\0';
+ sstrncpy (n.type_instance, SvPV_nolen (*tmp), sizeof (n.type_instance));
return plugin_dispatch_notification (&n);
} /* static int pplugin_dispatch_notification (HV *) */
* time => $time,
* host => $hostname,
* plugin => $plugin,
+ * type => $type,
* plugin_instance => $instance,
* type_instance => $type_instance
* };
*/
static XS (Collectd_plugin_dispatch_values)
{
- SV *values = NULL;
+ SV *values = NULL;
+ int values_idx = 0;
int ret = 0;
dXSARGS;
- if (2 != items) {
- log_err ("Usage: Collectd::plugin_dispatch_values(name, values)");
+ if (2 == items) {
+ log_warn ("Collectd::plugin_dispatch_values with two arguments "
+ "is deprecated - pass the type through values->{type}.");
+ values_idx = 1;
+ }
+ else if (1 != items) {
+ log_err ("Usage: Collectd::plugin_dispatch_values(values)");
XSRETURN_EMPTY;
}
- log_debug ("Collectd::plugin_dispatch_values: "
- "name = \"%s\", values=\"%s\"",
- SvPV_nolen (ST (0)), SvPV_nolen (ST (1)));
+ log_debug ("Collectd::plugin_dispatch_values: values=\"%s\"",
+ SvPV_nolen (ST (values_idx)));
- values = ST (1);
+ values = ST (values_idx);
if (! (SvROK (values) && (SVt_PVHV == SvTYPE (SvRV (values))))) {
log_err ("Collectd::plugin_dispatch_values: Invalid values.");
XSRETURN_EMPTY;
}
- if ((NULL == ST (0)) || (NULL == values))
+ if (((2 == items) && (NULL == ST (0))) || (NULL == values))
XSRETURN_EMPTY;
- ret = pplugin_dispatch_values (aTHX_ SvPV_nolen (ST (0)),
- (HV *)SvRV (values));
+ if ((2 == items) && (NULL == hv_store ((HV *)SvRV (values), "type", 4,
+ newSVsv (ST (0)), 0))) {
+ log_err ("Collectd::plugin_dispatch_values: Could not store type.");
+ XSRETURN_EMPTY;
+ }
+
+ ret = pplugin_dispatch_values (aTHX_ (HV *)SvRV (values));
if (0 == ret)
XSRETURN_YES;
return pplugin_call_all (aTHX_ PLUGIN_NOTIF, notif);
} /* static int perl_notify (const notification_t *) */
-static int perl_flush (const int timeout)
+/* TODO: Implement flushing of single identifiers. */
+static int perl_flush (int timeout, const char *identifier)
{
dTHX;
static int g_pv_set (pTHX_ SV *var, MAGIC *mg)
{
char *pv = mg->mg_ptr;
- strncpy (pv, SvPV_nolen (var), DATA_MAX_NAME_LEN);
- pv[DATA_MAX_NAME_LEN - 1] = '\0';
+ sstrncpy (pv, SvPV_nolen (var), DATA_MAX_NAME_LEN);
return 0;
} /* static int g_pv_set (pTHX_ SV *, MAGIC *) */
value = ci->values[0].value.string;
log_debug ("perl_config: Setting plugin basename to \"%s\"", value);
- strncpy (base_name, value, sizeof (base_name));
- base_name[sizeof (base_name) - 1] = '\0';
+ sstrncpy (base_name, value, sizeof (base_name));
return 0;
} /* static int perl_config_basename (oconfig_item_it *) */
diff --git a/src/ping.c b/src/ping.c
index 09de77ce97f8db083127a386f6ec41ea99c1d134..ac5b0f85907040ab0b7fbc242f6dad85d81ce79c 100644 (file)
--- a/src/ping.c
+++ b/src/ping.c
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ping", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
- strncpy (vl.type_instance, host, sizeof (vl.type_instance));
+ sstrncpy (vl.type_instance, host, sizeof (vl.type_instance));
+ sstrncpy (vl.type, "ping", sizeof (vl.type));
- plugin_dispatch_values ("ping", &vl);
+ plugin_dispatch_values (&vl);
}
static int ping_read (void)
diff --git a/src/plugin.c b/src/plugin.c
index e611b8cec2067c06c9f93fd053bfe24973c80d8b..bf8fb085685e0e48ba4bf6c570b0b31618e1d60c 100644 (file)
--- a/src/plugin.c
+++ b/src/plugin.c
**/
#include "collectd.h"
+#include "utils_complain.h"
#include <ltdl.h>
/* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
* type when matching the filename */
- if (snprintf (typename, BUFSIZE, "%s.so", type) >= BUFSIZE)
+ if (ssnprintf (typename, sizeof (typename),
+ "%s.so", type) >= sizeof (typename))
{
WARNING ("snprintf: truncated: `%s.so'", type);
return (-1);
if (strncasecmp (de->d_name, typename, typename_len))
continue;
- if (snprintf (filename, BUFSIZE, "%s/%s", dir, de->d_name) >= BUFSIZE)
+ if (ssnprintf (filename, sizeof (filename),
+ "%s/%s", dir, de->d_name) >= sizeof (filename))
{
WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name);
continue;
return (register_callback (&list_write, name, (void *) callback));
} /* int plugin_register_write */
-int plugin_register_flush (const char *name, int (*callback) (const int))
+int plugin_register_flush (const char *name,
+ int (*callback) (const int timeout, const char *identifier))
{
return (register_callback (&list_flush, name, (void *) callback));
} /* int plugin_register_flush */
}
} /* void plugin_flush_all */
+int plugin_flush (const char *plugin, int timeout, const char *identifier)
+{
+ int (*callback) (int timeout, const char *identifier);
+ llentry_t *le;
+
+ if (list_flush == NULL)
+ return (0);
+
+ le = llist_head (list_flush);
+ while (le != NULL)
+ {
+ if ((plugin != NULL)
+ && (strcmp (plugin, le->key) != 0))
+ continue;
+
+ callback = (int (*) (int, const char *)) le->value;
+ le = le->next;
+
+ (*callback) (timeout, identifier);
+ }
+ return (0);
+} /* int plugin_flush */
+
void plugin_shutdown_all (void)
{
int (*callback) (void);
}
} /* void plugin_shutdown_all */
-int plugin_dispatch_values (const char *name, value_list_t *vl)
+int plugin_dispatch_values (value_list_t *vl)
{
+ static c_complain_t no_write_complaint = C_COMPLAIN_INIT;
+
int (*callback) (const data_set_t *, const value_list_t *);
data_set_t *ds;
llentry_t *le;
- if (list_write == NULL)
- {
- ERROR ("plugin_dispatch_values: No write callback has been "
- "registered. Please load at least one plugin "
- "that provides a write function.");
+ if ((vl == NULL) || (*vl->type == '\0')) {
+ ERROR ("plugin_dispatch_values: Invalid value list.");
return (-1);
}
+ if (list_write == NULL)
+ c_complain_once (LOG_WARNING, &no_write_complaint,
+ "plugin_dispatch_values: No write callback has been "
+ "registered. Please load at least one output plugin, "
+ "if you want the collected data to be stored.");
+
if (data_sets == NULL)
{
ERROR ("plugin_dispatch_values: No data sets registered. "
return (-1);
}
- if (c_avl_get (data_sets, name, (void *) &ds) != 0)
+ if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
{
- INFO ("plugin_dispatch_values: Dataset not found: %s", name);
+ INFO ("plugin_dispatch_values: Dataset not found: %s", vl->type);
return (-1);
}
(unsigned int) vl->time, vl->interval,
vl->host,
vl->plugin, vl->plugin_instance,
- ds->type, vl->type_instance);
+ vl->type, vl->type_instance);
+
+#if COLLECT_DEBUG
+ assert (0 == strcmp (ds->type, vl->type));
+#else
+ if (0 != strcmp (ds->type, vl->type))
+ WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
+ ds->type, vl->type);
+#endif
#if COLLECT_DEBUG
assert (ds->ds_num == vl->values_len);
escape_slashes (vl->host, sizeof (vl->host));
escape_slashes (vl->plugin, sizeof (vl->plugin));
escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
+ escape_slashes (vl->type, sizeof (vl->type));
escape_slashes (vl->type_instance, sizeof (vl->type_instance));
/* Update the value cache */
return (ds);
} /* data_set_t *plugin_get_ds */
+
+static int plugin_notification_meta_add (notification_t *n,
+ const char *name,
+ enum notification_meta_type_e type,
+ const void *value)
+{
+ notification_meta_t *meta;
+ notification_meta_t *tail;
+
+ if ((n == NULL) || (name == NULL) || (value == NULL))
+ {
+ ERROR ("plugin_notification_meta_add: A pointer is NULL!");
+ return (-1);
+ }
+
+ meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
+ if (meta == NULL)
+ {
+ ERROR ("plugin_notification_meta_add: malloc failed.");
+ return (-1);
+ }
+ memset (meta, 0, sizeof (notification_meta_t));
+
+ sstrncpy (meta->name, name, sizeof (meta->name));
+ meta->type = type;
+
+ switch (type)
+ {
+ case NM_TYPE_STRING:
+ {
+ meta->value_string = strdup ((const char *) value);
+ if (meta->value_string == NULL)
+ {
+ ERROR ("plugin_notification_meta_add: strdup failed.");
+ sfree (meta);
+ return (-1);
+ }
+ break;
+ }
+ case NM_TYPE_SIGNED_INT:
+ {
+ meta->value_signed_int = *((int64_t *) value);
+ break;
+ }
+ case NM_TYPE_UNSIGNED_INT:
+ {
+ meta->value_unsigned_int = *((uint64_t *) value);
+ break;
+ }
+ case NM_TYPE_DOUBLE:
+ {
+ meta->value_double = *((double *) value);
+ break;
+ }
+ case NM_TYPE_BOOLEAN:
+ {
+ meta->value_boolean = *((bool *) value);
+ break;
+ }
+ default:
+ {
+ ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
+ sfree (meta);
+ return (-1);
+ }
+ } /* switch (type) */
+
+ meta->next = NULL;
+ tail = n->meta;
+ while ((tail != NULL) && (tail->next != NULL))
+ tail = tail->next;
+
+ if (tail == NULL)
+ n->meta = meta;
+ else
+ tail->next = meta;
+
+ return (0);
+} /* int plugin_notification_meta_add */
+
+int plugin_notification_meta_add_string (notification_t *n,
+ const char *name,
+ const char *value)
+{
+ return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
+}
+
+int plugin_notification_meta_add_signed_int (notification_t *n,
+ const char *name,
+ int64_t value)
+{
+ return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
+}
+
+int plugin_notification_meta_add_unsigned_int (notification_t *n,
+ const char *name,
+ uint64_t value)
+{
+ return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
+}
+
+int plugin_notification_meta_add_double (notification_t *n,
+ const char *name,
+ double value)
+{
+ return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
+}
+
+int plugin_notification_meta_add_boolean (notification_t *n,
+ const char *name,
+ bool value)
+{
+ return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
+}
+
+int plugin_notification_meta_copy (notification_t *dst,
+ const notification_t *src)
+{
+ notification_meta_t *meta;
+
+ assert (dst != NULL);
+ assert (src != NULL);
+ assert (dst != src);
+ assert ((src->meta == NULL) || (src->meta != dst->meta));
+
+ for (meta = src->meta; meta != NULL; meta = meta->next)
+ {
+ if (meta->type == NM_TYPE_STRING)
+ plugin_notification_meta_add_string (dst, meta->name,
+ meta->value_string);
+ else if (meta->type == NM_TYPE_SIGNED_INT)
+ plugin_notification_meta_add_signed_int (dst, meta->name,
+ meta->value_signed_int);
+ else if (meta->type == NM_TYPE_UNSIGNED_INT)
+ plugin_notification_meta_add_unsigned_int (dst, meta->name,
+ meta->value_unsigned_int);
+ else if (meta->type == NM_TYPE_DOUBLE)
+ plugin_notification_meta_add_double (dst, meta->name,
+ meta->value_double);
+ else if (meta->type == NM_TYPE_BOOLEAN)
+ plugin_notification_meta_add_boolean (dst, meta->name,
+ meta->value_boolean);
+ }
+
+ return (0);
+} /* int plugin_notification_meta_copy */
+
+int plugin_notification_meta_free (notification_t *n)
+{
+ notification_meta_t *this;
+ notification_meta_t *next;
+
+ if (n == NULL)
+ {
+ ERROR ("plugin_notification_meta_free: n == NULL!");
+ return (-1);
+ }
+
+ this = n->meta;
+ n->meta = NULL;
+ while (this != NULL)
+ {
+ next = this->next;
+
+ if (this->type == NM_TYPE_STRING)
+ {
+ free ((char *)this->value_string);
+ this->value_string = NULL;
+ }
+ sfree (this);
+
+ this = next;
+ }
+
+ return (0);
+} /* int plugin_notification_meta_free */
diff --git a/src/plugin.h b/src/plugin.h
index 318b54734a0cbe1777855b624c9dd87adacab492..3bf7e4c1d01174f5f95671f9fd1ea6ed9943eeeb 100644 (file)
--- a/src/plugin.h
+++ b/src/plugin.h
char host[DATA_MAX_NAME_LEN];
char plugin[DATA_MAX_NAME_LEN];
char plugin_instance[DATA_MAX_NAME_LEN];
+ char type[DATA_MAX_NAME_LEN];
char type_instance[DATA_MAX_NAME_LEN];
};
typedef struct value_list_s value_list_t;
-#define VALUE_LIST_INIT { NULL, 0, 0, interval_g, "localhost", "", "", "" }
-#define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "" }
+#define VALUE_LIST_INIT { NULL, 0, 0, interval_g, "localhost", "", "", "", "" }
+#define VALUE_LIST_STATIC { NULL, 0, 0, 0, "localhost", "", "", "", "" }
struct data_source_s
{
};
typedef struct data_set_s data_set_t;
+enum notification_meta_type_e
+{
+ NM_TYPE_STRING,
+ NM_TYPE_SIGNED_INT,
+ NM_TYPE_UNSIGNED_INT,
+ NM_TYPE_DOUBLE,
+ NM_TYPE_BOOLEAN
+};
+
+typedef struct notification_meta_s
+{
+ char name[DATA_MAX_NAME_LEN];
+ enum notification_meta_type_e type;
+ union
+ {
+ const char *value_string;
+ int64_t value_signed_int;
+ uint64_t value_unsigned_int;
+ double value_double;
+ bool value_boolean;
+ };
+ struct notification_meta_s *next;
+} notification_meta_t;
+
typedef struct notification_s
{
int severity;
char plugin_instance[DATA_MAX_NAME_LEN];
char type[DATA_MAX_NAME_LEN];
char type_instance[DATA_MAX_NAME_LEN];
+ notification_meta_t *meta;
} notification_t;
/*
void plugin_init_all (void);
void plugin_read_all (void);
-void plugin_flush_all (int timeout);
void plugin_shutdown_all (void);
+void plugin_flush_all (int timeout);
int plugin_flush_one (int timeout, const char *name);
+int plugin_flush (const char *plugin, int timeout, const char *identifier);
/*
* The `plugin_register_*' functions are used to make `config', `init',
int plugin_register_write (const char *name,
int (*callback) (const data_set_t *ds, const value_list_t *vl));
int plugin_register_flush (const char *name,
- int (*callback) (const int));
+ int (*callback) (const int timeout, const char *identifier));
int plugin_register_shutdown (char *name,
int (*callback) (void));
int plugin_register_data_set (const data_set_t *ds);
* write-functions.
*
* ARGUMENTS
- * `name' Name/type of the data-set that describe the values in `vl'.
* `vl' Value list of the values that have been read by a `read'
* function.
*/
-int plugin_dispatch_values (const char *name, value_list_t *vl);
+int plugin_dispatch_values (value_list_t *vl);
int plugin_dispatch_notification (const notification_t *notif);
const data_set_t *plugin_get_ds (const char *name);
+int plugin_notification_meta_add_string (notification_t *n,
+ const char *name,
+ const char *value);
+int plugin_notification_meta_add_signed_int (notification_t *n,
+ const char *name,
+ int64_t value);
+int plugin_notification_meta_add_unsigned_int (notification_t *n,
+ const char *name,
+ uint64_t value);
+int plugin_notification_meta_add_double (notification_t *n,
+ const char *name,
+ double value);
+int plugin_notification_meta_add_boolean (notification_t *n,
+ const char *name,
+ bool value);
+
+int plugin_notification_meta_copy (notification_t *dst,
+ const notification_t *src);
+
+int plugin_notification_meta_free (notification_t *n);
+
#endif /* PLUGIN_H */
diff --git a/src/postgresql.c b/src/postgresql.c
--- /dev/null
+++ b/src/postgresql.c
@@ -0,0 +1,519 @@
+/**
+ * collectd - src/postgresql.c
+ * Copyright (C) 2008 Sebastian Harl
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Sebastian Harl <sh at tokkee.org>
+ **/
+
+/*
+ * This module collects PostgreSQL database statistics.
+ */
+
+#include "collectd.h"
+#include "common.h"
+
+#include "configfile.h"
+#include "plugin.h"
+
+#include "utils_complain.h"
+
+#include <pg_config_manual.h>
+#include <libpq-fe.h>
+
+#define log_err(...) ERROR ("postgresql: " __VA_ARGS__)
+#define log_warn(...) WARNING ("postgresql: " __VA_ARGS__)
+#define log_info(...) INFO ("postgresql: " __VA_ARGS__)
+
+/* Appends the (parameter, value) pair to the string
+ * pointed to by 'buf' suitable to be used as argument
+ * for PQconnectdb(). If value equals NULL, the pair
+ * is ignored. */
+#define C_PSQL_PAR_APPEND(buf, buf_len, parameter, value) \
+ if ((0 < (buf_len)) && (NULL != (value)) && ('\0' != *(value))) { \
+ int s = ssnprintf (buf, buf_len, " %s = '%s'", parameter, value); \
+ if (0 < s) { \
+ buf += s; \
+ buf_len -= s; \
+ } \
+ }
+
+/* Returns the tuple (major, minor, patchlevel)
+ * for the given version number. */
+#define C_PSQL_SERVER_VERSION3(server_version) \
+ (server_version) / 10000, \
+ (server_version) / 100 - (int)((server_version) / 10000) * 100, \
+ (server_version) - (int)((server_version) / 100) * 100
+
+/* Returns true if the given host specifies a
+ * UNIX domain socket. */
+#define C_PSQL_IS_UNIX_DOMAIN_SOCKET(host) \
+ ((NULL == (host)) || ('\0' == *(host)) || ('/' == *(host)))
+
+/* Returns the tuple (host, delimiter, port) for a
+ * given (host, port) pair. Depending on the value of
+ * 'host' a UNIX domain socket or a TCP socket is
+ * assumed. */
+#define C_PSQL_SOCKET3(host, port) \
+ ((NULL == (host)) || ('\0' == *(host))) ? DEFAULT_PGSOCKET_DIR : host, \
+ C_PSQL_IS_UNIX_DOMAIN_SOCKET (host) ? "/.s.PGSQL." : ":", \
+ port
+
+typedef struct {
+ PGconn *conn;
+ c_complain_t conn_complaint;
+
+ /* user configuration */
+ char *host;
+ char *port;
+ char *database;
+ char *user;
+ char *password;
+
+ char *sslmode;
+
+ char *krbsrvname;
+
+ char *service;
+} c_psql_database_t;
+
+static c_psql_database_t *databases = NULL;
+static int databases_num = 0;
+
+static void submit (const c_psql_database_t *db,
+ const char *type, const char *type_instance,
+ value_t *values, size_t values_len)
+{
+ value_list_t vl = VALUE_LIST_INIT;
+
+ vl.values = values;
+ vl.values_len = values_len;
+ vl.time = time (NULL);
+
+ if (C_PSQL_IS_UNIX_DOMAIN_SOCKET (db->host)
+ || (0 == strcmp (db->host, "localhost")))
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ else
+ sstrncpy (vl.host, db->host, sizeof (vl.host));
+
+ sstrncpy (vl.plugin, "postgresql", sizeof (vl.plugin));
+ sstrncpy (vl.plugin_instance, db->database, sizeof (vl.plugin_instance));
+
+ sstrncpy (vl.type, type, sizeof (vl.type));
+
+ if (NULL != type_instance)
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+
+ plugin_dispatch_values (&vl);
+ return;
+} /* submit */
+
+static void submit_counter (const c_psql_database_t *db,
+ const char *type, const char *type_instance,
+ const char *value)
+{
+ value_t values[1];
+
+ if ((NULL == value) || ('\0' == *value))
+ return;
+
+ values[0].counter = atoll (value);
+ submit (db, type, type_instance, values, 1);
+ return;
+} /* submit_counter */
+
+static void submit_gauge (const c_psql_database_t *db,
+ const char *type, const char *type_instance,
+ const char *value)
+{
+ value_t values[1];
+
+ if ((NULL == value) || ('\0' == *value))
+ return;
+
+ values[0].gauge = atof (value);
+ submit (db, type, type_instance, values, 1);
+ return;
+} /* submit_gauge */
+
+static int c_psql_check_connection (c_psql_database_t *db)
+{
+ /* "ping" */
+ PQclear (PQexec (db->conn, "SELECT 42;"));
+
+ if (CONNECTION_OK != PQstatus (db->conn)) {
+ PQreset (db->conn);
+
+ /* trigger c_release() */
+ if (0 == db->conn_complaint.interval)
+ db->conn_complaint.interval = 1;
+
+ if (CONNECTION_OK != PQstatus (db->conn)) {
+ c_complain (LOG_ERR, &db->conn_complaint,
+ "Failed to connect to database %s: %s",
+ db->database, PQerrorMessage (db->conn));
+ return -1;
+ }
+ }
+
+ c_release (LOG_INFO, &db->conn_complaint,
+ "Successfully reconnected to database %s", PQdb (db->conn));
+ return 0;
+} /* c_psql_check_connection */
+
+static int c_psql_stat_database (c_psql_database_t *db)
+{
+ const char *const query =
+ "SELECT numbackends, xact_commit, xact_rollback "
+ "FROM pg_stat_database "
+ "WHERE datname = $1;";
+
+ PGresult *res;
+
+ int n;
+
+ res = PQexecParams (db->conn, query, /* number of parameters */ 1,
+ NULL, (const char *const *)&db->database, NULL, NULL,
+ /* return text data */ 0);
+
+ if (PGRES_TUPLES_OK != PQresultStatus (res)) {
+ log_err ("Failed to execute SQL query: %s",
+ PQerrorMessage (db->conn));
+ log_info ("SQL query was: %s", query);
+ PQclear (res);
+ return -1;
+ }
+
+ n = PQntuples (res);
+ if (1 < n) {
+ log_warn ("pg_stat_database has more than one entry "
+ "for database %s - ignoring additional results.",
+ db->database);
+ }
+ else if (1 > n) {
+ log_err ("pg_stat_database has no entry for database %s",
+ db->database);
+ PQclear (res);
+ return -1;
+ }
+
+ submit_gauge (db, "pg_numbackends", NULL, PQgetvalue (res, 0, 0));
+
+ submit_counter (db, "pg_xact", "commit", PQgetvalue (res, 0, 1));
+ submit_counter (db, "pg_xact", "rollback", PQgetvalue (res, 0, 2));
+
+ PQclear (res);
+ return 0;
+} /* c_psql_stat_database */
+
+static int c_psql_stat_user_tables (c_psql_database_t *db)
+{
+ const char *const query =
+ "SELECT sum(seq_scan), sum(seq_tup_read), "
+ "sum(idx_scan), sum(idx_tup_fetch), "
+ "sum(n_tup_ins), sum(n_tup_upd), sum(n_tup_del), "
+ "sum(n_tup_hot_upd), sum(n_live_tup), sum(n_dead_tup) "
+ "FROM pg_stat_user_tables;";
+
+ PGresult *res;
+
+ int n;
+
+ res = PQexec (db->conn, query);
+
+ if (PGRES_TUPLES_OK != PQresultStatus (res)) {
+ log_err ("Failed to execute SQL query: %s",
+ PQerrorMessage (db->conn));
+ log_info ("SQL query was: %s", query);
+ PQclear (res);
+ return -1;
+ }
+
+ n = PQntuples (res);
+ assert (1 >= n);
+
+ if (1 > n) /* no user tables */
+ return 0;
+
+ submit_counter (db, "pg_scan", "seq", PQgetvalue (res, 0, 0));
+ submit_counter (db, "pg_scan", "seq_tup_read", PQgetvalue (res, 0, 1));
+ submit_counter (db, "pg_scan", "idx", PQgetvalue (res, 0, 2));
+ submit_counter (db, "pg_scan", "idx_tup_fetch", PQgetvalue (res, 0, 3));
+
+ submit_counter (db, "pg_n_tup_c", "ins", PQgetvalue (res, 0, 4));
+ submit_counter (db, "pg_n_tup_c", "upd", PQgetvalue (res, 0, 5));
+ submit_counter (db, "pg_n_tup_c", "del", PQgetvalue (res, 0, 6));
+ submit_counter (db, "pg_n_tup_c", "hot_upd", PQgetvalue (res, 0, 7));
+
+ submit_gauge (db, "pg_n_tup_g", "live", PQgetvalue (res, 0, 8));
+ submit_gauge (db, "pg_n_tup_g", "dead", PQgetvalue (res, 0, 9));
+
+ PQclear (res);
+ return 0;
+} /* c_psql_stat_user_tables */
+
+static int c_psql_statio_user_tables (c_psql_database_t *db)
+{
+ const char *const query =
+ "SELECT sum(heap_blks_read), sum(heap_blks_hit), "
+ "sum(idx_blks_read), sum(idx_blks_hit), "
+ "sum(toast_blks_read), sum(toast_blks_hit), "
+ "sum(tidx_blks_read), sum(tidx_blks_hit) "
+ "FROM pg_statio_user_tables;";
+
+ PGresult *res;
+
+ int n;
+
+ res = PQexec (db->conn, query);
+
+ if (PGRES_TUPLES_OK != PQresultStatus (res)) {
+ log_err ("Failed to execute SQL query: %s",
+ PQerrorMessage (db->conn));
+ log_info ("SQL query was: %s", query);
+ PQclear (res);
+ return -1;
+ }
+
+ n = PQntuples (res);
+ assert (1 >= n);
+
+ if (1 > n) /* no user tables */
+ return 0;
+
+ submit_counter (db, "pg_blks", "heap_read", PQgetvalue (res, 0, 0));
+ submit_counter (db, "pg_blks", "heap_hit", PQgetvalue (res, 0, 1));
+
+ submit_counter (db, "pg_blks", "idx_read", PQgetvalue (res, 0, 2));
+ submit_counter (db, "pg_blks", "idx_hit", PQgetvalue (res, 0, 3));
+
+ submit_counter (db, "pg_blks", "toast_read", PQgetvalue (res, 0, 4));
+ submit_counter (db, "pg_blks", "toast_hit", PQgetvalue (res, 0, 5));
+
+ submit_counter (db, "pg_blks", "tidx_read", PQgetvalue (res, 0, 6));
+ submit_counter (db, "pg_blks", "tidx_hit", PQgetvalue (res, 0, 7));
+
+ PQclear (res);
+ return 0;
+} /* c_psql_statio_user_tables */
+
+static int c_psql_read (void)
+{
+ int success = 0;
+ int i;
+
+ for (i = 0; i < databases_num; ++i) {
+ c_psql_database_t *db = databases + i;
+
+ assert (NULL != db->database);
+
+ if (0 != c_psql_check_connection (db))
+ continue;
+
+ c_psql_stat_database (db);
+ c_psql_stat_user_tables (db);
+ c_psql_statio_user_tables (db);
+
+ ++success;
+ }
+
+ if (! success)
+ return -1;
+ return 0;
+} /* c_psql_read */
+
+static int c_psql_shutdown (void)
+{
+ int i;
+
+ if ((NULL == databases) || (0 == databases_num))
+ return 0;
+
+ plugin_unregister_read ("postgresql");
+ plugin_unregister_shutdown ("postgresql");
+
+ for (i = 0; i < databases_num; ++i) {
+ c_psql_database_t *db = databases + i;
+
+ PQfinish (db->conn);
+
+ sfree (db->database);
+ sfree (db->host);
+ sfree (db->port);
+ sfree (db->user);
+ sfree (db->password);
+
+ sfree (db->sslmode);
+
+ sfree (db->krbsrvname);
+
+ sfree (db->service);
+ }
+
+ sfree (databases);
+ databases_num = 0;
+ return 0;
+} /* c_psql_shutdown */
+
+static int c_psql_init (void)
+{
+ int i;
+
+ if ((NULL == databases) || (0 == databases_num))
+ return 0;
+
+ for (i = 0; i < databases_num; ++i) {
+ c_psql_database_t *db = databases + i;
+
+ char conninfo[4096];
+ char *buf = conninfo;
+ int buf_len = sizeof (conninfo);
+ int status;
+
+ char *server_host;
+ int server_version;
+
+ status = ssnprintf (buf, buf_len, "dbname = '%s'", db->database);
+ if (0 < status) {
+ buf += status;
+ buf_len -= status;
+ }
+
+ C_PSQL_PAR_APPEND (buf, buf_len, "host", db->host);
+ C_PSQL_PAR_APPEND (buf, buf_len, "port", db->port);
+ C_PSQL_PAR_APPEND (buf, buf_len, "user", db->user);
+ C_PSQL_PAR_APPEND (buf, buf_len, "password", db->password);
+ C_PSQL_PAR_APPEND (buf, buf_len, "sslmode", db->sslmode);
+ C_PSQL_PAR_APPEND (buf, buf_len, "krbsrvname", db->krbsrvname);
+ C_PSQL_PAR_APPEND (buf, buf_len, "service", db->service);
+
+ db->conn = PQconnectdb (conninfo);
+ if (0 != c_psql_check_connection (db))
+ continue;
+
+ server_host = PQhost (db->conn);
+ server_version = PQserverVersion (db->conn);
+ log_info ("Sucessfully connected to database %s (user %s) "
+ "at server %s%s%s (server version: %d.%d.%d, "
+ "protocol version: %d, pid: %d)",
+ PQdb (db->conn), PQuser (db->conn),
+ C_PSQL_SOCKET3(server_host, PQport (db->conn)),
+ C_PSQL_SERVER_VERSION3 (server_version),
+ PQprotocolVersion (db->conn), PQbackendPID (db->conn));
+ }
+
+ plugin_register_read ("postgresql", c_psql_read);
+ plugin_register_shutdown ("postgresql", c_psql_shutdown);
+ return 0;
+} /* c_psql_init */
+
+static int config_set (char *name, char **var, const oconfig_item_t *ci)
+{
+ if ((0 != ci->children_num) || (1 != ci->values_num)
+ || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
+ log_err ("%s expects a single string argument.", name);
+ return 1;
+ }
+
+ sfree (*var);
+ *var = sstrdup (ci->values[0].value.string);
+ return 0;
+} /* config_set */
+
+static int c_psql_config_database (oconfig_item_t *ci)
+{
+ c_psql_database_t *db;
+
+ int i;
+
+ if ((1 != ci->values_num)
+ || (OCONFIG_TYPE_STRING != ci->values[0].type)) {
+ log_err ("<Database> expects a single string argument.");
+ return 1;
+ }
+
+ ++databases_num;
+ if (NULL == (databases = (c_psql_database_t *)realloc (databases,
+ databases_num * sizeof (*databases)))) {
+ log_err ("Out of memory.");
+ exit (5);
+ }
+
+ db = databases + (databases_num - 1);
+
+ db->conn = NULL;
+
+ db->conn_complaint.last = 0;
+ db->conn_complaint.interval = 0;
+
+ db->database = sstrdup (ci->values[0].value.string);
+ db->host = NULL;
+ db->port = NULL;
+ db->user = NULL;
+ db->password = NULL;
+
+ db->sslmode = NULL;
+
+ db->krbsrvname = NULL;
+
+ db->service = NULL;
+
+ for (i = 0; i < ci->children_num; ++i) {
+ oconfig_item_t *c = ci->children + i;
+
+ if (0 == strcasecmp (c->key, "Host"))
+ config_set ("Host", &db->host, c);
+ else if (0 == strcasecmp (c->key, "Port"))
+ config_set ("Port", &db->port, c);
+ else if (0 == strcasecmp (c->key, "User"))
+ config_set ("User", &db->user, c);
+ else if (0 == strcasecmp (c->key, "Password"))
+ config_set ("Password", &db->password, c);
+ else if (0 == strcasecmp (c->key, "SSLMode"))
+ config_set ("SSLMode", &db->sslmode, c);
+ else if (0 == strcasecmp (c->key, "KRBSrvName"))
+ config_set ("KRBSrvName", &db->krbsrvname, c);
+ else if (0 == strcasecmp (c->key, "Service"))
+ config_set ("Service", &db->service, c);
+ else
+ log_warn ("Ignoring unknown config key \"%s\".", c->key);
+ }
+ return 0;
+}
+
+static int c_psql_config (oconfig_item_t *ci)
+{
+ int i;
+
+ for (i = 0; i < ci->children_num; ++i) {
+ oconfig_item_t *c = ci->children + i;
+
+ if (0 == strcasecmp (c->key, "Database"))
+ c_psql_config_database (c);
+ else
+ log_warn ("Ignoring unknown config key \"%s\".", c->key);
+ }
+ return 0;
+} /* c_psql_config */
+
+void module_register (void)
+{
+ plugin_register_complex_config ("postgresql", c_psql_config);
+ plugin_register_init ("postgresql", c_psql_init);
+} /* module_register */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/powerdns.c b/src/powerdns.c
index 644dd56b99f3d1dec0ead8d926145a9e7d274582..b451073ff351b9c4831949c93d2ac1e70838e88a 100644 (file)
--- a/src/powerdns.c
+++ b/src/powerdns.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "powerdns", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* }}} static void submit */
static int powerdns_get_data_dgram (list_item_t *item, /* {{{ */
memset (&sa_unix, 0, sizeof (sa_unix));
sa_unix.sun_family = AF_UNIX;
- strncpy (sa_unix.sun_path,
+ sstrncpy (sa_unix.sun_path,
(local_sockpath != NULL) ? local_sockpath : PDNS_LOCAL_SOCKPATH,
sizeof (sa_unix.sun_path));
- sa_unix.sun_path[sizeof (sa_unix.sun_path) - 1] = 0;
status = unlink (sa_unix.sun_path);
if ((status != 0) && (errno != ENOENT))
}
item->sockaddr.sun_family = AF_UNIX;
- sstrncpy (item->sockaddr.sun_path, socket_temp, UNIX_PATH_MAX);
+ sstrncpy (item->sockaddr.sun_path, socket_temp,
+ sizeof (item->sockaddr.sun_path));
e = llentry_create (item->instance, item);
if (e == NULL)
diff --git a/src/processes.c b/src/processes.c
index 6ad4681370aa7861e11cb7b956576010befd0faa..7531a6ae9cc1ac8d06c01ad7d1b7bc8ea7c936d6 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
/**
* collectd - src/processes.c
* Copyright (C) 2005 Lyonel Vincent
- * Copyright (C) 2006-2007 Florian Forster (Mach code)
+ * Copyright (C) 2006-2008 Florian Forster (Mach code)
+ * Copyright (C) 2008 Oleg King
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Authors:
* Lyonel Vincent <lyonel at ezix.org>
* Florian octo Forster <octo at verplant.org>
+ * Oleg King <king2 at kaluga.ru>
**/
#include "collectd.h"
# endif
/* #endif KERNEL_LINUX */
+#elif HAVE_KVM_H
+# include <kvm.h>
+# include <sys/user.h>
+# include <sys/proc.h>
+# if HAVE_SYS_SYSCTL_H
+# include <sys/sysctl.h>
+# endif
+/* #endif HAVE_KVM_H */
+
#else
# error "No applicable input method."
#endif
+#if HAVE_REGEX_H
+# include <regex.h>
+#endif
+
#define BUFSIZE 256
static const char *config_keys[] =
{
"Process",
+ "ProcessMatch",
NULL
};
-static int config_keys_num = 1;
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
typedef struct procstat_entry_s
{
typedef struct procstat
{
char name[PROCSTAT_NAME_LEN];
+#if HAVE_REGEX_H
+ regex_t *re;
+#endif
unsigned long num_proc;
unsigned long num_lwp;
static long pagesize_g;
#endif /* KERNEL_LINUX */
-static void ps_list_register (const char *name)
+/* put name of process from config to list_head_g tree
+ list_head_g is a list of 'procstat_t' structs with
+ processes names we want to watch */
+static void ps_list_register (const char *name, const char *regexp)
{
procstat_t *new;
procstat_t *ptr;
+ int status;
- if ((new = (procstat_t *) malloc (sizeof (procstat_t))) == NULL)
+ new = (procstat_t *) malloc (sizeof (procstat_t));
+ if (new == NULL)
+ {
+ ERROR ("processes plugin: ps_list_register: malloc failed.");
return;
+ }
memset (new, 0, sizeof (procstat_t));
- strncpy (new->name, name, PROCSTAT_NAME_LEN);
+ sstrncpy (new->name, name, sizeof (new->name));
+#if HAVE_REGEX_H
+ if (regexp != NULL)
+ {
+ DEBUG ("ProcessMatch: adding \"%s\" as criteria to process %s.", regexp, name);
+ new->re = (regex_t *) malloc (sizeof (regex_t));
+ if (new->re == NULL)
+ {
+ ERROR ("processes plugin: ps_list_register: malloc failed.");
+ sfree (new);
+ return;
+ }
+
+ status = regcomp (new->re, regexp, REG_EXTENDED | REG_NOSUB);
+ if (status != 0)
+ {
+ DEBUG ("ProcessMatch: compiling the regular expression \"%s\" failed.", regexp);
+ sfree(new->re);
+ return;
+ }
+ }
+#else
+ if (regexp != NULL)
+ {
+ ERROR ("processes plugin: ps_list_register: "
+ "Regular expression \"%s\" found in config "
+ "file, but support for regular expressions "
+ "has been dispabled at compile time.",
+ regexp);
+ sfree (new);
+ return;
+ }
+#endif
+
for (ptr = list_head_g; ptr != NULL; ptr = ptr->next)
{
if (strcmp (ptr->name, name) == 0)
+ {
+ WARNING ("processes plugin: You have configured more "
+ "than one `Process' or "
+ "`ProcessMatch' with the same name. "
+ "All but the first setting will be "
+ "ignored.");
+ sfree (new->re);
+ sfree (new);
return;
+ }
+
if (ptr->next == NULL)
break;
}
list_head_g = new;
else
ptr->next = new;
-}
+} /* void ps_list_register */
-static procstat_t *ps_list_search (const char *name)
+/* try to match name against entry, returns 1 if success */
+static int ps_list_match (const char *name, const char *cmdline, procstat_t *ps)
{
- procstat_t *ptr;
+#if HAVE_REGEX_H
+ if (ps->re != NULL)
+ {
+ int status;
+ const char *str;
- for (ptr = list_head_g; ptr != NULL; ptr = ptr->next)
- if (strcmp (ptr->name, name) == 0)
- break;
+ str = cmdline;
+ if ((str == NULL) || (str[0] == 0))
+ str = name;
- return (ptr);
-}
+ assert (str != NULL);
+
+ status = regexec (ps->re, str,
+ /* nmatch = */ 0,
+ /* pmatch = */ NULL,
+ /* eflags = */ 0);
+ if (status == 0)
+ return (1);
+ }
+ else
+#endif
+ if (strcmp (ps->name, name) == 0)
+ return (1);
-static void ps_list_add (const char *name, procstat_entry_t *entry)
+ return (0);
+} /* int ps_list_match */
+
+/* add process entry to 'instances' of process 'name' (or refresh it) */
+static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t *entry)
{
procstat_t *ps;
procstat_entry_t *pse;
if (entry->id == 0)
return;
- if ((ps = ps_list_search (name)) == NULL)
- return;
-
- for (pse = ps->instances; pse != NULL; pse = pse->next)
- if ((pse->id == entry->id) || (pse->next == NULL))
- break;
-
- if ((pse == NULL) || (pse->id != entry->id))
+ for (ps = list_head_g; ps != NULL; ps = ps->next)
{
- procstat_entry_t *new;
-
- new = (procstat_entry_t *) malloc (sizeof (procstat_entry_t));
- if (new == NULL)
- return;
- memset (new, 0, sizeof (procstat_entry_t));
- new->id = entry->id;
+ if ((ps_list_match (name, cmdline, ps)) == 0)
+ continue;
- if (pse == NULL)
- ps->instances = new;
- else
- pse->next = new;
+ for (pse = ps->instances; pse != NULL; pse = pse->next)
+ if ((pse->id == entry->id) || (pse->next == NULL))
+ break;
- pse = new;
- }
+ if ((pse == NULL) || (pse->id != entry->id))
+ {
+ procstat_entry_t *new;
+
+ new = (procstat_entry_t *) malloc (sizeof (procstat_entry_t));
+ if (new == NULL)
+ return;
+ memset (new, 0, sizeof (procstat_entry_t));
+ new->id = entry->id;
+
+ if (pse == NULL)
+ ps->instances = new;
+ else
+ pse->next = new;
- pse->age = 0;
- pse->num_proc = entry->num_proc;
- pse->num_lwp = entry->num_lwp;
- pse->vmem_rss = entry->vmem_rss;
+ pse = new;
+ }
- ps->num_proc += pse->num_proc;
- ps->num_lwp += pse->num_lwp;
- ps->vmem_rss += pse->vmem_rss;
+ pse->age = 0;
+ pse->num_proc = entry->num_proc;
+ pse->num_lwp = entry->num_lwp;
+ pse->vmem_rss = entry->vmem_rss;
- if ((entry->vmem_minflt_counter == 0)
- && (entry->vmem_majflt_counter == 0))
- {
- pse->vmem_minflt_counter += entry->vmem_minflt;
- pse->vmem_minflt = entry->vmem_minflt;
+ ps->num_proc += pse->num_proc;
+ ps->num_lwp += pse->num_lwp;
+ ps->vmem_rss += pse->vmem_rss;
- pse->vmem_majflt_counter += entry->vmem_majflt;
- pse->vmem_majflt = entry->vmem_majflt;
- }
- else
- {
- if (entry->vmem_minflt_counter < pse->vmem_minflt_counter)
+ if ((entry->vmem_minflt_counter == 0)
+ && (entry->vmem_majflt_counter == 0))
{
- pse->vmem_minflt = entry->vmem_minflt_counter
- + (ULONG_MAX - pse->vmem_minflt_counter);
- }
- else
- {
- pse->vmem_minflt = entry->vmem_minflt_counter - pse->vmem_minflt_counter;
- }
- pse->vmem_minflt_counter = entry->vmem_minflt_counter;
+ pse->vmem_minflt_counter += entry->vmem_minflt;
+ pse->vmem_minflt = entry->vmem_minflt;
- if (entry->vmem_majflt_counter < pse->vmem_majflt_counter)
- {
- pse->vmem_majflt = entry->vmem_majflt_counter
- + (ULONG_MAX - pse->vmem_majflt_counter);
+ pse->vmem_majflt_counter += entry->vmem_majflt;
+ pse->vmem_majflt = entry->vmem_majflt;
}
else
{
- pse->vmem_majflt = entry->vmem_majflt_counter - pse->vmem_majflt_counter;
+ if (entry->vmem_minflt_counter < pse->vmem_minflt_counter)
+ {
+ pse->vmem_minflt = entry->vmem_minflt_counter
+ + (ULONG_MAX - pse->vmem_minflt_counter);
+ }
+ else
+ {
+ pse->vmem_minflt = entry->vmem_minflt_counter - pse->vmem_minflt_counter;
+ }
+ pse->vmem_minflt_counter = entry->vmem_minflt_counter;
+
+ if (entry->vmem_majflt_counter < pse->vmem_majflt_counter)
+ {
+ pse->vmem_majflt = entry->vmem_majflt_counter
+ + (ULONG_MAX - pse->vmem_majflt_counter);
+ }
+ else
+ {
+ pse->vmem_majflt = entry->vmem_majflt_counter - pse->vmem_majflt_counter;
+ }
+ pse->vmem_majflt_counter = entry->vmem_majflt_counter;
}
- pse->vmem_majflt_counter = entry->vmem_majflt_counter;
- }
-
- ps->vmem_minflt_counter += pse->vmem_minflt;
- ps->vmem_majflt_counter += pse->vmem_majflt;
- if ((entry->cpu_user_counter == 0)
- && (entry->cpu_system_counter == 0))
- {
- pse->cpu_user_counter += entry->cpu_user;
- pse->cpu_user = entry->cpu_user;
+ ps->vmem_minflt_counter += pse->vmem_minflt;
+ ps->vmem_majflt_counter += pse->vmem_majflt;
- pse->cpu_system_counter += entry->cpu_system;
- pse->cpu_system = entry->cpu_system;
- }
- else
- {
- if (entry->cpu_user_counter < pse->cpu_user_counter)
+ if ((entry->cpu_user_counter == 0)
+ && (entry->cpu_system_counter == 0))
{
- pse->cpu_user = entry->cpu_user_counter
- + (ULONG_MAX - pse->cpu_user_counter);
- }
- else
- {
- pse->cpu_user = entry->cpu_user_counter - pse->cpu_user_counter;
- }
- pse->cpu_user_counter = entry->cpu_user_counter;
+ pse->cpu_user_counter += entry->cpu_user;
+ pse->cpu_user = entry->cpu_user;
- if (entry->cpu_system_counter < pse->cpu_system_counter)
- {
- pse->cpu_system = entry->cpu_system_counter
- + (ULONG_MAX - pse->cpu_system_counter);
+ pse->cpu_system_counter += entry->cpu_system;
+ pse->cpu_system = entry->cpu_system;
}
else
{
- pse->cpu_system = entry->cpu_system_counter - pse->cpu_system_counter;
+ if (entry->cpu_user_counter < pse->cpu_user_counter)
+ {
+ pse->cpu_user = entry->cpu_user_counter
+ + (ULONG_MAX - pse->cpu_user_counter);
+ }
+ else
+ {
+ pse->cpu_user = entry->cpu_user_counter - pse->cpu_user_counter;
+ }
+ pse->cpu_user_counter = entry->cpu_user_counter;
+
+ if (entry->cpu_system_counter < pse->cpu_system_counter)
+ {
+ pse->cpu_system = entry->cpu_system_counter
+ + (ULONG_MAX - pse->cpu_system_counter);
+ }
+ else
+ {
+ pse->cpu_system = entry->cpu_system_counter - pse->cpu_system_counter;
+ }
+ pse->cpu_system_counter = entry->cpu_system_counter;
}
- pse->cpu_system_counter = entry->cpu_system_counter;
- }
- ps->cpu_user_counter += pse->cpu_user;
- ps->cpu_system_counter += pse->cpu_system;
+ ps->cpu_user_counter += pse->cpu_user;
+ ps->cpu_system_counter += pse->cpu_system;
+ }
}
+/* remove old entries from instances of processes in list_head_g */
static void ps_list_reset (void)
{
procstat_t *ps;
} /* for (ps = list_head_g; ps != NULL; ps = ps->next) */
}
+/* put all pre-defined 'Process' names from config to list_head_g tree */
static int ps_config (const char *key, const char *value)
{
if (strcasecmp (key, "Process") == 0)
{
- ps_list_register (value);
+ ps_list_register (value, NULL);
+ }
+ else if (strcasecmp (key, "ProcessMatch") == 0)
+ {
+ char *new_val;
+ char *fields[3];
+ int fields_num;
+
+ new_val = strdup (value);
+ if (new_val == NULL)
+ return (1);
+ fields_num = strsplit (new_val, fields,
+ STATIC_ARRAY_SIZE (fields));
+ if (fields_num != 2)
+ {
+ sfree (new_val);
+ return (1);
+ }
+ ps_list_register (fields[0], fields[1]);
+ sfree (new_val);
}
else
{
return (0);
} /* int ps_init */
+/* submit global state (e.g.: qty of zombies, running, etc..) */
static void ps_submit_state (const char *state, double value)
{
value_t values[1];
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "processes", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, "", sizeof (vl.plugin_instance));
- strncpy (vl.type_instance, state, sizeof (vl.type_instance));
+ sstrncpy (vl.type, "ps_state", sizeof (vl.type));
+ sstrncpy (vl.type_instance, state, sizeof (vl.type_instance));
- plugin_dispatch_values ("ps_state", &vl);
+ plugin_dispatch_values (&vl);
}
+/* submit info about specific process (e.g.: memory taken, cpu usage, etc..) */
static void ps_submit_proc_list (procstat_t *ps)
{
value_t values[2];
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "processes", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance));
+ sstrncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, "ps_rss", sizeof (vl.type));
vl.values[0].gauge = ps->vmem_rss;
vl.values_len = 1;
- plugin_dispatch_values ("ps_rss", &vl);
+ plugin_dispatch_values (&vl);
+ sstrncpy (vl.type, "ps_cputime", sizeof (vl.type));
vl.values[0].counter = ps->cpu_user_counter;
vl.values[1].counter = ps->cpu_system_counter;
vl.values_len = 2;
- plugin_dispatch_values ("ps_cputime", &vl);
+ plugin_dispatch_values (&vl);
+ sstrncpy (vl.type, "ps_count", sizeof (vl.type));
vl.values[0].gauge = ps->num_proc;
vl.values[1].gauge = ps->num_lwp;
vl.values_len = 2;
- plugin_dispatch_values ("ps_count", &vl);
+ plugin_dispatch_values (&vl);
+ sstrncpy (vl.type, "ps_pagefaults", sizeof (vl.type));
vl.values[0].counter = ps->vmem_minflt_counter;
vl.values[1].counter = ps->vmem_majflt_counter;
vl.values_len = 2;
- plugin_dispatch_values ("ps_pagefaults", &vl);
+ plugin_dispatch_values (&vl);
DEBUG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; "
"vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; "
ps->cpu_user_counter, ps->cpu_system_counter);
} /* void ps_submit_proc_list */
+/* ------- additional functions for KERNEL_LINUX/HAVE_THREAD_INFO ------- */
#if KERNEL_LINUX
static int *ps_read_tasks (int pid)
{
DIR *dh;
struct dirent *ent;
- snprintf (dirname, 64, "/proc/%i/task", pid);
- dirname[63] = '\0';
+ ssnprintf (dirname, sizeof (dirname), "/proc/%i/task", pid);
if ((dh = opendir (dirname)) == NULL)
{
{
char filename[64];
char buffer[1024];
- FILE *fh;
char *fields[64];
char fields_len;
memset (ps, 0, sizeof (procstat_t));
- snprintf (filename, 64, "/proc/%i/stat", pid);
- filename[63] = '\0';
+ ssnprintf (filename, sizeof (filename), "/proc/%i/stat", pid);
- if ((fh = fopen (filename, "r")) == NULL)
+ i = read_file_contents (filename, buffer, sizeof(buffer) - 1);
+ if (i <= 0)
return (-1);
-
- if (fgets (buffer, 1024, fh) == NULL)
- {
- fclose (fh);
- return (-1);
- }
-
- fclose (fh);
+ buffer[i] = 0;
fields_len = strsplit (buffer, fields, 64);
if (fields_len < 24)
@@ -663,7 +776,9 @@ static int mach_get_task_name (task_t t, int *pid, char *name, size_t name_max_l
return (0);
}
#endif /* HAVE_THREAD_INFO */
+/* ------- end of additional functions for KERNEL_LINUX/HAVE_THREAD_INFO ------- */
+/* do actual readings from kernel */
static int ps_read (void)
{
#if HAVE_THREAD_INFO
if (mach_get_task_name (task_list[task],
&task_pid,
task_name, PROCSTAT_NAME_LEN) == 0)
- ps = ps_list_search (task_name);
+ {
+ /* search for at least one match */
+ for (ps = list_head_g; ps != NULL; ps = ps->next)
+ /* FIXME: cmdline should be here instead of NULL */
+ if (ps_list_match (task_name, NULL, ps) == 1)
+ break;
+ }
/* Collect more detailed statistics for this process */
if (ps != NULL)
}
if (ps != NULL)
- ps_list_add (task_name, &pse);
+ /* FIXME: cmdline should be here instead of NULL */
+ ps_list_add (task_name, NULL, &pse);
} /* for (task_list) */
if ((status = vm_deallocate (port_task_self,
case 'W': paging++; break;
}
- ps_list_add (ps.name, &pse);
+ /* FIXME: cmdline should be here instead of NULL */
+ ps_list_add (ps.name, NULL, &pse);
}
closedir (proc);
for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
ps_submit_proc_list (ps_ptr);
-#endif /* KERNEL_LINUX */
+/* #endif KERNEL_LINUX */
+
+#elif HAVE_LIBKVM
+ int running = 0;
+ int sleeping = 0;
+ int zombies = 0;
+ int stopped = 0;
+ int blocked = 0;
+ int idle = 0;
+ int wait = 0;
+
+ kvm_t *kd;
+ char errbuf[1024];
+ char cmdline[ARG_MAX];
+ char *cmdline_ptr;
+ struct kinfo_proc *procs; /* array of processes */
+ char **argv;
+ int count; /* returns number of processes */
+ int i;
+
+ procstat_t *ps_ptr;
+ procstat_entry_t pse;
+
+ ps_list_reset ();
+
+ /* Open the kvm interface, get a descriptor */
+ kd = kvm_open (NULL, NULL, NULL, 0, errbuf);
+ if (kd == NULL)
+ {
+ ERROR ("processes plugin: Cannot open kvm interface: %s",
+ errbuf);
+ return (0);
+ }
+
+ /* Get the list of processes. */
+ procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, &count);
+ if (procs == NULL)
+ {
+ kvm_close (kd);
+ ERROR ("processes plugin: Cannot get kvm processes list: %s",
+ kvm_geterr(kd));
+ return (0);
+ }
+
+ /* Iterate through the processes in kinfo_proc */
+ for (i = 0; i < count; i++)
+ {
+ /* retrieve the arguments */
+ cmdline[0] = 0;
+ cmdline_ptr = NULL;
+
+ argv = kvm_getargv (kd, (const struct kinfo_proc *) &(procs[i]), 0);
+ if (argv != NULL)
+ {
+ int status;
+ int argc;
+
+ argc = 0;
+ while (argv[argc] != NULL)
+ argc++;
+
+ status = strjoin (cmdline, sizeof (cmdline),
+ argv, argc, " ");
+
+ if (status < 0)
+ {
+ WARNING ("processes plugin: Command line did "
+ "not fit into buffer.");
+ }
+ else
+ {
+ cmdline_ptr = &cmdline[0];
+ }
+ }
+
+ pse.id = procs[i].ki_pid;
+ pse.age = 0;
+
+ pse.num_proc = 1;
+ pse.num_lwp = procs[i].ki_numthreads;
+
+ pse.vmem_rss = procs[i].ki_rssize * getpagesize();
+ pse.vmem_minflt = 0;
+ pse.vmem_minflt_counter = procs[i].ki_rusage.ru_minflt;
+ pse.vmem_majflt = 0;
+ pse.vmem_majflt_counter = procs[i].ki_rusage.ru_majflt;
+
+ pse.cpu_user = 0;
+ pse.cpu_user_counter = procs[i].ki_rusage.ru_utime.tv_sec
+ * 1000
+ + procs[i].ki_rusage.ru_utime.tv_usec;
+ pse.cpu_system = 0;
+ pse.cpu_system_counter = procs[i].ki_rusage.ru_stime.tv_sec
+ * 1000
+ + procs[i].ki_rusage.ru_stime.tv_usec;
+
+ switch (procs[i].ki_stat)
+ {
+ case SSTOP: stopped++; break;
+ case SSLEEP: sleeping++; break;
+ case SRUN: running++; break;
+ case SIDL: idle++; break;
+ case SWAIT: wait++; break;
+ case SLOCK: blocked++; break;
+ case SZOMB: zombies++; break;
+ }
+
+ ps_list_add (procs[i].ki_comm, cmdline_ptr, &pse);
+ }
+
+ kvm_close(kd);
+
+ ps_submit_state ("running", running);
+ ps_submit_state ("sleeping", sleeping);
+ ps_submit_state ("zombies", zombies);
+ ps_submit_state ("stopped", stopped);
+ ps_submit_state ("blocked", blocked);
+ ps_submit_state ("idle", idle);
+ ps_submit_state ("wait", wait);
+
+ for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
+ ps_submit_proc_list (ps_ptr);
+#endif /* HAVE_LIBKVM */
return (0);
} /* int ps_read */
diff --git a/src/qmail.c b/src/qmail.c
--- /dev/null
+++ b/src/qmail.c
@@ -0,0 +1,263 @@
+/**
+ * collectd - src/qmail.c
+ * Copyright (C) 2008 Alessandro Iurlano
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Alessandro Iurlano <alessandro.iurlano at gmail.com>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+
+#define DEFAULT_BASE_DIR "/var/qmail"
+
+static char *qmail_base_dir;
+
+static const char *config_keys[] =
+{
+ "QmailDir"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static void qmail_submit (const char *plugin_instance, gauge_t value)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].gauge = value;
+
+ vl.values = values;
+ vl.values_len = STATIC_ARRAY_SIZE (values);
+ vl.time = time (NULL);
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.type, "gauge", sizeof (vl.type));
+ sstrncpy (vl.plugin, "qmail", sizeof (vl.plugin));
+ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+
+ plugin_dispatch_values (&vl);
+} /* void qmail_submit */
+
+static int count_files_in_subtree (const char *path, int depth)
+{
+#if NAME_MAX < 1024
+# define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + 1024 + 1)
+#else
+# define DIRENT_BUFFER_SIZE (sizeof (struct dirent) + NAME_MAX + 1)
+#endif
+
+ DIR *dh;
+ struct dirent *de;
+ char dirent_buffer[DIRENT_BUFFER_SIZE];
+ int status;
+
+ char **subdirs;
+ size_t subdirs_num;
+
+ int count;
+ int i;
+
+ dh = opendir (path);
+ if (dh == NULL)
+ {
+ ERROR ("qmail plugin: opendir (%s) failed.", path);
+ return (-1);
+ }
+
+ subdirs = NULL;
+ subdirs_num = 0;
+
+ count = 0;
+ while (42)
+ {
+ char abs_path[PATH_MAX];
+ struct stat statbuf;
+
+ de = NULL;
+ status = readdir_r (dh, (struct dirent *) dirent_buffer, &de);
+ if (status != 0)
+ {
+ char errbuf[4096];
+ ERROR ("qmail plugin: readdir_r failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ closedir (dh);
+ return (-1);
+ }
+ else if (de == NULL)
+ {
+ /* end of directory */
+ break;
+ }
+
+ if (de->d_name[0] == '.')
+ continue;
+
+ ssnprintf (abs_path, sizeof (abs_path), "%s/%s", path, de->d_name);
+
+ status = lstat (abs_path, &statbuf);
+ if (status != 0)
+ {
+ ERROR ("qmail plugin: stat (%s) failed.", abs_path);
+ continue;
+ }
+
+ if (S_ISREG (statbuf.st_mode))
+ {
+ count++;
+ }
+ else if (S_ISDIR (statbuf.st_mode))
+ {
+ char **temp;
+
+ temp = (char **) realloc (subdirs, sizeof (char *) * (subdirs_num + 1));
+ if (temp == NULL)
+ {
+ ERROR ("qmail plugin: realloc failed.");
+ continue;
+ }
+ subdirs = temp;
+
+ subdirs[subdirs_num] = strdup (abs_path);
+ if (subdirs[subdirs_num] == NULL)
+ {
+ ERROR ("qmail plugin: strdup failed.");
+ continue;
+ }
+ subdirs_num++;
+ }
+ }
+
+ closedir (dh);
+ dh = NULL;
+
+ if (depth > 0)
+ {
+ for (i = 0; i < subdirs_num; i++)
+ {
+ status = count_files_in_subtree (subdirs[i], depth - 1);
+ if (status > 0)
+ count += status;
+ }
+ }
+
+ for (i = 0; i < subdirs_num; i++)
+ {
+ sfree (subdirs[i]);
+ }
+ sfree (subdirs);
+
+ return (count);
+} /* int count_files_in_subtree */
+
+static int read_queue_length (const char *queue_name, const char *path)
+{
+ int64_t num_files;
+
+ num_files = count_files_in_subtree (path, /* depth = */ 1);
+ if (num_files < 0)
+ {
+ ERROR ("qmail plugin: Counting files in `%s' failed.", path);
+ return (-1);
+ }
+
+ qmail_submit (queue_name, (gauge_t) num_files);
+ return (0);
+} /* int read_queue_length */
+
+static int queue_len_read (void)
+{
+ char path[4096];
+ int success;
+ int status;
+
+ success = 0;
+
+ ssnprintf (path, sizeof (path), "%s/queue/mess",
+ (qmail_base_dir != NULL)
+ ? qmail_base_dir
+ : DEFAULT_BASE_DIR);
+
+ status = read_queue_length ("messages", path);
+ if (status == 0)
+ success++;
+
+ ssnprintf (path, sizeof (path), "%s/queue/todo",
+ (qmail_base_dir != NULL)
+ ? qmail_base_dir
+ : DEFAULT_BASE_DIR);
+
+ status = read_queue_length ("todo", path);
+ if (status == 0)
+ success++;
+
+ if (success > 0)
+ return 0;
+ return (-1);
+} /* int queue_len_read */
+
+static int qmail_config (const char *key, const char *val)
+{
+ if (strcasecmp ("QmailDir", key) == 0)
+ {
+ size_t qmail_base_dir_len;
+
+ sfree (qmail_base_dir);
+ qmail_base_dir = strdup(val);
+ if (qmail_base_dir == NULL)
+ {
+ ERROR ("qmail plugin: strdup failed.");
+ return (1);
+ }
+
+ qmail_base_dir_len = strlen (qmail_base_dir);
+ while ((qmail_base_dir_len > 0)
+ && (qmail_base_dir[qmail_base_dir_len - 1] == '/'))
+ {
+ qmail_base_dir[qmail_base_dir_len - 1] = 0;
+ qmail_base_dir_len--;
+ }
+
+ if (qmail_base_dir_len == 0)
+ {
+ ERROR ("qmail plugin: QmailDir is invalid.");
+ sfree (qmail_base_dir);
+ qmail_base_dir = NULL;
+ return (1);
+ }
+ }
+ else
+ {
+ return (-1);
+ }
+
+ return (0);
+} /* int qmail_config */
+
+void module_register (void)
+{
+ plugin_register_config ("qmail", qmail_config,
+ config_keys, config_keys_num);
+ plugin_register_read ("qmail", queue_len_read);
+} /* void module_register */
+
+/*
+ * vim: set sw=2 sts=2 et :
+ */
diff --git a/src/rrdtool.c b/src/rrdtool.c
index 3b2c54fc9265bb49c05618164af4dc7d8f8ce121..7cf243671254cf261b77fe3e79d21885f321384e 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
/**
* collectd - src/rrdtool.c
- * Copyright (C) 2006,2007 Florian octo Forster
+ * Copyright (C) 2006-2008 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
};
typedef struct rrd_cache_s rrd_cache_t;
+enum rrd_queue_dir_e
+{
+ QUEUE_INSERT_FRONT,
+ QUEUE_INSERT_BACK
+};
+typedef enum rrd_queue_dir_e rrd_queue_dir_t;
+
struct rrd_queue_s
{
char *filename;
if (rra_num >= rra_max)
break;
- if (snprintf (buffer, sizeof (buffer), "RRA:%s:%3.1f:%u:%u",
+ if (ssnprintf (buffer, sizeof (buffer), "RRA:%s:%3.1f:%u:%u",
rra_types[j], xff,
cdp_len, cdp_num) >= sizeof (buffer))
{
sstrncpy (min, "U", sizeof (min));
}
else
- {
- snprintf (min, sizeof (min), "%lf", d->min);
- min[sizeof (min) - 1] = '\0';
- }
+ ssnprintf (min, sizeof (min), "%lf", d->min);
if (isnan (d->max))
{
sstrncpy (max, "U", sizeof (max));
}
else
- {
- snprintf (max, sizeof (max), "%lf", d->max);
- max[sizeof (max) - 1] = '\0';
- }
+ ssnprintf (max, sizeof (max), "%lf", d->max);
- status = snprintf (buffer, sizeof (buffer),
+ status = ssnprintf (buffer, sizeof (buffer),
"DS:%s:%s:%i:%s:%s",
d->name, type,
(heartbeat > 0) ? heartbeat : (2 * vl->interval),
#if HAVE_THREADSAFE_LIBRRD
static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up,
- int argc, char **argv)
+ int argc, const char **argv)
{
int status;
return (status);
} /* int srrd_create */
-static int srrd_update (char *filename, char *template, int argc, char **argv)
+static int srrd_update (char *filename, char *template,
+ int argc, const char **argv)
{
int status;
#else /* !HAVE_THREADSAFE_LIBRRD */
static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up,
- int argc, char **argv)
+ int argc, const char **argv)
{
int status;
@@ -395,10 +397,8 @@ static int srrd_create (char *filename, unsigned long pdp_step, time_t last_up,
if (last_up == 0)
last_up = time (NULL) - 10;
- snprintf (pdp_step_str, sizeof (pdp_step_str), "%lu", pdp_step);
- pdp_step_str[sizeof (pdp_step_str) - 1] = '\0';
- snprintf (last_up_str, sizeof (last_up_str), "%u", (unsigned int) last_up);
- last_up_str[sizeof (last_up_str) - 1] = '\0';
+ ssnprintf (pdp_step_str, sizeof (pdp_step_str), "%lu", pdp_step);
+ ssnprintf (last_up_str, sizeof (last_up_str), "%u", (unsigned int) last_up);
new_argv[0] = "create";
new_argv[1] = filename;
return (status);
} /* int srrd_create */
-static int srrd_update (char *filename, char *template, int argc, char **argv)
+static int srrd_update (char *filename, char *template,
+ int argc, const char **argv)
{
int status;
@@ -513,7 +514,7 @@ static int rrd_create_file (char *filename, const data_set_t *ds, const value_li
status = srrd_create (filename,
(stepsize > 0) ? stepsize : vl->interval,
vl->time - 10,
- argc, argv);
+ argc, (const char **)argv);
free (argv);
ds_free (ds_num, ds_def);
memset (buffer, '\0', buffer_len);
- status = snprintf (buffer, buffer_len, "%u", (unsigned int) vl->time);
+ status = ssnprintf (buffer, buffer_len, "%u", (unsigned int) vl->time);
if ((status < 1) || (status >= buffer_len))
return (-1);
offset = status;
return (-1);
if (ds->ds[i].type == DS_TYPE_COUNTER)
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
":%llu", vl->values[i].counter);
else
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
":%lf", vl->values[i].gauge);
if ((status < 1) || (status >= (buffer_len - offset)))
if (datadir != NULL)
{
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
"%s/", datadir);
if ((status < 1) || (status >= buffer_len - offset))
return (-1);
offset += status;
}
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
"%s/", vl->host);
if ((status < 1) || (status >= buffer_len - offset))
return (-1);
offset += status;
if (strlen (vl->plugin_instance) > 0)
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
"%s-%s/", vl->plugin, vl->plugin_instance);
else
- status = snprintf (buffer + offset, buffer_len - offset,
+ status = ssnprintf (buffer + offset, buffer_len - offset,
"%s/", vl->plugin);
if ((status < 1) || (status >= buffer_len - offset))
return (-1);
offset += status;
if (strlen (vl->type_instance) > 0)
- status = snprintf (buffer + offset, buffer_len - offset,
- "%s-%s.rrd", ds->type, vl->type_instance);
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ "%s-%s.rrd", vl->type, vl->type_instance);
else
- status = snprintf (buffer + offset, buffer_len - offset,
- "%s.rrd", ds->type);
+ status = ssnprintf (buffer + offset, buffer_len - offset,
+ "%s.rrd", vl->type);
if ((status < 1) || (status >= buffer_len - offset))
return (-1);
offset += status;
pthread_mutex_unlock (&cache_lock);
/* Write the values to the RRD-file */
- srrd_update (queue_entry->filename, NULL, values_num, values);
+ srrd_update (queue_entry->filename, NULL,
+ values_num, (const char **)values);
DEBUG ("rrdtool plugin: queue thread: Wrote %i values to %s",
values_num, queue_entry->filename);
return ((void *) 0);
} /* void *rrd_queue_thread */
-static int rrd_queue_cache_entry (const char *filename)
+static int rrd_queue_cache_entry (const char *filename, rrd_queue_dir_t dir)
{
- rrd_queue_t *queue_entry;
-
- queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t));
- if (queue_entry == NULL)
- return (-1);
-
- queue_entry->filename = strdup (filename);
- if (queue_entry->filename == NULL)
- {
- free (queue_entry);
- return (-1);
- }
-
- queue_entry->next = NULL;
-
- pthread_mutex_lock (&queue_lock);
- if (queue_tail == NULL)
- queue_head = queue_entry;
- else
- queue_tail->next = queue_entry;
- queue_tail = queue_entry;
- pthread_cond_signal (&queue_cond);
- pthread_mutex_unlock (&queue_lock);
-
- DEBUG ("rrdtool plugin: Put `%s' into the update queue", filename);
-
- return (0);
+ rrd_queue_t *queue_entry;
+
+ queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t));
+ if (queue_entry == NULL)
+ return (-1);
+
+ queue_entry->filename = strdup (filename);
+ if (queue_entry->filename == NULL)
+ {
+ free (queue_entry);
+ return (-1);
+ }
+
+ queue_entry->next = NULL;
+
+ pthread_mutex_lock (&queue_lock);
+ if (dir == QUEUE_INSERT_FRONT)
+ {
+ queue_entry->next = queue_head;
+ queue_head = queue_entry;
+ if (queue_tail == NULL)
+ queue_tail = queue_head;
+ }
+ else /* (dir == QUEUE_INSERT_BACK) */
+ {
+ if (queue_tail == NULL)
+ queue_head = queue_entry;
+ else
+ queue_tail->next = queue_entry;
+ queue_tail = queue_entry;
+ }
+ pthread_cond_signal (&queue_cond);
+ pthread_mutex_unlock (&queue_lock);
+
+ DEBUG ("rrdtool plugin: Put `%s' into the update queue", filename);
+
+ return (0);
} /* int rrd_queue_cache_entry */
+static int rrd_queue_move_to_front (const char *filename)
+{
+ rrd_queue_t *this;
+ rrd_queue_t *prev;
+
+ this = NULL;
+ prev = NULL;
+ pthread_mutex_lock (&queue_lock);
+ for (this = queue_head; this != NULL; this = this->next)
+ {
+ if (strcmp (this->filename, filename) == 0)
+ break;
+ prev = this;
+ }
+
+ /* Check if we found the entry and if it is NOT the first entry. */
+ if ((this != NULL) && (prev != NULL))
+ {
+ prev->next = this->next;
+ this->next = queue_head;
+ queue_head = this;
+ }
+ pthread_mutex_unlock (&queue_lock);
+
+ return (0);
+} /* int rrd_queue_move_to_front */
+
static void rrd_cache_flush (int timeout)
{
rrd_cache_t *rc;
continue;
else if (rc->values_num > 0)
{
- if (rrd_queue_cache_entry (key) == 0)
+ if (rrd_queue_cache_entry (key, QUEUE_INSERT_BACK) == 0)
rc->flags = FLAG_QUEUED;
}
else /* ancient and no values -> waste of memory */
cache_flush_last = now;
} /* void rrd_cache_flush */
+static int rrd_cache_flush_identifier (int timeout, const char *identifier)
+{
+ rrd_cache_t *rc;
+ time_t now;
+ int status;
+ char key[2048];
+
+ if (identifier == NULL)
+ {
+ rrd_cache_flush (timeout);
+ return (0);
+ }
+
+ now = time (NULL);
+
+ if (datadir == NULL)
+ snprintf (key, sizeof (key), "%s.rrd",
+ identifier);
+ else
+ snprintf (key, sizeof (key), "%s/%s.rrd",
+ datadir, identifier);
+ key[sizeof (key) - 1] = 0;
+
+ status = c_avl_get (cache, key, (void *) &rc);
+ if (status != 0)
+ {
+ WARNING ("rrdtool plugin: rrd_cache_flush_identifier: "
+ "c_avl_get (%s) failed. Does that file really exist?",
+ key);
+ return (status);
+ }
+
+ if (rc->flags == FLAG_QUEUED)
+ status = rrd_queue_move_to_front (key);
+ else if ((now - rc->first_value) < timeout)
+ status = 0;
+ else if (rc->values_num > 0)
+ {
+ status = rrd_queue_cache_entry (key, QUEUE_INSERT_FRONT);
+ if (status == 0)
+ rc->flags = FLAG_QUEUED;
+ }
+
+ return (status);
+} /* int rrd_cache_flush_identifier */
+
static int rrd_cache_insert (const char *filename,
const char *value, time_t value_time)
{
}
DEBUG ("rrdtool plugin: rrd_cache_insert: file = %s; "
- "values_num = %i; age = %u;",
+ "values_num = %i; age = %lu;",
filename, rc->values_num,
- rc->last_value - rc->first_value);
+ (unsigned long)(rc->last_value - rc->first_value));
if ((rc->last_value - rc->first_value) >= cache_timeout)
{
* the same time, ALWAYS lock `cache_lock' first! */
if (rc->flags != FLAG_QUEUED)
{
- if (rrd_queue_cache_entry (filename) == 0)
+ if (rrd_queue_cache_entry (filename, QUEUE_INSERT_BACK) == 0)
rc->flags = FLAG_QUEUED;
}
else
char values[512];
int status;
+ if (0 != strcmp (ds->type, vl->type)) {
+ ERROR ("rrdtool plugin: DS type does not match value list type");
+ return -1;
+ }
+
if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0)
return (-1);
return (status);
} /* int rrd_write */
-static int rrd_flush (const int timeout)
+static int rrd_flush (int timeout, const char *identifier)
{
pthread_mutex_lock (&cache_lock);
return (0);
}
- rrd_cache_flush (timeout);
+ rrd_cache_flush_identifier (timeout, identifier);
+
pthread_mutex_unlock (&cache_lock);
return (0);
} /* int rrd_flush */
diff --git a/src/sensors.c b/src/sensors.c
index 0968e311fb170c63ba8c01727ed8ea7e423bf733..5ed82a8c64836cf08e881743343877f04391d575 100644 (file)
--- a/src/sensors.c
+++ b/src/sensors.c
if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA)
{
- status = snprintf (buf, buf_size,
+ status = ssnprintf (buf, buf_size,
"%s-isa-%04x",
chip->prefix,
chip->addr);
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
- status = snprintf (match_key, sizeof (match_key), "%s/%s-%s",
+ status = ssnprintf (match_key, sizeof (match_key), "%s/%s-%s",
plugin_instance, type, type_instance);
if (status < 1)
return;
- match_key[sizeof (match_key) - 1] = '\0';
if (sensor_list != NULL)
{
vl.values_len = 1;
vl.time = time (NULL);
- strncpy (vl.host, hostname_g, sizeof (vl.host));
- vl.host[sizeof (vl.host) - 1] = '\0';
- strncpy (vl.plugin, "sensors", sizeof (vl.plugin));
- vl.plugin[sizeof (vl.plugin) - 1] = '\0';
- strncpy (vl.plugin_instance, plugin_instance,
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "sensors", sizeof (vl.plugin));
+ sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
- vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0';
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void sensors_submit */
static int sensors_read (void)
sizeof (plugin_instance), fl->chip);
if (status < 0)
continue;
- plugin_instance[sizeof (plugin_instance) - 1] = '\0';
- strncpy (type_instance, fl->data->name,
+ sstrncpy (type_instance, fl->data->name,
sizeof (type_instance));
- type_instance[sizeof (type_instance) - 1] = '\0';
sensors_submit (plugin_instance,
sensor_type_name_map[fl->type],
sizeof (plugin_instance), fl->chip);
if (status < 0)
continue;
- plugin_instance[sizeof (plugin_instance) - 1] = '\0';
- strncpy (type_instance, fl->feature->name,
+ sstrncpy (type_instance, fl->feature->name,
sizeof (type_instance));
- type_instance[sizeof (type_instance) - 1] = '\0';
if (fl->feature->type == SENSORS_FEATURE_IN)
type = "voltage";
diff --git a/src/serial.c b/src/serial.c
index 4f08a346eb542fee24e84d3f4918fcc73552a4fb..1c874e52177e919d59056126015da12edf760109 100644 (file)
--- a/src/serial.c
+++ b/src/serial.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "serial", sizeof (vl.plugin));
- strncpy (vl.type_instance, type_instance,
+ sstrncpy (vl.type, "serial_octets", sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
- plugin_dispatch_values ("serial_octets", &vl);
+ plugin_dispatch_values (&vl);
}
static int serial_read (void)
diff --git a/src/snmp.c b/src/snmp.c
index 460624b4e4a2f8bd9be1b7ca22a6dfa2ec15b192..07465ddd26d1a951addd40b0ea28f9a7cad6b409 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
@@ -198,7 +198,8 @@ static int csnmp_config_add_data_instance (data_definition_t *dd, oconfig_item_t
else
{
/* Instance is a simple string */
- strncpy (dd->instance.string, ci->values[0].value.string, DATA_MAX_NAME_LEN - 1);
+ sstrncpy (dd->instance.string, ci->values[0].value.string,
+ sizeof (dd->instance.string));
}
return (0);
temp += (uint32_t) vl->val.counter64->low;
DEBUG ("snmp plugin: Parsed int64 value is %"PRIu64".", temp);
}
+ else if (vl->type == ASN_OCTET_STR)
+ {
+ /* We'll handle this later.. */
+ }
else
{
WARNING ("snmp plugin: I don't know the ASN type `%i'", (int) vl->type);
defined = 0;
}
- if (type == DS_TYPE_COUNTER)
+ if (vl->type == ASN_OCTET_STR)
+ {
+ char *string;
+ char *endptr;
+
+ string = (char *) vl->val.string;
+ endptr = NULL;
+
+ if (string != NULL)
+ {
+ if (type == DS_TYPE_COUNTER)
+ ret.counter = (counter_t) strtoll (string, &endptr, /* base = */ 0);
+ else if (type == DS_TYPE_GAUGE)
+ ret.gauge = (gauge_t) strtod (string, &endptr);
+ }
+
+ /* Check if an error occurred */
+ if ((string == NULL) || (endptr == string))
+ {
+ if (type == DS_TYPE_COUNTER)
+ ret.counter = 0;
+ else if (type == DS_TYPE_GAUGE)
+ ret.gauge = NAN;
+ }
+ }
+ else if (type == DS_TYPE_COUNTER)
{
ret.counter = temp;
}
if (instance_len > vb->val_len)
instance_len = vb->val_len;
- strncpy (il->instance, (char *) ((vb->type == ASN_OCTET_STR)
+ sstrncpy (il->instance, (char *) ((vb->type == ASN_OCTET_STR)
? vb->val.string
: vb->val.bitstring),
instance_len);
- il->instance[instance_len] = '\0';
for (ptr = il->instance; *ptr != '\0'; ptr++)
{
else
{
value_t val = csnmp_value_list_to_value (vb, DS_TYPE_COUNTER, 1.0, 0.0);
- snprintf (il->instance, sizeof (il->instance),
+ ssnprintf (il->instance, sizeof (il->instance),
"%llu", val.counter);
}
- il->instance[sizeof (il->instance) - 1] = '\0';
/* TODO: Debugging output */
@@ -907,8 +935,7 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat
return (-1);
}
- strncpy (vl.host, host->name, sizeof (vl.host));
- vl.host[sizeof (vl.host) - 1] = '\0';
+ sstrncpy (vl.host, host->name, sizeof (vl.host));
sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin));
vl.interval = host->interval;
@@ -972,30 +999,28 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat
|| (instance_list_ptr->subid == value_table_ptr[0]->subid));
#endif
+ sstrncpy (vl.type, data->type, sizeof (vl.type));
+
{
char temp[DATA_MAX_NAME_LEN];
if (instance_list_ptr == NULL)
- snprintf (temp, sizeof (temp), "%u",
- (uint32_t) subid);
+ ssnprintf (temp, sizeof (temp), "%u", (uint32_t) subid);
else
- strncpy (temp, instance_list_ptr->instance,
- sizeof (temp));
- temp[sizeof (temp) - 1] = '\0';
+ sstrncpy (temp, instance_list_ptr->instance, sizeof (temp));
if (data->instance_prefix == NULL)
- strncpy (vl.type_instance, temp, sizeof (vl.type_instance));
+ sstrncpy (vl.type_instance, temp, sizeof (vl.type_instance));
else
- snprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s",
+ ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s",
data->instance_prefix, temp);
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
}
for (i = 0; i < data->values_len; i++)
vl.values[i] = value_table_ptr[i]->value;
/* If we get here `vl.type_instance' and all `vl.values' have been set */
- plugin_dispatch_values (data->type, &vl);
+ plugin_dispatch_values (&vl);
subid++;
} /* while (have_more != 0) */
@@ -1299,11 +1324,10 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
vl.values[i].gauge = NAN;
}
- strncpy (vl.host, host->name, sizeof (vl.host));
- vl.host[sizeof (vl.host) - 1] = '\0';
+ sstrncpy (vl.host, host->name, sizeof (vl.host));
sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin));
- strncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ sstrncpy (vl.type, data->type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance));
vl.interval = host->interval;
@@ -1361,8 +1385,8 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
snmp_free_pdu (res);
res = NULL;
- DEBUG ("snmp plugin: -> plugin_dispatch_values (%s, &vl);", data->type);
- plugin_dispatch_values (data->type, &vl);
+ DEBUG ("snmp plugin: -> plugin_dispatch_values (&vl);");
+ plugin_dispatch_values (&vl);
sfree (vl.values);
return (0);
diff --git a/src/swap.c b/src/swap.c
index 4d1f24de73ae40bf79a07621e6bfb945521669a3..f9debc1b595a4e405bc3b11fad25716b2db2245c 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "swap", sizeof (vl.plugin));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type, "swap", sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values ("swap", &vl);
+ plugin_dispatch_values (&vl);
} /* void swap_submit */
static int swap_read (void)
diff --git a/src/tape.c b/src/tape.c
index 5b5cdb4641d9d176599e689c195d8d36d923b113..caca537b0038be024f2771d979f3eeeb289ce53d 100644 (file)
--- a/src/tape.c
+++ b/src/tape.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "tape", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, plugin_instance,
+ sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void tape_submit */
static int tape_read (void)
diff --git a/src/tcpconns.c b/src/tcpconns.c
index 5a8f461971a8909391a99d36bb89eacf57d71252..655c53e5689ff35647216d50b2a4b01e4bbb1cf2 100644 (file)
--- a/src/tcpconns.c
+++ b/src/tcpconns.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "tcpconns", sizeof (vl.plugin));
+ sstrncpy (vl.type, "tcp_connections", sizeof (vl.type));
if (((port_collect_listening != 0) && (pe->flags & PORT_IS_LISTENING))
|| (pe->flags & PORT_COLLECT_LOCAL))
{
- snprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
+ ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
"%hu-local", pe->port);
- vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0';
for (i = 1; i <= TCP_STATE_MAX; i++)
{
vl.values[0].gauge = pe->count_local[i];
- strncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ sstrncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance));
- plugin_dispatch_values ("tcp_connections", &vl);
+ plugin_dispatch_values (&vl);
}
}
if (pe->flags & PORT_COLLECT_REMOTE)
{
- snprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
+ ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
"%hu-remote", pe->port);
- vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0';
for (i = 1; i <= TCP_STATE_MAX; i++)
{
vl.values[0].gauge = pe->count_remote[i];
- strncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
+ sstrncpy (vl.type_instance, tcp_state[i], sizeof (vl.type_instance));
- plugin_dispatch_values ("tcp_connections", &vl);
+ plugin_dispatch_values (&vl);
}
}
} /* void conn_submit */
diff --git a/src/teamspeak2.c b/src/teamspeak2.c
index 52a1007ed4fcddd300955d3dbd55c40268830e53..5cd427afc2bb5ccb0c173d8791401e51fe682707 100644 (file)
--- a/src/teamspeak2.c
+++ b/src/teamspeak2.c
if (plugin_instance != NULL)
sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
-
+
+ sstrncpy (vl.type, type, sizeof (vl.type));
+
if (type_instance != NULL)
sstrncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void tss2_submit_gauge */
static void tss2_submit_io (const char *plugin_instance, const char *type,
if (plugin_instance != NULL)
sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
-
- plugin_dispatch_values (type, &vl);
+
+ sstrncpy (vl.type, type, sizeof (vl.type));
+
+ plugin_dispatch_values (&vl);
} /* void tss2_submit_gauge */
static void tss2_close_socket (void)
@@ -372,8 +376,7 @@ static int tss2_select_vserver (FILE *read_fh, FILE *write_fh, vserver_list_t *v
int status;
/* Send request */
- snprintf (command, sizeof (command), "sel %i\r\n", vserver->port);
- command[sizeof (command) - 1] = 0;
+ ssnprintf (command, sizeof (command), "sel %i\r\n", vserver->port);
status = tss2_send_request (write_fh, command);
if (status != 0)
else
{
/* Request server information */
- snprintf (plugin_instance, sizeof (plugin_instance), "vserver%i",
+ ssnprintf (plugin_instance, sizeof (plugin_instance), "vserver%i",
vserver->port);
- plugin_instance[sizeof (plugin_instance) - 1] = 0;
/* Select the server */
status = tss2_select_vserver (read_fh, write_fh, vserver);
diff --git a/src/thermal.c b/src/thermal.c
--- /dev/null
+++ b/src/thermal.c
@@ -0,0 +1,268 @@
+/**
+ * collectd - src/thermal.c
+ * Copyright (C) 2008 Michał Mirosław
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Michał Mirosław <mirq-linux at rere.qmqm.pl>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+#include "utils_ignorelist.h"
+
+#if !KERNEL_LINUX
+# error "This module is for Linux only."
+#endif
+
+const char *const dirname_sysfs = "/sys/class/thermal";
+const char *const dirname_procfs = "/proc/acpi/thermal_zone";
+
+static char force_procfs = 0;
+static ignorelist_t *device_list;
+static value_list_t vl_temp_template = VALUE_LIST_STATIC;
+static value_list_t vl_state_template = VALUE_LIST_STATIC;
+
+enum dev_type {
+ TEMP = 0,
+ COOLING_DEV
+};
+
+static void thermal_submit (const char *plugin_instance, enum dev_type dt,
+ gauge_t value)
+{
+ value_list_t vl = (dt == TEMP) ? vl_temp_template : vl_state_template;
+ value_t vt;
+
+ vt.gauge = value;
+
+ vl.values = &vt;
+ vl.time = time (NULL);
+ sstrncpy (vl.plugin, "thermal", sizeof(vl.plugin));
+ sstrncpy (vl.plugin_instance, plugin_instance,
+ sizeof(vl.plugin_instance));
+ sstrncpy (vl.type, (dt == TEMP) ? "temperature" : "gauge",
+ sizeof (vl.type));
+
+ plugin_dispatch_values (&vl);
+}
+
+static int thermal_sysfs_device_read (const char *name)
+{
+ char filename[256];
+ char data[1024];
+ int len;
+ int ok = 0;
+
+ if (device_list && ignorelist_match (device_list, name))
+ return -1;
+
+ len = snprintf (filename, sizeof (filename), "%s/%s/temp", dirname_sysfs, name);
+ if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
+ return -1;
+
+ len = read_file_contents (filename, data, sizeof(data));
+ if (len > 1 && data[--len] == '\n') {
+ char *endptr = NULL;
+ double temp;
+
+ data[len] = 0;
+ errno = 0;
+ temp = strtod (data, &endptr) / 1000.0;
+
+ if (endptr == data + len && errno == 0) {
+ thermal_submit(name, TEMP, temp);
+ ++ok;
+ }
+ }
+
+ len = snprintf (filename, sizeof (filename), "%s/%s/cur_state", dirname_sysfs, name);
+ if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
+ return -1;
+
+ len = read_file_contents (filename, data, sizeof(data));
+ if (len > 1 && data[--len] == '\n') {
+ char *endptr = NULL;
+ double state;
+
+ data[len] = 0;
+ errno = 0;
+ state = strtod (data, &endptr);
+
+ if (endptr == data + len && errno == 0) {
+ thermal_submit(name, COOLING_DEV, state);
+ ++ok;
+ }
+ }
+
+ return ok ? 0 : -1;
+}
+
+static int thermal_procfs_device_read (const char *name)
+{
+ const char str_temp[] = "temperature:";
+ char filename[256];
+ char data[1024];
+ int len;
+
+ if (device_list && ignorelist_match (device_list, name))
+ return -1;
+
+ /**
+ * rechot ~ # cat /proc/acpi/thermal_zone/THRM/temperature
+ * temperature: 55 C
+ */
+
+ len = snprintf (filename, sizeof (filename), "%s/%s/temperature", dirname_procfs, name);
+ if ((len < 0) || ((unsigned int)len >= sizeof (filename)))
+ return -1;
+
+ len = read_file_contents (filename, data, sizeof(data));
+ if (len > sizeof(str_temp) && data[--len] == '\n' && !strncmp(data, str_temp, sizeof(str_temp)-1)) {
+ char *endptr = NULL;
+ double temp;
+ double celsius, add;
+
+ if (data[--len] == 'C') {
+ add = 0;
+ celsius = 1;
+ } else if (data[len] == 'F') {
+ add = -32;
+ celsius = 5/9;
+ } else if (data[len] == 'K') {
+ add = -273.15;
+ celsius = 1;
+ } else
+ return -1;
+
+ while (len > 0 && data[--len] == ' ')
+ ;
+ data[len + 1] = 0;
+
+ while (len > 0 && data[--len] != ' ')
+ ;
+ ++len;
+
+ errno = 0;
+ temp = (strtod (data + len, &endptr) + add) * celsius;
+
+ if (endptr != data + len && errno == 0) {
+ thermal_submit(name, TEMP, temp);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+static const char *config_keys[] = {
+ "Device",
+ "IgnoreSelected",
+ "ForceUseProcfs"
+};
+
+static int thermal_config (const char *key, const char *value)
+{
+ if (device_list == NULL)
+ device_list = ignorelist_create (1);
+
+ if (strcasecmp (key, "Device") == 0)
+ {
+ if (ignorelist_add (device_list, value))
+ {
+ ERROR ("thermal plugin: "
+ "Cannot add value to ignorelist.");
+ return 1;
+ }
+ }
+ else if (strcasecmp (key, "IgnoreSelected") == 0)
+ {
+ ignorelist_set_invert (device_list, 1);
+ if ((strcasecmp (value, "True") == 0)
+ || (strcasecmp (value, "Yes") == 0)
+ || (strcasecmp (value, "On") == 0))
+ ignorelist_set_invert (device_list, 0);
+ }
+ else if (strcasecmp (key, "ForceUseProcfs") == 0)
+ {
+ force_procfs = 0;
+ if ((strcasecmp (value, "True") == 0)
+ || (strcasecmp (value, "Yes") == 0)
+ || (strcasecmp (value, "On") == 0))
+ force_procfs = 1;
+ }
+ else
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+static int thermal_sysfs_read (void)
+{
+ return walk_directory (dirname_sysfs, thermal_sysfs_device_read);
+}
+
+static int thermal_procfs_read (void)
+{
+ return walk_directory (dirname_procfs, thermal_procfs_device_read);
+}
+
+static int thermal_init (void)
+{
+ int ret = -1;
+
+ if (!force_procfs && access (dirname_sysfs, R_OK | X_OK) == 0) {
+ ret = plugin_register_read ("thermal", thermal_sysfs_read);
+ } else if (access (dirname_procfs, R_OK | X_OK) == 0) {
+ ret = plugin_register_read ("thermal", thermal_procfs_read);
+ }
+
+ if (!ret) {
+ vl_temp_template.values_len = 1;
+ vl_temp_template.interval = interval_g;
+ sstrncpy (vl_temp_template.host, hostname_g,
+ sizeof(vl_temp_template.host));
+ sstrncpy (vl_temp_template.plugin, "thermal",
+ sizeof(vl_temp_template.plugin));
+ sstrncpy (vl_temp_template.type_instance, "temperature",
+ sizeof(vl_temp_template.type_instance));
+
+ vl_state_template = vl_temp_template;
+ sstrncpy (vl_state_template.type_instance, "cooling_state",
+ sizeof(vl_state_template.type_instance));
+ }
+
+ return ret;
+}
+
+static int thermal_shutdown (void)
+{
+ ignorelist_free (device_list);
+
+ return 0;
+}
+
+void module_register (void)
+{
+ plugin_register_config ("thermal", thermal_config,
+ config_keys, STATIC_ARRAY_SIZE(config_keys));
+ plugin_register_init ("thermal", thermal_init);
+ plugin_register_shutdown ("thermal", thermal_shutdown);
+}
+
diff --git a/src/types.db b/src/types.db
index 97c170b7dd90fef053ad105d1b82f866a56e3376..fabae12471cd6448d36ed83b19951e3e6a9e1cd3 100644 (file)
--- a/src/types.db
+++ b/src/types.db
apache_scoreboard count:GAUGE:0:65535
bitrate value:GAUGE:0:4294967295
cache_result value:COUNTER:0:4294967295
-cache_size value:GAUGE:0:4294967295
+cache_size value:GAUGE:0:4294967295
charge value:GAUGE:0:U
connections value:COUNTER:0:U
counter value:COUNTER:U:U
nginx_connections value:GAUGE:0:U
nginx_requests value:COUNTER:0:134217728
percent percent:GAUGE:0:100.1
+pg_blks value:COUNTER:0:U
+pg_n_tup_c value:COUNTER:0:U
+pg_n_tup_g value:GAUGE:0:U
+pg_numbackends value:GAUGE:0:U
+pg_scan value:COUNTER:0:U
+pg_xact value:COUNTER:0:U
ping ping:GAUGE:0:65535
players value:GAUGE:0:1000000
power value:GAUGE:0:U
diff --git a/src/types_list.c b/src/types_list.c
index 3be792d5ca11bbd741f9b599a517c9cfea7da9ac..7600c346ecc1e8c901460a029c2ead4c167e5576 100644 (file)
--- a/src/types_list.c
+++ b/src/types_list.c
if (buf_len < 11)
{
- ERROR ("parse_ds: (buf_len = %u) < 11", buf_len);
+ ERROR ("parse_ds: (buf_len = %zu) < 11", buf_len);
return (-1);
}
return (-1);
}
- strncpy (dsrc->name, fields[0], sizeof (dsrc->name));
- dsrc->name[sizeof (dsrc->name) - 1] = '\0';
+ sstrncpy (dsrc->name, fields[0], sizeof (dsrc->name));
if (strcasecmp (fields[1], "GAUGE") == 0)
dsrc->type = DS_TYPE_GAUGE;
memset (ds, '\0', sizeof (data_set_t));
- strncpy (ds->type, fields[0], sizeof (ds->type));
- ds->type[sizeof (ds->type) - 1] = '\0';
+ sstrncpy (ds->type, fields[0], sizeof (ds->type));
ds->ds_num = fields_num - 1;
ds->ds = (data_source_t *) calloc (ds->ds_num, sizeof (data_source_t));
diff --git a/src/unixsock.c b/src/unixsock.c
index d80091b1bd18bfffd290ae4c7a54b6086131605f..d34b91fae204d9ac43e885c5895db4c37448005e 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
memset (&sa, '\0', sizeof (sa));
sa.sun_family = AF_UNIX;
- strncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
- sizeof (sa.sun_path) - 1);
+ sstrncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
+ sizeof (sa.sun_path));
/* unlink (sa.sun_path); */
DEBUG ("unixsock plugin: socket path = %s", sa.sun_path);
diff --git a/src/users.c b/src/users.c
index d0bd63cdb540ef2bc8d5e145e386f2590e604ef7..1231075a324803bd3fa866396c62563763496e67 100644 (file)
--- a/src/users.c
+++ b/src/users.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "users", sizeof (vl.plugin));
+ sstrncpy (vl.type, "users", sizeof (vl.plugin));
- plugin_dispatch_values ("users", &vl);
+ plugin_dispatch_values (&vl);
} /* void users_submit */
static int users_read (void)
diff --git a/src/utils_cache.c b/src/utils_cache.c
index 9f7e3b686e52083f37871afc4f69391d1dd191bc..d0e77ef351b840a79fcd91123264c3b43670dbb2 100644 (file)
--- a/src/utils_cache.c
+++ b/src/utils_cache.c
return (-1);
}
- snprintf (n.message, sizeof (n.message),
+ ssnprintf (n.message, sizeof (n.message),
"%s has not been updated for %i seconds.", name,
(int) (n.time - ce->last_update));
pthread_mutex_unlock (&cache_lock);
- n.message[sizeof (n.message) - 1] = '\0';
plugin_dispatch_notification (&n);
return (0);
}
else
{
- WARNING ("uc_check_timeout: ut_check_interesting (%s) returned ",
+ WARNING ("uc_check_timeout: ut_check_interesting (%s) returned "
"invalid status %i.",
keys[i], status);
}
n.severity = NOTIF_OKAY;
n.time = vl->time;
- snprintf (n.message, sizeof (n.message),
+ ssnprintf (n.message, sizeof (n.message),
"Received a value for %s. It was missing for %u seconds.",
name, (unsigned int) update_delay);
- n.message[sizeof (n.message) - 1] = '\0';
plugin_dispatch_notification (&n);
if (ret_num != ds->ds_num)
{
ERROR ("utils_cache: uc_get_rate: ds[%s] has %i values, "
- "but uc_get_rate_by_name returned %i.",
+ "but uc_get_rate_by_name returned %zu.",
ds->type, ds->ds_num, ret_num);
sfree (ret);
return (NULL);
diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c
index 6fa8b7bf00b5d0b68979b4e828e1f7093e32f5dc..7feaac28c556b6a74b10af845082c7342926722f 100644 (file)
--- a/src/utils_cmd_flush.c
+++ b/src/utils_cmd_flush.c
return -1; \
}
+static int add_to_array (char ***array, int *array_num, char *value)
+{
+ char **temp;
+
+ temp = (char **) realloc (*array, sizeof (char *) * (*array_num + 1));
+ if (temp == NULL)
+ return (-1);
+
+ *array = temp;
+ (*array)[*array_num] = value;
+ (*array_num)++;
+
+ return (0);
+} /* int add_to_array */
+
int handle_flush (FILE *fh, char **fields, int fields_num)
{
int success = 0;
int error = 0;
int timeout = -1;
+ char **plugins = NULL;
+ int plugins_num = 0;
+ char **identifiers = NULL;
+ int identifiers_num = 0;
int i;
if (strncasecmp ("plugin=", option, strlen ("plugin=")) == 0)
{
- char *plugin = option + strlen ("plugin=");
+ char *plugin;
+
+ plugin = option + strlen ("plugin=");
+ add_to_array (&plugins, &plugins_num, plugin);
+ }
+ else if (strncasecmp ("identifier=", option, strlen ("identifier=")) == 0)
+ {
+ char *identifier;
- if (0 == plugin_flush_one (timeout, plugin))
- ++success;
- else
- ++error;
+ identifier = option + strlen ("identifier=");
+ add_to_array (&identifiers, &identifiers_num, identifier);
}
else if (strncasecmp ("timeout=", option, strlen ("timeout=")) == 0)
{
}
}
+ /* Add NULL entries for `any plugin' and/or `any value' if nothing was
+ * specified. */
+ if (plugins_num == 0)
+ add_to_array (&plugins, &plugins_num, NULL);
+
+ if (identifiers_num == 0)
+ add_to_array (&identifiers, &identifiers_num, NULL);
+
+ for (i = 0; i < plugins_num; i++)
+ {
+ char *plugin;
+ int j;
+
+ plugin = plugins[i];
+
+ for (j = 0; j < identifiers_num; j++)
+ {
+ char *identifier;
+ int status;
+
+ identifier = identifiers[j];
+ status = plugin_flush (plugin, timeout, identifier);
+ if (status == 0)
+ success++;
+ else
+ error++;
+ }
+ }
+
if ((success + error) > 0)
{
print_to_socket (fh, "0 Done: %i successful, %i errors\n",
diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c
index 16a09b1b71093c7eb5752e4c28772fc34800a667..9cbba126f48496c5750d623dc6cd5fe8fd0cdccf 100644 (file)
--- a/src/utils_cmd_putval.c
+++ b/src/utils_cmd_putval.c
}
static int parse_value (const data_set_t *ds, value_list_t *vl,
- const char *type,
FILE *fh, char *buffer)
{
char *dummy;
return (-1);
}
- plugin_dispatch_values (type, vl);
+ plugin_dispatch_values (vl);
return (0);
} /* int parse_value */
sstrncpy (vl.host, hostname, sizeof (vl.host));
sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (plugin_instance != NULL)
sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
if (type_instance != NULL)
/* It's parse_value's job to write an error to `fh'.
* This is not the case with `parse_option below.
* Neither will write an success message. */
- if (parse_value (ds, &vl, type, fh, fields[i]) != 0)
+ if (parse_value (ds, &vl, fh, fields[i]) != 0)
break;
}
else if (strchr (fields[i], '=') != NULL)
diff --git a/src/utils_complain.c b/src/utils_complain.c
--- /dev/null
+++ b/src/utils_complain.c
@@ -0,0 +1,101 @@
+/**
+ * collectd - src/utils_complain.c
+ * Copyright (C) 2006-2007 Florian octo Forster
+ * Copyright (C) 2008 Sebastian tokkee Harl
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <octo at verplant.org>
+ * Sebastian tokkee Harl <sh at tokkee.org>
+ **/
+
+#include "utils_complain.h"
+#include "plugin.h"
+
+/* vcomplain returns 0 if it did not report, 1 else */
+static int vcomplain (int level, c_complain_t *c,
+ const char *format, va_list ap)
+{
+ time_t now;
+ char message[512];
+
+ now = time (NULL);
+
+ if (c->last + c->interval > now)
+ return 0;
+
+ c->last = now;
+
+ if (c->interval < interval_g)
+ c->interval = interval_g;
+ else
+ c->interval *= 2;
+
+ if (c->interval > 86400)
+ c->interval = 86400;
+
+ vsnprintf (message, sizeof (message), format, ap);
+ message[sizeof (message) - 1] = '\0';
+
+ plugin_log (level, message);
+ return 1;
+} /* vcomplain */
+
+void c_complain (int level, c_complain_t *c, const char *format, ...)
+{
+ va_list ap;
+
+ /* reset the old interval */
+ if (c->interval < 0)
+ c->interval *= -1;
+
+ va_start (ap, format);
+ vcomplain (level, c, format, ap);
+ va_end (ap);
+} /* c_complain */
+
+void c_complain_once (int level, c_complain_t *c, const char *format, ...)
+{
+ va_list ap;
+
+ if (c->interval < 0)
+ return;
+
+ va_start (ap, format);
+ if (vcomplain (level, c, format, ap))
+ c->interval *= -1;
+ va_end (ap);
+} /* c_complain_once */
+
+void c_do_release (int level, c_complain_t *c, const char *format, ...)
+{
+ char message[512];
+ va_list ap;
+
+ if (c->interval == 0)
+ return;
+
+ c->interval = 0;
+
+ va_start (ap, format);
+ vsnprintf (message, sizeof (message), format, ap);
+ message[sizeof (message) - 1] = '\0';
+ va_end (ap);
+
+ plugin_log (level, message);
+} /* c_release */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/utils_complain.h b/src/utils_complain.h
--- /dev/null
+++ b/src/utils_complain.h
@@ -0,0 +1,96 @@
+/**
+ * collectd - src/utils_complain.h
+ * Copyright (C) 2006-2007 Florian octo Forster
+ * Copyright (C) 2008 Sebastian tokkee Harl
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; only version 2 of the License is applicable.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <octo at verplant.org>
+ * Sebastian tokkee Harl <sh at tokkee.org>
+ **/
+
+#ifndef UTILS_COMPLAIN_H
+#define UTILS_COMPLAIN_H 1
+
+#include <time.h>
+
+typedef struct
+{
+ /* time of the last report */
+ time_t last;
+
+ /* how long to wait until reporting again
+ * 0 indicates that the complaint is no longer valid
+ * < 0 indicates that the complaint has been reported once
+ * => c_complain_once will not report again
+ * => c_complain uses the absolute value to reset the old value */
+ int interval;
+} c_complain_t;
+
+#define C_COMPLAIN_INIT { 0, 0 }
+
+/*
+ * NAME
+ * c_complain
+ *
+ * DESCRIPTION
+ * Complain about something. This function will report a message (usually
+ * indicating some error condition) using the collectd logging mechanism.
+ * When this function is called again, reporting the message again will be
+ * deferred by an increasing interval (up to one day) to prevent flooding
+ * the logs. A call to `c_release' resets the counter.
+ *
+ * PARAMETERS
+ * `level' The log level passed to `plugin_log'.
+ * `c' Identifier for the complaint.
+ * `format' Message format - see the documentation of printf(3).
+ */
+void c_complain (int level, c_complain_t *c, const char *format, ...);
+
+/*
+ * NAME
+ * c_complain_once
+ *
+ * DESCRIPTION
+ * Complain about something once. This function will not report anything
+ * again, unless `c_release' has been called in between. If used after some
+ * calls to `c_complain', it will report again on the next interval and stop
+ * after that.
+ *
+ * See `c_complain' for further details and a description of the parameters.
+ */
+void c_complain_once (int level, c_complain_t *c, const char *format, ...);
+
+/*
+ * NAME
+ * c_release
+ *
+ * DESCRIPTION
+ * Release a complaint. This will report a message once, marking the
+ * complaint as released.
+ *
+ * See `c_complain' for a description of the parameters.
+ */
+void c_do_release (int level, c_complain_t *c, const char *format, ...);
+#define c_release(level, c, ...) \
+ do { \
+ if ((c)->interval != 0) \
+ c_do_release(level, c, __VA_ARGS__); \
+ } while (0)
+
+#endif /* UTILS_COMPLAIN_H */
+
+/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
+
diff --git a/src/utils_dns.c b/src/utils_dns.c
index 9b001517c80945f1d5e5e4d643c867f31a07ab54..f2ab3377ed43bf60dc40584e7dfbe3773cfdca9a 100644 (file)
--- a/src/utils_dns.c
+++ b/src/utils_dns.c
*/
#include "collectd.h"
+#include "common.h"
#if HAVE_NETINET_IN_SYSTM_H
# include <netinet/in_systm.h>
if (0 != x)
return 0;
if ('\0' == qh.qname[0])
- strncpy (qh.qname, ".", sizeof (qh.qname));
+ sstrncpy (qh.qname, ".", sizeof (qh.qname));
while ((t = strchr(qh.qname, '\n')))
*t = ' ';
while ((t = strchr(qh.qname, '\r')))
case T_ANY: return ("ANY"); /* ... 255 */
#endif /* __BIND >= 19950621 */
default:
- snprintf (buf, 32, "#%i", t);
- buf[31] = '\0';
+ ssnprintf (buf, sizeof (buf), "#%i", t);
return (buf);
}; /* switch (t) */
/* NOTREACHED */
return "Update";
break;
default:
- snprintf(buf, 30, "Opcode%d", o);
+ ssnprintf(buf, sizeof (buf), "Opcode%d", o);
return buf;
}
/* NOTREACHED */
#endif /* RFC2136 rcodes */
#endif /* __BIND >= 19950621 */
default:
- snprintf (buf, 32, "RCode%i", rcode);
- buf[31] = '\0';
+ ssnprintf (buf, sizeof (buf), "RCode%i", rcode);
return (buf);
}
/* Never reached */
diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c
index 1d9467fe210d89e6ce0f9c6537e3be9e389d6e8e..518715b1f48ada50c018e38f600dd6c14bcbd66f 100644 (file)
--- a/src/utils_ignorelist.c
+++ b/src/utils_ignorelist.c
/* We need to copy `entry' since it's const */
entry_copy = smalloc (entry_len);
memset (entry_copy, '\0', entry_len);
- strncpy (entry_copy, entry + 1, entry_len - 2);
+ sstrncpy (entry_copy, entry + 1, entry_len - 2);
DEBUG("I'm about to add regex entry: %s", entry_copy);
ret = ignorelist_append_regex(il, entry_copy);
diff --git a/src/utils_mount.c b/src/utils_mount.c
index 44ad7ea8642f98a222140ce9ced1babd7afdb39d..c53431f1a6458e8902b25ff2537f545e536b6269 100644 (file)
--- a/src/utils_mount.c
+++ b/src/utils_mount.c
* (This is useful, if the cdrom on /dev/hdc must not
* be accessed.)
*/
- snprintf(device, sizeof(device), "%s/%s",
+ ssnprintf(device, sizeof(device), "%s/%s",
DEVLABELDIR, ptname);
if(!get_label_uuid(device, &label, uuid)) {
uuidcache_addentry(sstrdup(device),
return r;
} /* char *cu_mount_getoptionvalue(char *line, char *keyword) */
-
-
int
cu_mount_type(const char *type)
{
return CUMT_UNKNOWN;
} /* int cu_mount_type(const char *type) */
-
-
diff --git a/src/utils_tail_match.c b/src/utils_tail_match.c
index 34fe2dced95c91fc5a493dc71a724248ceec45a1..f518b1cd9172304d0319851b78c862c48a6a2388 100644 (file)
--- a/src/utils_tail_match.c
+++ b/src/utils_tail_match.c
sstrncpy (vl.plugin, data->plugin, sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, data->plugin_instance,
sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, data->type, sizeof (vl.type));
sstrncpy (vl.type_instance, data->type_instance,
sizeof (vl.type_instance));
- plugin_dispatch_values (data->type, &vl);
+ plugin_dispatch_values (&vl);
if (match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE)
{
diff --git a/src/utils_threshold.c b/src/utils_threshold.c
index 4da8943cdbf3c4a403dfb2e2b7b5ffb5f5405813..bea5bfb5ea210620c9703f77db4e444eb9764a15 100644 (file)
--- a/src/utils_threshold.c
+++ b/src/utils_threshold.c
return (-1);
}
- strncpy (th->type_instance, ci->values[0].value.string,
+ sstrncpy (th->type_instance, ci->values[0].value.string,
sizeof (th->type_instance));
- th->type_instance[sizeof (th->type_instance) - 1] = '\0';
return (0);
} /* int ut_config_type_instance */
}
memcpy (&th, th_orig, sizeof (th));
- strncpy (th.type, ci->values[0].value.string, sizeof (th.type));
- th.type[sizeof (th.type) - 1] = '\0';
+ sstrncpy (th.type, ci->values[0].value.string, sizeof (th.type));
th.warning_min = NAN;
th.warning_max = NAN;
return (-1);
}
- strncpy (th->plugin_instance, ci->values[0].value.string,
+ sstrncpy (th->plugin_instance, ci->values[0].value.string,
sizeof (th->plugin_instance));
- th->plugin_instance[sizeof (th->plugin_instance) - 1] = '\0';
return (0);
} /* int ut_config_plugin_instance */
}
memcpy (&th, th_orig, sizeof (th));
- strncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin));
- th.plugin[sizeof (th.plugin) - 1] = '\0';
+ sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin));
for (i = 0; i < ci->children_num; i++)
{
}
memcpy (&th, th_orig, sizeof (th));
- strncpy (th.host, ci->values[0].value.string, sizeof (th.host));
- th.host[sizeof (th.host) - 1] = '\0';
+ sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host));
for (i = 0; i < ci->children_num; i++)
{
*/
/* }}} */
-static threshold_t *threshold_search (const data_set_t *ds,
- const value_list_t *vl)
+static threshold_t *threshold_search (const value_list_t *vl)
{
threshold_t *th;
if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
- ds->type, vl->type_instance)) != NULL)
+ vl->type, vl->type_instance)) != NULL)
return (th);
else if ((th = threshold_get (vl->host, vl->plugin, vl->plugin_instance,
- ds->type, NULL)) != NULL)
+ vl->type, NULL)) != NULL)
return (th);
else if ((th = threshold_get (vl->host, vl->plugin, NULL,
- ds->type, vl->type_instance)) != NULL)
+ vl->type, vl->type_instance)) != NULL)
return (th);
else if ((th = threshold_get (vl->host, vl->plugin, NULL,
- ds->type, NULL)) != NULL)
+ vl->type, NULL)) != NULL)
return (th);
else if ((th = threshold_get (vl->host, "", NULL,
- ds->type, vl->type_instance)) != NULL)
+ vl->type, vl->type_instance)) != NULL)
return (th);
else if ((th = threshold_get (vl->host, "", NULL,
- ds->type, NULL)) != NULL)
+ vl->type, NULL)) != NULL)
return (th);
else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
- ds->type, vl->type_instance)) != NULL)
+ vl->type, vl->type_instance)) != NULL)
return (th);
else if ((th = threshold_get ("", vl->plugin, vl->plugin_instance,
- ds->type, NULL)) != NULL)
+ vl->type, NULL)) != NULL)
return (th);
else if ((th = threshold_get ("", vl->plugin, NULL,
- ds->type, vl->type_instance)) != NULL)
+ vl->type, vl->type_instance)) != NULL)
return (th);
else if ((th = threshold_get ("", vl->plugin, NULL,
- ds->type, NULL)) != NULL)
+ vl->type, NULL)) != NULL)
return (th);
else if ((th = threshold_get ("", "", NULL,
- ds->type, vl->type_instance)) != NULL)
+ vl->type, vl->type_instance)) != NULL)
return (th);
else if ((th = threshold_get ("", "", NULL,
- ds->type, NULL)) != NULL)
+ vl->type, NULL)) != NULL)
return (th);
return (NULL);
n.time = vl->time;
- status = snprintf (buf, bufsize, "Host %s, plugin %s",
+ status = ssnprintf (buf, bufsize, "Host %s, plugin %s",
vl->host, vl->plugin);
buf += status;
bufsize -= status;
if (vl->plugin_instance[0] != '\0')
{
- status = snprintf (buf, bufsize, " (instance %s)",
+ status = ssnprintf (buf, bufsize, " (instance %s)",
vl->plugin_instance);
buf += status;
bufsize -= status;
}
- status = snprintf (buf, bufsize, " type %s", ds->type);
+ status = ssnprintf (buf, bufsize, " type %s", vl->type);
buf += status;
bufsize -= status;
if (vl->type_instance[0] != '\0')
{
- status = snprintf (buf, bufsize, " (instance %s)",
+ status = ssnprintf (buf, bufsize, " (instance %s)",
vl->type_instance);
buf += status;
bufsize -= status;
}
+ plugin_notification_meta_add_string (&n, "DataSource",
+ ds->ds[ds_index].name);
+ plugin_notification_meta_add_double (&n, "CurrentValue", values[ds_index]);
+ plugin_notification_meta_add_double (&n, "WarningMin", th->warning_min);
+ plugin_notification_meta_add_double (&n, "WarningMax", th->warning_max);
+ plugin_notification_meta_add_double (&n, "FailureMin", th->failure_min);
+ plugin_notification_meta_add_double (&n, "FailureMax", th->failure_max);
+
/* Send an okay notification */
if (state == STATE_OKAY)
{
- status = snprintf (buf, bufsize, ": All data sources are within range again.");
+ status = ssnprintf (buf, bufsize, ": All data sources are within range again.");
buf += status;
bufsize -= status;
}
{
if (!isnan (min) && !isnan (max))
{
- status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
+ status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
"%f. That is within the %s region of %f and %f.",
ds->ds[ds_index].name, values[ds_index],
(state == STATE_ERROR) ? "failure" : "warning",
}
else
{
- status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
+ status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
"%f. That is %s the %s threshold of %f.",
ds->ds[ds_index].name, values[ds_index],
isnan (min) ? "below" : "above",
}
else /* is not inverted */
{
- status = snprintf (buf, bufsize, ": Data source \"%s\" is currently "
+ status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
"%f. That is %s the %s threshold of %f.",
ds->ds[ds_index].name, values[ds_index],
(values[ds_index] < min) ? "below" : "above",
plugin_dispatch_notification (&n);
+ plugin_notification_meta_free (&n);
return (0);
} /* }}} int ut_report_state */
/* Is this lock really necessary? So far, thresholds are only inserted at
* startup. -octo */
pthread_mutex_lock (&threshold_lock);
- th = threshold_search (ds, vl);
+ th = threshold_search (vl);
pthread_mutex_unlock (&threshold_lock);
if (th == NULL)
return (0);
memset (&ds, '\0', sizeof (ds));
memset (&vl, '\0', sizeof (vl));
- strncpy (vl.host, host, sizeof (vl.host));
- vl.host[sizeof (vl.host) - 1] = '\0';
- strncpy (vl.plugin, plugin, sizeof (vl.plugin));
- vl.plugin[sizeof (vl.plugin) - 1] = '\0';
+ sstrncpy (vl.host, host, sizeof (vl.host));
+ sstrncpy (vl.plugin, plugin, sizeof (vl.plugin));
if (plugin_instance != NULL)
- {
- strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- vl.plugin_instance[sizeof (vl.plugin_instance) - 1] = '\0';
- }
- strncpy (ds.type, type, sizeof (ds.type));
- ds.type[sizeof (ds.type) - 1] = '\0';
+ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (ds.type, type, sizeof (ds.type));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
- {
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
- }
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
sfree (name_copy);
host = plugin = plugin_instance = type = type_instance = NULL;
- th = threshold_search (&ds, &vl);
+ th = threshold_search (&vl);
if (th == NULL)
return (0);
if ((th->flags & UT_FLAG_PERSIST) == 0)
diff --git a/src/uuid.c b/src/uuid.c
index d54301a223bee899c430f4f1d19de617e8b78a4a..e0de0d9b314ed53575b7e5f00b08921a03834642 100644 (file)
--- a/src/uuid.c
+++ b/src/uuid.c
char *uuid = uuid_get_local ();
if (uuid) {
- strncpy (hostname_g, uuid, DATA_MAX_NAME_LEN);
- hostname_g[DATA_MAX_NAME_LEN-1] = '\0';
+ sstrncpy (hostname_g, uuid, DATA_MAX_NAME_LEN);
sfree (uuid);
return 0;
}
diff --git a/src/vmem.c b/src/vmem.c
index 5341e1594798b9eb24b0826f489e87054ad80a78..25f7c70cd3c15b581f0f22f3252e921c82373c33 100644 (file)
--- a/src/vmem.c
+++ b/src/vmem.c
sstrncpy (vl.plugin, "vmem", sizeof (vl.plugin));
if (plugin_instance != NULL)
sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
if (type_instance != NULL)
sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void vmem_submit */
static void submit_two (const char *plugin_instance, const char *type,
diff --git a/src/vserver.c b/src/vserver.c
index 7188b13e366b3b4b0f40bd4b8dbe5e8418b1bcd7..dac4392693159ad63dc1a095536b5a4cbefe9d09 100644 (file)
--- a/src/vserver.c
+++ b/src/vserver.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, "if_octets", sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values ("if_octets", &vl);
+ plugin_dispatch_values (&vl);
} /* void traffic_submit */
static void load_submit (const char *plugin_instance,
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, "load", sizeof (vl.type));
- plugin_dispatch_values ("load", &vl);
+ plugin_dispatch_values (&vl);
}
static void submit_gauge (const char *plugin_instance, const char *type,
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "vserver", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- strncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void submit_gauge */
static inline long long __get_sock_bytes(const char *s)
continue;
/* socket message accounting */
- len = snprintf (file, BUFSIZE, PROCDIR "/%s/cacct", dent->d_name);
- if ((len < 0) || (len >= BUFSIZE))
+ len = ssnprintf (file, sizeof (file),
+ PROCDIR "/%s/cacct", dent->d_name);
+ if ((len < 0) || (len >= sizeof (file)))
continue;
if (NULL == (fh = fopen (file, "r")))
}
/* thread information and load */
- len = snprintf (file, BUFSIZE, PROCDIR "/%s/cvirt", dent->d_name);
- if ((len < 0) || (len >= BUFSIZE))
+ len = ssnprintf (file, sizeof (file),
+ PROCDIR "/%s/cvirt", dent->d_name);
+ if ((len < 0) || (len >= sizeof (file)))
continue;
if (NULL == (fh = fopen (file, "r")))
}
/* processes and memory usage */
- len = snprintf (file, BUFSIZE, PROCDIR "/%s/limit", dent->d_name);
- if ((len < 0) || (len >= BUFSIZE))
+ len = ssnprintf (file, sizeof (file),
+ PROCDIR "/%s/limit", dent->d_name);
+ if ((len < 0) || (len >= sizeof (file)))
continue;
if (NULL == (fh = fopen (file, "r")))
diff --git a/src/wireless.c b/src/wireless.c
index 0edaf458688bcddd3dcce19c42652be93ece2e52..21bbcb401b141e0c09bb7f2a1cb8ce1db5f881b6 100644 (file)
--- a/src/wireless.c
+++ b/src/wireless.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "wireless", sizeof (vl.plugin));
- strncpy (vl.plugin_instance, plugin_instance,
+ sstrncpy (vl.plugin_instance, plugin_instance,
sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void wireless_submit */
#define POWER_MIN -90.0
diff --git a/src/xmms.c b/src/xmms.c
index 7f3edf0a27fd762d3b18f93ff4c8f2a0a8a05a16..09786fc9282b6f01bd8568750b771e4f8df039ea 100644 (file)
--- a/src/xmms.c
+++ b/src/xmms.c
vl.time = time (NULL);
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "xmms", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
- plugin_dispatch_values (type, &vl);
+ plugin_dispatch_values (&vl);
} /* void cxmms_submit */
int cxmms_read (void)