Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2022-08-08 00:47 GMT
Find Nodes?
    Voting Booth?

    No recent polls found