emjga1 has asked for the wisdom of the Perl Monks concerning the following question:
I have written a Perl Script to auto generate a Nagios configuration file
While the code works very well. Snipit of it is below. It does not look good and is vary hard to maintanin or to add new bits to.
Can any body point me in the right direction to do things a bit better. e.g possable use of Forms
Thanks
Matt
Snipit of code -
foreach (@MASTER) { chomp; @line = split(/\t/,$_); $nodename = $line[0]; $machine_type = $line[2]; $comment = $line[6]; $location = $line[8]; $machine = $line[10]; $serial = $line[12]; $fname = $line[16]; $lname = $line[18]; $phone = $line[20]; $racf = $line[22]; $installed = $line[24]; $type = $line[26]; #print "NODE $nodename TYPE $machine_type COMMENT $comment LOCATION $l +ocation MACHINE $machine SERIAL $serial Fist na me $fname Last name $lname Phone $phone RACF $racf $type\n"; nslookup(); if (@found = grep(/\b$nodename\b/,@exceptions)) { print "found $nodename in exceptions - ignoring\n"; } else { #if (@found = grep(/\b$type\b/,server)) { # print "Node $nodename is a server\n"; #} else { #print "Node $nodename is a workstation\n"; } print "Doing $nodename\n"; print autoconf "\n# Host $nodename $machine_type check host al +ive \n"; print autoconf "define host{\n"; print autoconf "use generic-host\n"; print autoconf "host_name $nodename\n"; print autoconf "alias $comment\n"; print autoconf "address $IPnumber\n"; # If a Sun T3 then use normal ping command and not the New ping if (@T3 = grep(/\b$machine_type\b/,"sun_t3")) { print autoconf "check_command check-host-alive-ping\n"; } else { print autoconf "check_command check-host-alive\n"; } print autoconf "max_check_attempts 10\n"; print autoconf "notification_interval 7\n"; print autoconf "notification_period 24x7\n"; print autoconf "notification_options d,u,r\n"; print autoconf "}\n"; print autoconf " \n"; print autoconf "#Serviceescalation definition $nodename $machi +ne_type PING\n"; print autoconf "define serviceescalation{\n"; print autoconf "host_name $nodename\n"; print autoconf "service_description PING\n"; print autoconf "first_notification 2\n"; print autoconf "last_notification 2\n"; print autoconf "contact_groups $machine_type-admins-escalatio +n\n"; print autoconf "notification_interval 0\n"; print autoconf "}\n"; print autoconf "\n"; print autoconf "#Service Definition $nodename $machine_type PI +NG\n"; print autoconf "define service{ \n"; print autoconf "use generic-service \n"; print autoconf "host_name $nodename\n"; print autoconf "service_description PING\n"; print autoconf "is_volatile 0\n"; print autoconf "check_period 24x7\n"; print autoconf "max_check_attempts 3\n"; print autoconf "normal_check_interval 5\n"; print autoconf "retry_check_interval 1\n"; print autoconf "contact_groups $machine_type-admins\n"; print autoconf "notification_interval 7\n"; print autoconf "notification_period 24x7\n"; print autoconf "notification_options c,r\n"; # If a Sun T3 then use normal ping command and not the New ping if (@T3 = grep(/\b$machine_type\b/,"sun_t3")) { print autoconf "check_command check_ping\n"; } else { print autoconf "check_command check_newping\n"; } print autoconf "}\n"; print autoconf "\n"; print autoconfnscgi "\n# Extended info for client $nodename $m +achine_type using info.cgi script\n"; if (@SUN = grep(/\b$machine_type\b/,"sun")) { print autoconfnscgi "define hostextinfo{\n"; print autoconfnscgi "host_name $nodename\n"; print autoconfnscgi "notes_url info.cgi?host= +$nodename&type=$machine_type&comment=$comment&l ocation=$location&machine=$machine&serial=$serial&fname=$fname&lname=$ +lname&phone=$phone&racf=$racf\n"; print autoconfnscgi "icon_image $machine_type. +gif\n";
update (broquaint): dropped <code> tags and added formatting
(ybiC): balanced <readmore> tags, remove trainling (Long) from title
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Better use of perl print statment for Nagios, (Long)
by liz (Monsignor) on Jul 30, 2003 at 13:58 UTC | |
|
Re: Better use of perl print statment for Nagios, (Long)
by l2kashe (Deacon) on Jul 30, 2003 at 14:51 UTC | |
|
Re: Better use of perl print statment for Nagios, (Long)
by BrowserUk (Patriarch) on Jul 30, 2003 at 15:58 UTC | |
|
Re: Better use of perl print statment for Nagios
by emjga1 (Novice) on Jul 31, 2003 at 09:03 UTC |