-
Notifications
You must be signed in to change notification settings - Fork 9
/
supervisor_check.pl
65 lines (48 loc) · 1.45 KB
/
supervisor_check.pl
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/perl
use strict;
use Switch;
# --------- base config -------------
my $ZabbixServer = "1.2.3.4";
my $HostName = "HostName";
# ----------------------------------
switch ($ARGV[0])
{
case "discovery" {
my $first = 1;
print "{\n";
print "\t\"data\":[\n\n";
my $result = `/usr/bin/supervisorctl status`;
my @lines = split /\n/, $result;
foreach my $l (@lines) {
my @stat = split / +/, $l;
# my $status = substr($stat[1], 0, -1);
print ",\n" if not $first;
$first = 0;
print "\t{\n";
print "\t\t\"{#NAME}\":\"$stat[0]\",\n";
print "\t\t\"{#STATUS}\":\"$stat[1]\"\n";
print "\t}";
}
print "\n\t]\n";
print "}\n";
}
case "status" {
my $result = `/usr/bin/supervisorctl pid`;
if ( $result =~ m/^\d+$/ ) {
$result = `/usr/bin/zabbix_sender -z $ZabbixServer -s $HostName -k "supervisor.status" -o "OK"`;
print $result;
$result = `/usr/bin/supervisorctl status`;
my @lines = split /\n/, $result;
foreach my $l (@lines) {
my @stat = split / +/, $l;
$result = `/usr/bin/zabbix_sender -z $ZabbixServer -s $HostName -k "supervisor.check[$stat[0],Status]" -o $stat[1]`;
print $result;
}
}
else {
# error supervisor not runing
$result = `/usr/bin/zabbix_sender -z $ZabbixServer -s $HostName -k "supervisor.status" -o "FAIL"`;
print $result;
}
}
}