Folks

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


In reply to Better use of perl print statment for Nagios by emjga1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.