forked from alcy/OpsBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNagios.pm
More file actions
32 lines (30 loc) · 875 Bytes
/
Nagios.pm
File metadata and controls
32 lines (30 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package OpsBot::Nagios;
use strict;
use warnings;
require Exporter;
our @EXPORT_OK = qw(&nagios);
use OpsBot::Config;
use Monitoring::Livestatus;
sub nagios {
my $msg_body = shift;
my $output='';
my $ml = Monitoring::Livestatus->new(
server => "$plugins{nagios}->{server}:$plugins{nagios}->{port}"
);
my ($host) = ( $msg_body =~ /(?:^\!nagios) host=(\S+)/ );
my %tmp=();
my $services_with_info = $ml->selectcol_arrayref("GET hosts\nColumns: services_with_info\nFilter: host_name = $host");
for my $serviceref ( @$services_with_info ) {
foreach (@$serviceref) {
my @serviceattrs = @$_;
if ($serviceattrs[1] != 0 ) {
$tmp{$serviceattrs[0]} = $serviceattrs[3]; # service description and service error code
}
}
}
for my $key ( keys %tmp ) {
$output = $output . "$key ---> $tmp{$key}\n";
}
return $output;
}
1;