Import host CSV file?

jeff vier jeff.vier at tradingtechnologies.com
Tue Nov 4 20:59:44 CET 2003


I actually wrote one for him in awk.  it's attached.

easy enough to hack for any CSV layout, I think.

On Tue, 2003-11-04 at 12:17, Skip Montanaro wrote:
>     Jon> Has anyone writen a script to import a large number of hosts from a
>     Jon> CSV file into nagios? Just wondering...
> 
> No, but it shouldn't be too difficult.  I use Python (2.3 comes with an
> easy-to-use csv module of which I am a co-author), but I suspect you
> wouldn't have much trouble with Perl, Tcl or Ruby presuming they either
> support csv file reading or that your csv file doesn't exercise csv's corner
> cases.
> 
> What sort of information do you have in your csv file?  If it's just basic
> name, alias, ip sorts of stuff, then generating host definitions from that
> should be a breeze.
-------------- next part --------------
#!/bin/awk -f

# usage: ./csv.to.nagios.hosts.awk [file.csv]...

BEGIN { FS="," }

{
	print "define host {"
	print "\tuse\t\tgeneric"
	print "\thost_name\t" $1
	print "\talias\t\t" $2
	print "\taddress\t\t" $3
	print "\tparents\t\t" $4 "," $5
	print "\t}"
	print ""
}


More information about the Users mailing list