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 | |
################## | |
## CSV Format ## | |
## Delimiter ; ## | |
################## | |
###################################################### | |
### ### | |
### name;ip_contador ### | |
### ### | |
###################################################### | |
# you should change the template in the end of this script | |
# vdominguez 2012 | |
use strict; | |
use warnings; | |
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n"; | |
open(my $data, '<', $file) or die "Could not open '$file' $!\n"; | |
while (my $line = <$data>) { | |
chomp $line; | |
my @fields = split ";" , $line; | |
if ($fields[0] && $fields[1]) { | |
my $hosts = create_host_in_file ($fields[0],$fields[1]); | |
print $hosts; | |
} | |
} | |
sub create_host_in_file { | |
my $host_name=shift; | |
my $host_address=shift; | |
my $template = <<END; | |
define host { | |
host_name $host_name | |
alias $host_name | |
address $host_address | |
use HostGeneric | |
# check_command process-service-perfdata | |
# event_handler process-service-perfdata | |
# notification_period none | |
# check_command process-service-perfdata | |
# event_handler process-service-perfdata | |
# notification_period none | |
# contact_groups sistemasdist-Grupo | |
} |
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 -w | |
############################################# | |
# Convert host.cfg from nagios in a CSV? # | |
# Debian requires .deb:libnagios-object-perl# | |
############################################# | |
# vdominguez 2012 | |
use strict; | |
use lib qw( ./lib ../lib); | |
use Nagios::Config; | |
use Nagios::Object::Config; | |
use Data::Dumper; | |
Nagios::Object::Config->strict_mode(1); | |
my $file = $ARGV[0] or die "Need a host.cfg file\n"; | |
my $obj = undef; | |
$obj = Nagios::Object::Config->new(); | |
$obj->parse($file); | |
if ($ARGV[1] =~ m/-d/) { | |
print Dumper($obj), "\n"; | |
} else { | |
my $hosts = $obj->all_objects_for_type("Nagios::Host"); | |
if (scalar(@$hosts) == 0) { | |
# print "No hosts have yet been defined\n"; | |
} else { | |
foreach my $host (@$hosts) { | |
printf $host->host_name . ";" . $host->address . "\n"; | |
} | |
} | |
} |