Last active
December 11, 2015 05:59
-
-
Save unicolet/4556268 to your computer and use it in GitHub Desktop.
Configuration for collectd to tail a log file and trigger an OpenNMS UEI whenever a certain pattern occurs. http://unicolet.blogspot.it/2013/01/triggering-opennms-notifications-when.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Interval 10 | |
LoadPlugin logfile | |
#LoadPlugin write_graphite | |
LoadPlugin csv | |
LoadPlugin threshold | |
LoadPlugin exec | |
LoadPlugin tail | |
<Plugin "logfile"> | |
LogLevel "debug" | |
File "stdout" | |
Timestamp true | |
</Plugin> | |
<Plugin exec> | |
NotificationExec "me" "/opt/collectd/bin/notif.pl" | |
</Plugin> | |
<Plugin "csv"> | |
DataDir "/tmp" | |
StoreRates true | |
</Plugin> | |
<Plugin "tail"> | |
<File "/tmp/scp.log"> | |
Instance "scp" | |
<Match> | |
Regex "ERROR" | |
DSType "CounterInc" | |
Type "counter" | |
Instance "hi_error" | |
</Match> | |
</File> | |
</Plugin> | |
# Load required matches: | |
#LoadPlugin match_empty_counter | |
#LoadPlugin match_hashed | |
LoadPlugin match_regex | |
LoadPlugin match_value | |
#LoadPlugin match_timediff | |
# Load required targets: | |
LoadPlugin target_notification | |
#LoadPlugin target_replace | |
#LoadPlugin target_scale | |
#LoadPlugin target_set | |
#LoadPlugin target_v5upgrade | |
PostCacheChain "SelectHiErrors" | |
<Chain "SelectHiErrors"> | |
<Rule "selecthi"> | |
<Match "regex"> | |
TypeInstance "^hi_error$" | |
</Match> | |
<Target "jump"> | |
Chain "CheckHiErrors" | |
</Target> | |
</Rule> | |
<Target "write"> | |
</Target> | |
</Chain> | |
<Chain "CheckHiErrors"> | |
<Rule "checkhivalue"> | |
<Match "value"> | |
Min 0 | |
Max 0 | |
Invert true | |
</Match> | |
<Target "notification"> | |
Message "%{type_instance}" | |
Severity "WARNING" | |
</Target> | |
</Rule> | |
</Chain> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Sys::Syslog; | |
use Sys::Syslog qw(:standard :macros); | |
openlog('collectd_notif', "ndelay,pid", LOG_USER); | |
while(<>) { | |
chomp; | |
($key, $val) = split("\:", $_); | |
if ($key =~ /TypeInstance/ && $val =~ /hi_error/) { | |
my @args = ("/opt/collectd/bin/send-event.pl", "uei.my.org/collectd/scp/HiError", "-i", "192.168.123.123", "opennms.my.org"); | |
system(@args) == 0 or syslog(LOG_ERROR|LOG_USER, "Error sending UEI uei.my.org/collectd/scp/HiError"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment