LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Help with Nagios Script (https://www.linuxquestions.org/questions/linux-software-2/help-with-nagios-script-756823/)

pokker67 09-21-2009 01:53 PM

Help with Nagios Script
 
HI!

first of all my apologies due to my poor English, is not lenguage

I have a little problem with a script that i use to send email messages regarding service status.
all process to sent and receive is ok, but the body of the message is not complete, below theres an example


Notificacion de tipo: PROBLEM
Equipo: Server (CPU)
Servicio: CRITICAL
Estado actual: busy <<<<<<<<<<<<<<<

in the line with "busy" must be show also a percentaje for the critical message and another stuff that the plugin shows as result
but i just receive only one word

My question is, is there some command line or instruccion on the perl script who is limiting the characters ???

I am not an Expert on perl or linux, so is difficult to me try to understand the code of the sript

the scrip that i use is the following


#!/usr/bin/perl
use Net::SMTP;
$destinatario=$ARGV[0];
$tipo=$ARGV[1];
$host=$ARGV[2];
$svname=$ARGV[3];
$status=$ARGV[4];
$ip=$ARGV[5];
$sdesc=$ARGV[6];
$smtp= Net::SMTP-> new("mailserver");
$smtp->mail("nagios@mydomain.com");
$smtp->to("$destinatario");
$smtp->data();
$smtp->datasend("To: $destinatario\n");
$smtp->datasend("subject: NAGIOS - $tipo: $host $svname estado $status\n");
$smtp->datasend("Notificacion de tipo: $tipo\n");
$smtp->datasend("Equipo: $host ($ip)\n");
$smtp->datasend("Servicio: $svname\n");
$smtp->datasend("Estado actual: $sdesc $status\n");
$smtp->dataend();
$smtp->quit;

thanks in advance for any help

kbp 09-21-2009 08:04 PM

Just off the top of my head... if the $status argument being passed in contains for example: "%90", it may get interpreted as a hash that doesn't exist, you may need to validate the input.

cheers

chrism01 09-21-2009 08:22 PM

This is a sub I use for sending emails from Perl;
Code:

#******************************************************************************
#
# Function      : send_email
#
# Description  : Send an email warning for errors
#
# Params        : $_[0]    error msg
#
# Returns      : none
#
#******************************************************************************
sub send_email
{
    my (
        $error_msg,        # input error msg
        $hostname,          # name of this box for sending
        $prog_full_name,    # prog path + name
        $contact_email,    # contact email address
        $mailer,            # mailer object
        $sender,            # sender of email as specified in cfg file
        $subject,          # subject line in email
        $body_text          # actual email msg text
        );

    # Assign input params
    $error_msg = $_[0];

    # Get hostname anyway we can using Sys::Hostname;
    # tries syscall(SYS_gethostname), `hostname`, `uname -n`
    $hostname = Sys::Hostname::hostname();

    # Get program full path name
    $prog_full_name = cwd()."/${0}";

    # Set the fields required by Mailer...
    $contact_email = $cfg::params{'ADMIN_EMAIL'};
    $sender = "$prog_full_name";
    $subject = "$prog_full_name: Error trapped";
    $body_text = "This is an automated message:\n\n".
                "$error_msg\n\n".
                "Regards,\n$prog_full_name at $hostname\n\n";

    # ... and send it
    $mailer = Mail::Mailer->new("sendmail");
    $mailer->open({ From    => $sender,
                    To      => $contact_email,
                    Subject => $subject,
                    }) or print "Can't open Mailer for sendmail: $!\n";
    print $mailer $body_text;
    close($mailer) or die "Can't close mailer: $!";
}

Maybe you can adjust it for your use; I've used it many times.


All times are GMT -5. The time now is 12:19 AM.