Advertisement
vicendominguez

Converting host.cfg to csv fast!

Feb 18th, 2013
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.85 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. #############################################
  3. # Convert host.cfg from nagios in a CSV?    #
  4. # Debian requires .deb:libnagios-object-perl#
  5. #############################################
  6. # vdominguez 2012
  7.  
  8. use strict;
  9. use lib qw( ./lib ../lib);
  10. use Nagios::Config;
  11. use Nagios::Object::Config;
  12. use Data::Dumper;
  13.  
  14. Nagios::Object::Config->strict_mode(1);
  15.  
  16. my $file = $ARGV[0] or die "Need a host.cfg file\n";
  17.  
  18. my $obj = undef;
  19. $obj = Nagios::Object::Config->new();
  20. $obj->parse($file);
  21.  
  22. if ($ARGV[1] =~ m/-d/) {
  23.     print Dumper($obj), "\n";
  24. } else {
  25.     my $hosts = $obj->all_objects_for_type("Nagios::Host");
  26.     if (scalar(@$hosts) == 0) {
  27. #        print "No hosts have yet been defined\n";
  28.     } else {
  29.         foreach my $host (@$hosts) {
  30.            printf $host->host_name . ";" . $host->address . "\n";
  31.        }
  32.    }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement