Advertisement
5t0ff31

icinga2 make hosts.conf from tab csv

Nov 22nd, 2016
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.95 KB | None | 0 0
  1. use tab between cols
  2. cat hosts.csv
  3. reporting-cucm          127.0.0.1       report-host     dummy
  4. reporting-fax           127.0.0.1       report-host     dummy
  5. vm-rz1-001  cust1-uk-lon-001  10.10.10.11   generic-host  linux
  6. vm-rz1-002  cust1-de-ber-001  10.10.10.12   generic-host  windows
  7. vm-rz2-001  cust1-uk-lon-001  10.10.10.21   generic-host  linux
  8. vm-rz2-002  cust1-de-ber-001  10.10.10.22   generic-host  windows
  9.  
  10. cat make_host.pl
  11. #! /usr/bin/perl
  12. #by shafiz
  13. #use strict;
  14. #use warnings;
  15. #use Text::CSV;
  16.  
  17. my($version) = "1.0";
  18. my($file) = "/etc/icinga2/scripts/hosts.csv";
  19. my @hosts = `cat $file`;
  20.  
  21. foreach( @hosts )
  22. {
  23.   chomp;
  24.   my @array = split("\t", $_);
  25.   printf "object Host \"$array[0]\"\{\n";
  26.   printf "        import           \"$array[3]\"\n";
  27.   printf "        address =        \"$array[2]\"\n";
  28.   printf "        vars.os =        \"$array[4]\"\n";
  29.   printf "        vars.urix =      \"$array[1]\"\n";
  30.   printf "       \}\n";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement