Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
laziness, impatience, and hubris
 
PerlMonks  

Re: Better use of perl print statment for Nagios, (Long)

by l2kashe (Deacon)
on Jul 30, 2003 at 14:51 UTC ( #279196=note: print w/ replies, xml ) Need Help??


in reply to Better use of perl print statment for Nagios

A couple of thoughts

Since it appears that the data you are interested in is always in the same offsets of your split you could define them once, and then use them throught out the rest of the code. (You could also use Constant, but read up on the docs and do a super search, as interesting problems can arise from using the module). You could use the select function to clean up the prints, or a HERE document. If you end up going with HERE docs, I would suggest doing whatever "extra" logic prior to, so that you don't need to end the print, perform a simple test and reinitiate printing.. Ala

# snipped for brevity's sake my $nodename = '0'; my $m_type = '2'; my $comment = '6'; # etc... for ( @MASTER ) { my($chk_cmd, $chk_ping); chomp; my $line = [ split("\t") ]; # If its a t3 array these lines need to be different, do it # now as opposed to later if ( $line->[$m_type] eq 'sun_t3') { $chk_cmd = "check_command\tcheck-host-alive-ping\n"; $chk_ping = "check_command\tcheck_ping\n"; } else { $chk_cmd = "check_command\tcheck-host-alive\n"; $chk_ping = "check_command\tcheck_newping\n"; } print autoconf<<EOF; # Host $line->[$nodename] $line->[$m_type] check host alive define host { use generic-host host_name $line->[$nodename] alias $line->[$comment] address $IPnumber $chk_cmd } EOF }

Also since quite a bit of that content is relativly static, I might end up using an array to store bits and pieces, then joining them into single scalars ala my $out = join("\n", @data); to further clean up the output.

use perl;


Comment on Re: Better use of perl print statment for Nagios, (Long)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://279196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2014-04-25 09:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (586 votes), past polls