Quote

Menambahkan otomatis kedalam icinga .

#!/usr/bin/perl
# dijalankan tiap hari berdasarkan crontab daily

use DBI;
require “/etc/icinga/Konfig.pl”;
print “content-type: text/html \n\n”; #The header

my $filename = ‘/etc/icinga/rekind/hosts.cfg’;
open(my $fh, ‘>’, $filename) or die “Could not open file ‘$filename’ $!”;

my $dbh2 = DBI->connect(“dbi:mysql:$database2:$host2:3306”, $user2, $pw2);
my $sth2 = $dbh2->prepare(“SELECT device,devip,serial,location,type,description FROM devices”);
$sth2->execute();

$sth2->bind_columns(undef, \$device, \$devip,\$serial,\$location,\$type,\$description);

while($sth2->fetch()) {

$ipaddr=dec2dot($devip);

print $fh “define host{\n”;
print $fh ” use generic-switch\n”;
print $fh ” host_name $device\n”;
print $fh ” alias $device\n”;
print $fh ” address $ipaddr \n”;
print $fh ” hostgroups all \n”;
print $fh ” }\n”;
print $fh ” \n”;
print $fh ” define service{\n”;
print $fh ” use generic-service \n”;
print $fh ” host_name $device\n”;
print $fh ” service_description PING\n”;
print $fh ” check_command check_ping!200.0,20%!600.0,60%\n”;
print $fh ” check_interval 5 \n”;
print $fh ” retry_interval 1\n”;
print $fh ” }\n”;

}

close (HTML);
$dbh2->disconnect();

Menambahkan otomatis kedalam icinga

Leave a comment