-
Notifications
You must be signed in to change notification settings - Fork 4
/
ctextcheckdiscover.pl
41 lines (29 loc) · 963 Bytes
/
ctextcheckdiscover.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
#!/usr/bin/perl
use strict;
my $first = 1;
print "{\n";
print "\t\"data\":[\n\n";
my $CTID = shift(@ARGV);
if ($CTID =~ /(\d+)$/ ) {$CTID = $1; }
my $CTNAME = `/usr/sbin/vzlist $CTID -a -o hostname -H 2>/dev/null`;
#cut end string
$CTNAME = substr($CTNAME, 0, -1);
my $vzresult = `/usr/sbin/vzctl exec2 $CTID "if test -e /etc/zabbix/ct_check.sh; then /etc/zabbix/ct_check.sh; fi" 2>/dev/null`;
my @lines = split /\n/, $vzresult;
foreach my $l (@lines) {
if ($l =~ /^(.*);(.*)$/)
{
my $key = $1;
my $descr = $2;
print ",\n" if not $first;
$first = 0;
print "\t{\n";
print "\t\t\"{#CTID}\":\"$CTID\",\n";
print "\t\t\"{#CTNAME}\":\"$CTNAME\",\n";
print "\t\t\"{#KEY}\":\"$key\",\n";
print "\t\t\"{#DESCR}\":\"$descr\"\n";
print "\t}";
}
}
print "\n\t]\n";
print "}\n";