Merge branch 'collectd-4.3' into collectd-4.4
[collectd.git] / bindings / perl / Collectd.pm
index 95a8a0a..4377570 100644 (file)
@@ -42,6 +42,7 @@ our %EXPORT_TAGS = (
                        plugin_register
                        plugin_unregister
                        plugin_dispatch_values
+                       plugin_dispatch_notification
                        plugin_log
        ) ],
        'types' => [ qw(
@@ -50,6 +51,7 @@ our %EXPORT_TAGS = (
                        TYPE_WRITE
                        TYPE_SHUTDOWN
                        TYPE_LOG
+                       TYPE_NOTIF
                        TYPE_DATASET
        ) ],
        'ds_types' => [ qw(
@@ -68,6 +70,11 @@ our %EXPORT_TAGS = (
                        LOG_INFO
                        LOG_DEBUG
        ) ],
+       'notif' => [ qw(
+                       NOTIF_FAILURE
+                       NOTIF_WARNING
+                       NOTIF_OKAY
+       ) ],
        'globals' => [ qw(
                        $hostname_g
                        $interval_g
@@ -80,6 +87,10 @@ our %EXPORT_TAGS = (
                foreach keys %EXPORT_TAGS;
 }
 
+# global variables
+our $hostname_g;
+our $interval_g;
+
 Exporter::export_ok_tags ('all');
 
 my @plugins : shared = ();
@@ -89,7 +100,8 @@ my %types = (
        TYPE_READ,     "read",
        TYPE_WRITE,    "write",
        TYPE_SHUTDOWN, "shutdown",
-       TYPE_LOG,      "log"
+       TYPE_LOG,      "log",
+       TYPE_NOTIF,    "notify"
 );
 
 foreach my $type (keys %types) {
@@ -138,8 +150,7 @@ sub plugin_call_all {
                my $status = 0;
 
                if ($p->{'wait_left'} > 0) {
-                       # TODO: use interval_g
-                       $p->{'wait_left'} -= 10;
+                       $p->{'wait_left'} -= $interval_g;
                }
 
                next if ($p->{'wait_left'} > 0);
@@ -166,11 +177,12 @@ sub plugin_call_all {
 
                if ($status) {
                        $p->{'wait_left'} = 0;
-                       $p->{'wait_time'} = 10;
+                       $p->{'wait_time'} = $interval_g;
                }
                elsif (TYPE_READ == $type) {
-                       WARNING ("${plugin}->read() failed with status $status. "
-                               . "Will suspend it for $p->{'wait_left'} seconds.");
+                       if ($p->{'wait_time'} < $interval_g) {
+                               $p->{'wait_time'} = $interval_g;
+                       }
 
                        $p->{'wait_left'} = $p->{'wait_time'};
                        $p->{'wait_time'} *= 2;
@@ -178,6 +190,9 @@ sub plugin_call_all {
                        if ($p->{'wait_time'} > 86400) {
                                $p->{'wait_time'} = 86400;
                        }
+
+                       WARNING ("${plugin}->read() failed with status $status. "
+                               . "Will suspend it for $p->{'wait_left'} seconds.");
                }
                elsif (TYPE_INIT == $type) {
                        ERROR ("${plugin}->init() failed with status $status. "
@@ -235,9 +250,8 @@ sub plugin_register {
                        $data = $pkg . "::" . $data;
                }
 
-               # TODO: make interval_g available at configuration time
                %p = (
-                       wait_time => 10,
+                       wait_time => $interval_g,
                        wait_left => 0,
                        cb_name   => $data,
                );