LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-21-2009, 01:53 PM   #1
pokker67
LQ Newbie
 
Registered: Apr 2009
Posts: 4

Rep: Reputation: 0
Wink 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
 
Old 09-21-2009, 08:04 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
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
 
Old 09-21-2009, 08:22 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,873

Rep: Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600Reputation: 2600
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Nagios and Oreon (Nagios web front end) installation and Configuration LXer Syndicated Linux News 1 05-31-2016 07:26 AM
Perl Script works from command line, but not when evoked by Nagios gfem Linux - General 10 06-05-2008 03:59 PM
Trying to get current cpu percentages in a script for nagios. (bash) helptonewbie Linux - Newbie 3 05-01-2008 06:09 PM
Nagios check_sun_hardware script alek66 Solaris / OpenSolaris 2 02-14-2008 05:22 AM
LXer: Nagios 2.5 and Oreon 1.3 (Nagios web front end) installation with screenshots LXer Syndicated Linux News 0 08-11-2006 05:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration