[gelöst] problem mit variable in script

Vom einfachen Programm zum fertigen Debian-Paket, Fragen rund um Programmiersprachen, Scripting und Lizenzierung.
Antworten
Benutzeravatar
rene04
Beiträge: 1751
Registriert: 26.08.2004 08:46:39
Wohnort: Kaiserslautern

[gelöst] problem mit variable in script

Beitrag von rene04 » 09.06.2010 16:25:17

Hallo,

ich habe hier ein script welches mir eine bestimmte variable ausgeben soll. leider tut es das nicht!

Code: Alles auswählen

#!/bin/sh

# notify-html-email.sh v1.7
#  by mgothard
# www.NagiosExchange.org
VERSION="1.7"

# Requires the following shell commands/programs (in reference order):
#   sendmail   - or other command-line mail tool; called to actually handle sending of message
#   printf     - interpret escape characters before passing to mail system
#   date       - used to generate unique Content-ID and MIME boundary; also to convert Nagios Unix epoch timestamps to human readable
#   hostname   - used to generate unique Content-ID and MIME boundary
#   uuencode   - generates Base64 encodes of Nagios graphics
#   head       - used to cleanup uuencode output
#   tail       - used to cleanup uuencode output
#   python     - manipulate strings

# ChangeLog
# ---------
# 1.7 - Added Nagios 3.x compatibility
#     - Changed HTML to reflect Nagios 3.x format changes
#     - More Outlook 2007 rendering fixes
#     - Added checks for critical supporting programs
#     - Modified error messages to be more helpful
# 1.6 - Fixed MIME boundary problem
#     - Fixed capitalization problems with "text-transform" on some browsers
#     - Fixed compatibility issues with Microsoft Outlook 2007 (with a loss of HTML 4.01 Strict compliance)
# 1.5 - New format looks and acts more like Nagios itself
#     - HTML 4.01 Strict compliant; all tags in lower case and all parameters quoted in prep for XHTML 1.0
#     - Multipart MIME added with embedded graphics and alternate text
#     - Single HTML form modified with variables for ease in editing
#     - Lots of code changes/cleanup
#     - Corrected some timezone related bugs
#     - Added tons of comments
# 1.0 - Original HTML message generation; text/html MIME type only
#     - CSS 2.0 compliant

# Known Bugs
# ---------
# 1. May be some bash specific syntax in here.  Please report this if you find it.

# ****************************************
# Modify the following variables as needed
# ****************************************

KOMMENTAR="$(/usr/bin/printf 'GET comments\nColumns: comment\nFilter: host_name = $NAGIOS_HOSTNAME\nFilter: service_description = $NAGIOS_SERVICEDESC\n' | /usr/local/bin/unixcat  /tmp/live.sock)"

# Full path to your mail program
MAILER=/usr/sbin/sendmail

# Any options necessary to read the FROM: and TO: fields, etc. from the input
MAILOPTS="-t"

# Full path to printf
PRINTF=/usr/bin/printf

# Full path to Nagios images directory.  Do NOT include a trailing backslash character! ('/')
IMAGES=/usr/local/nagios/share/images

# Text name for your reply-to address.  E-mail address is gleaned from Nagios config
REPLYNAME="NBnagios"
REPLYADDRESS="$REPLYNAME <$NAGIOS_ADMINEMAIL>"

# Full URL to Nagios front-end.  Do NOT include a trailing backslash character! ('/')
URLPATH="http://nbnagios/thruk"

# Full URL to Nagios cgi-bin directory.  Do NOT include a trailing backslash character! ('/')
URLCGIBIN="$URLPATH/cgi-bin"

# Date command formating parameters used in HTML message.  Can be null, or include options, or both
#  ex: "--rfc-3389=seconds", "+%x %X"
DATEFORMAT="+%m/%d/%Y %l:%M:%S%P %Z"

# Generate unique MIME Content-ID base for multipart message
CONTENTIDBASE="`date +%s`@`hostname --fqdn`"

# MIME boundary string
MIMEBOUNDARY1="=_NextPart_`date +%s`_`hostname`_1"
MIMEBOUNDARY2="=_NextPart_`date +%s`_`hostname`_2"

# *************END MODIFY*****************

# Check for proper usage
[ $1 ] || {
	echo -e "notify-html-email.sh $VERISON\n\nHTML 4.0 notification for Nagios 3.x and 2.x\n\nUsage: notify-html-email <notification_type>\n\nOptions:"
	echo -e " notification_type\n    Must be 'host' or 'service' indicating the type of notification\n"
	echo -e "This script should be called by a Nagios e-mail notification command\nfrom /usr/local/nagios/etc/misccommands.cfg"
	echo -e "It uses the NAGIOS_* environmental variables to generate and send an HTML\nmessage to the recipient.  The format of the e-mail is customizable by\nediting this script.\n"
	exit -1
}

# Be sure minimum necessary variables are present
[ $NAGIOS_HOSTNAME ] || {
	echo -e "ERROR: Hostname not found.\n\nMaybe this script was not called from Nagios?\nDo not try to execute this script manually.\nType $0 for more info"
	exit -1
}
[ $NAGIOS_CONTACTEMAIL ] || {
	echo -e "ERROR: E-mail address not found.\n\nMaybe this script was not called from Nagios?\nDo not try to execute this script manually.\nType $0 for more info"
	exit -1
}
[ $NAGIOS_ADMINEMAIL ] || {
	echo -e "ERROR: Reply-To e-mail address not found.\n\nMaybe this script was not called from Nagios?\nDo not try to execute this script manually.\nType $0 for more info"
	exit -1
}

# For future functionaliy
#[ $NAGIOS_MAINCONFIGFILE ] || {
#	echo "ERROR: Unable to locate the main Nagios config file.  Not called from Nagios?"
#	exit -1
#}

# Check all necessary programs are present
[ -f $MAILER ] || {
        echo -e "ERROR: E-mail program $MAILER could not be found!\n\nPlease edit this script and change the MAILER variable accordingly"
        exit -1
}
[ -f $PRINTF ] || {
        echo -e "ERROR: Print formatting function $PRINTF could not be found!\n\nPlease edit this script and change the PRINTF variable accordingly"
        exit -1
}
[ -d $IMAGES ] || {
        echo -e "ERROR: Images directory $IMAGES could not be found!\n\nPlease edit this script and change the IMAGES variable accordingly"
        exit -1
}

# Generate Base64 encodings for inline graphics
UUIMGSTATUS3=`uuencode --base64 $IMAGES/status3.gif status3.gif | tail --lines=+2 | head --lines=-1`
UUIMGDISABLED=`uuencode --base64 $IMAGES/disabled.gif disabled.gif | tail --lines=+2 | head --lines=-1`
UUIMGDELAY=`uuencode --base64 $IMAGES/delay.gif delay.gif | tail --lines=+2 | head --lines=-1`
UUIMGACK=`uuencode --base64 $IMAGES/ack.gif ack.gif | tail --lines=+2 | head --lines=-1`
UUIMGDOWNTIME=`uuencode --base64 $IMAGES/downtime.gif downtime.gif | tail --lines=+2 | head --lines=-1`
UUIMGENABLED=`uuencode --base64 $IMAGES/enabled.gif enabled.gif | tail --lines=+2 | head --lines=-1`
UUIMGCOMMENT=`uuencode --base64 $IMAGES/comment.gif comment.gif | tail --lines=+2 | head --lines=-1`

# Graphics that may not be used (depends on notification type)
MIMEGRAPHICACK="--$MIMEBOUNDARY2
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-Description: Inline graphic
Content-ID: <ack.gif$CONTENTIDBASE>
Content-Location: $URLPATH/images/ack.gif
Content-Disposition: inline

$UUIMGACK"
MIMEGRAPHIC1="--$MIMEBOUNDARY2
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-Description: Inline graphic
Content-ID: <status3.gif$CONTENTIDBASE>
Content-Location: $URLPATH/images/status3.gif
Content-Disposition: inline

$UUIMGSTATUS3"
MIMEGRAPHIC2="--$MIMEBOUNDARY2
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-Description: Inline graphic
Content-ID: <enabled.gif$CONTENTIDBASE>
Content-Location: $URLPATH/images/enabled.gif
Content-Disposition: inline

$UUIMGENABLED"

# Initialize variables
FLAPPING="NO"
FLAPPINGCLASS="notflapping"

case $NAGIOS_NOTIFICATIONTYPE
in
 PROBLEM) BKCLR="F83838" ;
	case $NAGIOS_SERVICESTATE
	in
	 WARNING) BKCLR="FFFF00" ;;
	 UNKNOWN) BKCLR="FF9900" ;;
	esac ;;
 RECOVERY) BKCLR="33FF00" ;
    MIMEGRAPHICACK="" ;;
 ACKNOWLEDGEMENT) BKCLR="0099FF" ;
  	R_SUBJECT="has been acknowledged by" ;
    STATUSACK="(Has been acknowledged)&nbsp;&nbsp;" ;
    MIMEGRAPHICACK="" ;;
 FLAPPINGSTART) BKCLR="F83838" ;
    R_SUBJECT="has started flapping" ;
    FLAPPING="YES" ;
    FLAPPINGCLASS="flapping" ;;
 FLAPPINGSTOP) BKCLR="33FF00" ;
   	R_SUBJECT="is no longer flapping" ;
    MIMEGRAPHICACK="" ;;
 FLAPPINGDISABLED) BKCLR="0099FF" ;
    R_SUBJECT="was flapping and had flapping notifications disabled";
    FLAPPING="DISABLED" ;
    FLAPPINGCLASS="flapping" ;
    MIMEGRAPHICACK="" ;;
 DOWNTIMESTART) BKCLR="0099FF" ;
    R_SUBJECT="has entered scheduled downtime" ;
    MIMEGRAPHICACK="" ;;
 DOWNTIMEEND) BKCLR="0099FF" ;
    R_SUBJECT="has exited scheduled downtime" ;
    MIMEGRAPHICACK="" ;;
 DOWNTIMECANCELLED) BKCLR="0099FF" ;
    R_SUBJECT="had scheduled downtime cancelled" ;
    MIMEGRAPHICACK="" ;;
 TEST) BKCLR="FF66FF" ;
    MIMEGRAPHICACK="" ;;
 *) BKCLR="FF66FF" ;;
esac

# Host message prep
if [[ $1 == 'host' ]] ;
then {

# ---Section only used for alternative text message---
LASTHOSTDOWNTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTHOSTDOWN seconds"`
LASTHOSTUPTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTHOSTUP seconds"`
LASTHOSTUNREACHABLETIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTHOSTUNREACHABLE seconds"`

if [[ $LASTHOSTDOWNTIME == "Thu Jan  1 00:00:00 UTC 1970" ]] ; then LASTHOSTDOWNTIME="never" ; fi
if [[ $LASTHOSTUPTIME == "Thu Jan  1 00:00:00 UTC 1970" ]] ; then LASTHOSTUPTIME="never" ; fi
if [[ $LASTHOSTUNREACHABLETIME == "Thu Jan  1 00:00:00 UTC 1970" ]] ; then LASTHOSTUNREACHABLETIME="never" ; fi

case $NAGIOS_HOSTSTATE
in
 UP) R_TIMES="Last time this host was down: $LASTHOSTDOWNTIME
    Last time this host was unreachable: $LASTHOSTUNREACHABLETIME" ;;
 DOWN | UNREACHABLE) R_TIMES="Last time this host was up: $LASTHOSTUPTIME" ;;
 *) R_TIMES="Error: Unknown host state" ;;
esac
# ---END SECTION---

# Catch for Nagios 2.x variable difference
if [[ $NAGIOS_HOSTNOTIFICATIONNUMBER == "" && $NAGIOS_NOTIFICATIONNUMBER != "" ]] ;
then {
    NAGIOS_HOSTNOTIFICATIONNUMBER=$NAGIOS_NOTIFICATIONNUMBER
};
fi

if [[ $R_SUBJECT == "" ]] ;
then {
    R_SUBJECT="is $NAGIOS_HOSTSTATE ($NAGIOS_HOSTNOTIFICATIONNUMBER)"
};
fi

if [[ $NAGIOS_NOTIFICATIONTYPE == "ACKNOWLEDGEMENT" ]] ;
then {
    R_SUBJECT="$R_SUBJECT $NAGIOS_HOSTACKAUTHOR"
    R_ACKADD="<tr class='commentOdd'>
      <td class='commentOdd'>$NAGIOS_HOSTACKAUTHOR</td>
      <td class='commentOdd'>$NAGIOS_HOSTACKCOMMENT</td>
    </tr>"
};
elif [[ $NAGIOS_NOTIFICATIONTYPE == "PROBLEM" || $NAGIOS_NOTIFICATIONTYPE == "FLAPPINGSTART" ]] ;
then {
    R_ACKCOMMAND="<tr class='command'>
                      <td><img src='cid:ack.gif$CONTENTIDBASE' class='icon' alt='Acknowledge'></td>
                      <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=33&host=$NAGIOS_HOSTNAME'>Acknowledge this host problem</a></td>
                    </tr>"
};
fi

R_SUBJECT="Nagios Host Alert - $NAGIOS_HOSTNAME $R_SUBJECT"
R_NUMBER=$NAGIOS_HOSTNOTIFICATIONNUMBER
R_DESCRIPTION=$NAGIOS_HOSTALIAS
R_NOTES=$NAGIOS_HOSTNOTES
R_STATE=$NAGIOS_HOSTSTATE
R_OUTPUT=$NAGIOS_HOSTOUTPUT
R_ATTEMPT=$NAGIOS_HOSTATTEMPT
R_PERFDATA=$NAGIOS_HOSTPERFDATA
R_DURATION=$NAGIOS_HOSTDURATION
R_LATENCY=$NAGIOS_HOSTLATENCY
R_EXECUTION=$NAGIOS_HOSTEXECUTIONTIME
R_PERCENT=$NAGIOS_HOSTPERCENTCHANGE
R_LASTCHECK=`date --date="1970-01-01 UTC $NAGIOS_LASTHOSTCHECK seconds" "$DATEFORMAT"`
R_LASTSTATECHANGE=`date --date="1970-01-01 UTC $NAGIOS_LASTHOSTSTATECHANGE seconds" "$DATEFORMAT"`
R_COMMANDTAIL="&host=$NAGIOS_HOSTNAME"
R_COMMANDADD1="<tr class='command'>
                      <td><img src='cid:status3.gif$CONTENTIDBASE' class='icon' alt='map'></td>
                      <td class='command'><a href='$URLCGIBIN/statusmap.cgi?host=$NAGIOS_HOSTNAME'>Locate host on map</a></td>
                    </tr>"
R_COMMANDADD2="48"
R_COMMANDADD3="96"
R_COMMANDADD4="25"
R_COMMANDADD5="10"
R_COMMANDADD6="55"
R_COMMANDADD7="<tr class='command'>
                        <td><img src='cid:enabled.gif$CONTENTIDBASE' class='icon' alt='enabled'></td>
                        <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=28$R_COMMANDTAIL'>Enable notifications for all services on this host</a></td>
                      </tr>
                      <tr class='command'>
                        <td><img src='cid:delay.gif$CONTENTIDBASE' class='icon' alt='delay'></td>
                        <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=17$R_COMMANDTAIL'>Schedule a check of all services on this host</a></td>
                      </tr>
                      <tr class='command'>
                        <td><img src='cid:disabled.gif$CONTENTIDBASE' class='icon' alt='disabled'></td>
                        <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=16$R_COMMANDTAIL'>Disable checks of all services on this host</a></td>
                      </tr>
                      <tr class='command'>
                        <td><img src='cid:enabled.gif$CONTENTIDBASE' class='icon' alt='enabled'></td>
                        <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=15$R_COMMANDTAIL'>Enable checks of all services on this host</a></td>
                      </tr>"
R_COMMANDADD8="58"
R_COMMANDADD9="1"
};

# Service message prep
elif [[ $1 == 'service' ]] ;
then {

# ---Section only used for alterative text message---
LASTSERVICECRITICALTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTSERVICECRITICAL seconds"`
LASTSERVICEWARNINGTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTSERVICEWARNING seconds"`
LASTSERVICEOKTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTSERVICEOK seconds"`
LASTSERVICEUNKNOWNTIME=`date --universal --date="1970-01-01 UTC $NAGIOS_LASTSERVICEUNKNOWN seconds"`

if [[ $LASTSERVICECRITICALTIME == "Thu Jan  1 00:00:00 UTC 1970" ]] ; then LASTSERVICECRITICALTIME="never" ; fi
if [[ $LASTSERVICEWARNINGTIME == "Thu Jan  1 00:00:00 UTC 1970" ]] ; then LASTSERVICEWARNINGTIME="never" ; fi
if [[ $LASTSERVICEOKTIME == "Thu Jan  1 00:00:00 UTC 1970" ]] ; then LASTSERVICEOKTIME="never" ; fi
if [[ $LASTSERVICEUNKNOWNTIME == "Thu Jan  1 00:00:00 UTC 1970" ]] ; then LASTSERVICEUNKNOWNTIME="never" ; fi

case $NAGIOS_SERVICESTATE
in
 OK) R_TIMES="Last time this service was critical: $LASTSERVICECRITICALTIME
    Last time this service was warning: $LASTSERVICEWARNINGTIME
    Last time this service was unknown: $LASTSERVICEUNKNOWNTIME" ;;
 WARNING | UNKNOWN | CRITICAL) R_TIMES="Last time this service was ok: $LASTSERVICEOKTIME" ;;
 *) R_TIMES="Error: Unknown service state" ;;
esac
# ---END SECTION---

# Catch for Nagios 2.x variable difference
if [[ $NAGIOS_SERVICENOTIFICATIONNUMBER == "" && $NAGIOS_NOTIFICATIONNUMBER != "" ]] ;
then {
    NAGIOS_SERVICENOTIFICATIONNUMBER=$NAGIOS_NOTIFICATIONNUMBER
};
fi

if [[ $R_SUBJECT == "" ]] ;
then {
    R_SUBJECT="is $NAGIOS_SERVICESTATE ($NAGIOS_SERVICENOTIFICATIONNUMBER)"
};
fi

if [[ $NAGIOS_NOTIFICATIONTYPE == "ACKNOWLEDGEMENT" ]] ;
then {
    R_SUBJECT="$R_SUBJECT $NAGIOS_SERVICEACKAUTHOR"
    R_ACKADD="<tr class='commentOdd'>
      <td class='commentOdd'>$NAGIOS_SERVICEACKAUTHOR</td>
      <td class='commentOdd'>$NAGIOS_SERVICEACKCOMMENT</td>
    </tr>"
};
elif [[ $NAGIOS_NOTIFICATIONTYPE == "PROBLEM" || $NAGIOS_NOTIFICATIONTYPE == "FLAPPINGSTART" ]] ;
then {
    R_ACKCOMMAND="<tr class='command'>
                      <td><img src='cid:ack.gif$CONTENTIDBASE' class='icon' alt='acknowledge'></td>
                      <td class='command'><a href='$URLCGIBIN/cmd.cgi?cmd_typ=34&host=$NAGIOS_HOSTNAME&service=$NAGIOS_SERVICEDESC'>Acknowledge this service problem</a></td>
                    </tr>"
};
fi


#R_SUBJECT="Nagios Service Alert - $NAGIOS_SERVICEDESC on $NAGIOS_HOSTNAME $R_SUBJECT"
R_SUBJECT="$NAGIOS_SERVICEDESC on $NAGIOS_HOSTNAME $R_SUBJECT"
R_NUMBER=$NAGIOS_SERVICENOTIFICATIONNUMBER
R_DESCRIPTION=$NAGIOS_SERVICEDESC
R_STATE=$NAGIOS_SERVICESTATE
R_OUTPUT=$NAGIOS_SERVICEOUTPUT
R_ATTEMPT=$NAGIOS_SERVICEATTEMPT
R_LINKBOX_ADD="<a href='$URLCGIBIN/extinfo.cgi?type=1&host=$NAGIOS_HOSTNAME'>View Information For This Host</a><br>"
R_LINKBOXLINK_ADD="&service=$NAGIOS_SERVICEDESC"
R_TITLE_ADD="<div class='data'>On Host</div>"
R_NOTES=$NAGIOS_SERVICENOTES
R_PERFDATA=$NAGIOS_SERVICEPERFDATA
R_DURATION=$NAGIOS_SERVICEDURATION
R_LATENCY=$NAGIOS_SERVICELATENCY
R_EXECUTION=$NAGIOS_SERVICEEXECUTIONTIME
R_PERCENT=$NAGIOS_SERVICEPERCENTCHANGE
R_LASTCHECK=`date --date="1970-01-01 UTC $NAGIOS_LASTSERVICECHECK seconds" "$DATEFORMAT"`
R_LASTSTATECHANGE=`date --date="1970-01-01 UTC $NAGIOS_LASTSERVICESTATECHANGE seconds" "$DATEFORMAT"`
R_COMMANDTAIL="&host=$NAGIOS_HOSTNAME&service=$NAGIOS_SERVICEDESC"
R_COMMANDADD2="6"
R_COMMANDADD3="7"
R_COMMANDADD4="23"
R_COMMANDADD5="9"
R_COMMANDADD6="56"
R_COMMANDADD8="60"
R_COMMANDADD9="3"
MIMEGRAPHIC1=""
MIMEGRAPHIC2=""
};

# Catch for bad argument
else {
   echo "ERROR: Invalid argument.  Must be 'host' or 'service'"
   exit -1
};
fi

# Included for browser compatability problems with CSS text-transform: capitalize
NAGIOS_NOTIFICATIONTYPE=`echo $NAGIOS_NOTIFICATIONTYPE | python -c "print raw_input().capitalize()"`
set -- `echo $1 | python -c "print raw_input().capitalize()"`

# Message generation
#  NOTE: All of the "R_" variables change when either 'host' or 'service' is selected
MSG=`echo "From: $REPLYADDRESS
Reply-To: $REPLYADDRESS
To: $NAGIOS_CONTACTALIAS <$NAGIOS_CONTACTEMAIL>
Subject: $R_SUBJECT
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=$MIMEBOUNDARY1

--$MIMEBOUNDARY1
Content-Type: text/plain; charset=us-ascii

$R_DESCRIPTION ($NAGIOS_HOSTNAME @ $NAGIOS_HOSTADDRESS) is $R_STATE,
Nagios reports: $R_OUTPUT,
This $1 has been $R_STATE for $R_ATTEMPT consecutive attempts,
$R_TIMES

--$MIMEBOUNDARY1
Content-Type: multipart/related; boundary=$MIMEBOUNDARY2; type=text/html

--$MIMEBOUNDARY2
Content-Type: text/html; charset=us-ascii
Content-Description: HTML message
Content-ID: <html$CONTENTIDBASE>

<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
            \"http://www.w3.org/TR/html4/strict.dtd\">
<html>
<head>
<title>Nagios Notification</title>
<meta http-equiv='Content-Type' content='text/html; charset=us-ascii'>
<style type='text/css'>

/* Modified styles from Nagios extinfo.css style sheet */
BODY { font-family: arial,sans-serif;  background-color: white;  color: black;  font-size: 10pt; }
.linkBox { font-size: 8pt;  background-color: #DBDBDB;  padding: 1px; }
DIV.dataTitle { text-align: center;  font-weight: bold;  font-size: 12pt; }
DIV.data { text-align: center;  font-size: 12pt; }
TABLE.data { font-size: 10pt;  background-color: white;  padding: 2px; }
TH.data { font-size: 10pt;  background-color: white;  text-align: left;  background-color: #999797;  color: #DCE5C1; }
.commandTitle { text-align: center;  font-weight: bold;  font-size: 12pt; }
TABLE.command { font-size: 10pt;  background-color: #DBDBDB;  padding: 2px; }
.command { font-size: 10pt; text-align: left; }
.commentTitle { text-align: center;  font-weight: bold;  font-size: 12pt; }
TABLE.comment { font-size: 10pt;  background-color: white;  padding: 2px; }
TH.comment { font-size: 10pt;  background-color: white;  text-align: left;  background-color: #999797;  color: #DCE5C1; }
.commentOdd { font-size: 9pt;  background-color: #DBDBDB; }
.commentEven { font-size: 9pt;  background-color: #C4C2C2; }
DIV.comment,A.comment { font-size: 10pt;  background-color: white;  text-align: center; }
.notflapping { font-size: 10pt;  text-align: left;  background-color: #33FF00;  font-weight: bold; float: left; }
.flapping { font-size: 10pt;  text-align: left;  background-color: #F83838;  font-weight: bold; float: left; }
.HostUP { font-size: 10pt;  text-align: left;  background-color: #33FF00;  font-weight: bold; float: left; }
.HostDOWN { font-size: 10pt;  text-align: left;  background-color: #F83838;  font-weight: bold; float: left; }
.HostUNREACHABLE { font-size: 10pt;  text-align: left;  background-color: #F83838;  font-weight: bold; float: left; }
.ServiceOK { font-size: 10pt;  text-align: left;  background-color: #33FF00;  font-weight: bold; float: left; }
.ServiceWARNING { font-size: 10pt;  text-align: left;  background-color: #FFFF00;  font-weight: bold; float: left; }
.ServiceUNKNOWN { font-size: 10pt;  text-align: left;  background-color: #FF9900;  font-weight: bold; float: left; }
.ServiceCRITICAL { font-size: 10pt;  text-align: left;  background-color: #F83838;  font-weight: bold; float: left; }
.commandPanel { background-color: white; text-align: center; vertical-align: top; }
.commentPanel { background-color: white; text-align: center; vertical-align: top; }
.stateInfoPanel { background-color: white; vertical-align: top; }
.stateInfoTable1 { font-size: 10pt;  background-color: #DBDBDB; text-align: left; }
.dataVar { font-size: 10pt; }
.dataVal { font-size: 10pt; }
/* End Copy */

/* a { text-decoration: none; }
a:hover { text-decoration: underline; } */
h1 { font-family: Garamond,'Times New Roman',serif; text-align: center; vertical-align: bottom; text-transform: capitalize; }
span.caps { text-transform: capitalize; }
.notif { background-color: #$BKCLR; }
.address { font-size: 10.0pt; font-style: italic; }
table.center { margin-left: auto; margin-right: auto; }
.fullwidth { width: 100%; }
.border { border-style: ridge; border-width: 2px; }
.border-thick { border-style: ridge; border-width: 3px; }
.noborder { border-style: none; }
.nopad { border-spacing: 0px; padding: 0px; }
td.onethirdl { text-align: left; vertical-align: top; width: 33%; }
td.onethirdc { text-align: center; vertical-align: middle; width: 33%; }
td.onethirdr { text-align: right; vertical-align: bottom; width: 33%; }
td.rightpanel { text-align: center; vertical-align: top; }
td.vcenter { vertical-align: middle; }
img.icon { border-style: none; border-width: 0px; height: 20px; width: 20px; }

</style>
</head>
<body>
<table class='center noborder' align='center'>
	<tr>
		<td class='notif'>
    	&nbsp;
		</td>
	</tr>
	<tr>
		<td>
			<h1><a href='$URLPATH'>Nagios</a> $NAGIOS_NOTIFICATIONTYPE Notification</h1>
		</td>
	</tr>
	<tr>
		<td class='notif'>
    	&nbsp;
		</td>
	</tr>
</table>

<div class='data'>
    <span class='caps'>$1</span>
</div>
<div class='dataTitle'>
    $R_DESCRIPTION
</div>
$R_TITLE_ADD
<div class='dataTitle'>
    <a href='$URLCGIBIN/status.cgi?host=$NAGIOS_HOSTNAME'>$NAGIOS_HOSTNAME</a>&nbsp;<a href='$NAGIOS_HOSTACTIONURL'>$NAGIOS_HOSTADDRESS</a>
</div>
<br>
<div class='dataTitle'>
	<span class='caps'>$1</span> State Information
</div>
	  
<table class='center noborder' align='center'>
	<tr>
		<td>
            <table cellspacing='0' class='center nopad border' border='2' align='center'>
				<tr>
					<td class='stateInfoTable1'>
						<table class='noborder' align='center'>
							<tr>
								<td class='dataVar'>Current Status:</td>
								<td class='dataVal'>
								<span class='$1$R_STATE'>
								&nbsp;&nbsp;$R_STATE&nbsp;&nbsp;$STATUSACK
								</span>
								&nbsp;(for $R_DURATION)
								</td>
							</tr>
							<tr>
								<td class='dataVar'>Status Information:</td>
								<td class='dataVal'>$R_OUTPUT</td>
							</tr>
							<tr>
								<td class='dataVar'>Check attempts:</td>
								<td class='dataVal'>$R_ATTEMPT</td>
							</tr>
							<tr>
								<td class='dataVar'>Last Check Time:</td>
								<td class='dataVal' nowrap='nowrap'>$R_LASTCHECK</td>
							</tr>
							<tr>
								<td class='dataVar' nowrap='nowrap'>Check Latency / Duration:</td>
								<td class='dataVal' nowrap='nowrap'>$R_LATENCY&nbsp;/&nbsp;$R_EXECUTION seconds</td>
							</tr>
							<tr>
								<td class='dataVar'>Last State Change:</td>
								<td class='dataVal' nowrap='nowrap'>$R_LASTSTATECHANGE</td>
							</tr>
							<tr>
								<td class='dataVar'>Current Notification Number:</td>
								<td class='dataVal'>$R_NUMBER</td>
							</tr>
							<tr>
								<td class='dataVar'>Is This <span class='caps'>$1</span> Flapping?</td>
								<td class='dataVal'>
								<span class='$FLAPPINGCLASS'>
								&nbsp;&nbsp;$FLAPPING&nbsp;&nbsp;
								</span>
									&nbsp;($R_PERCENT% state change)
								</td>
							</tr>
						</table>
					</td>
				</tr>
            </table>
		</td>
	</tr>
</table>

<table class='center' align='center'>
	<tr>
		<td colspan='2' class='commentPanel'>
		<div class='commentTitle'>
			<span class='caps'>$1</span> Comments
		</div>
		<table class='comment border-thick' border='3'>
			<tr class='comment'>
				<th class='comment'>Author</th>
				<th class='comment'>Comment</th>
			</tr>
			<tr>
				<td></td>
				<td>$NAGIOS_HOSTNAME
				$NAGIOS_SERVICEDESC
				Kommentar: $KOMMENTAR
				$R_ACKADD
				</td>
			</tr>
		</table>
		</td>
	</tr>
</table>
<p class='address'>All information is the property of <a href='mailto:$REPLYADDRESS'>$REPLYNAME</a><br>
  and should be treated as confidential</p>
</body>
</html>


--$MIMEBOUNDARY2--
--$MIMEBOUNDARY1--"`

[ "$MSG" ] || {
   echo "Error generating e-mail message."
   exit -1
}

# Send the damn e-mail already!
$PRINTF "%b" "$MSG" | $MAILER $MAILOPTS

exit
Es geht um die Variable KOMMENTAR. Wie man sieht wird das aus diesen beiden Variablen zuammengebaut. $NAGIOS_HOSTNAME und $NAGIOS_SERVICEDESC. Diese werden auch korrekt ausgegeben. Auch wenn ich den befehl:

/usr/bin/printf 'GET comments\nColumns: comment\nFilter: host_name = $NAGIOS_HOSTNAME\nFilter: service_description = $NAGIOS_SERVICEDESC\n' | /usr/local/bin/unixcat /tmp/live.sock

in meiner konsole ausführe auf dem server auf dem nagios läuft erhalte ich einen sinnvollen wert. aber wird von nagios nun eine notification verschickt mit diesem script ist KOMMENTAR leer. Ich suche schon seit einer halben ewigkeit nach dem fehler aber ich kann ihn nicht finden.

Ichmuss datzu sagen das ich die variable zusätzlich eingefügt habe und das nicht das original von mgothard ist.

wer weiss rat?

gruesse rene
Zuletzt geändert von rene04 am 10.06.2010 16:51:50, insgesamt 1-mal geändert.

Benutzeravatar
maieutike
Beiträge: 121
Registriert: 14.03.2010 14:43:16
Lizenz eigener Beiträge: MIT Lizenz
Wohnort: Leipzig
Kontaktdaten:

Re: problem mit variable in script

Beitrag von maieutike » 09.06.2010 22:14:30

Eventuell liegt es am Escaping.

Du kannst mit bash -x dir die Ausführung des Scripts anschauen. Vllt. ergibt sich da was ...

http://tldp.org/LDP/Bash-Beginners-Guid ... 02_03.html

Benutzeravatar
rene04
Beiträge: 1751
Registriert: 26.08.2004 08:46:39
Wohnort: Kaiserslautern

Re: problem mit variable in script

Beitrag von rene04 » 10.06.2010 12:21:42

hi,

wenn ich hier:

Code: Alles auswählen

KOMMENTAR="$(/usr/bin/printf 'GET comments\nColumns: comment\nFilter: host_name = $NAGIOS_HOSTNAME\nFilter: service_description = $NAGIOS_SERVICEDESC\n' | /usr/local/bin/unixcat  /tmp/live.sock)"
statt $NAGIOS_HOSTNAME und $NAGIOS_SERVICEDESC feste werte eintrage dann funktioniert es. das finde ich merkwürdig denn die beiden Variablen haben werte. sie werden ja auch ausgegeben an dieser stelle:

Code: Alles auswählen

<tr>
            <td></td>
            <td>$NAGIOS_HOSTNAME
            $NAGIOS_SERVICEDESC
            Kommentar: $KOMMENTAR
            $R_ACKADD
            </td>
         </tr>
siehe:

XXXX_LB_xxxx_backend
[URL] XXXX_LB_xxxx_backend - LB
Kommentar:

ich verstehs nicht :(

gruesse rene

Benutzeravatar
heinz
Beiträge: 535
Registriert: 20.12.2007 01:43:49

Re: problem mit variable in script

Beitrag von heinz » 10.06.2010 14:56:06

Hallo rene04,

habs jetzt nicht getestet aber sollte es nicht eher so (oä) aussehen?
KOMMENTAR=$(/usr/bin/printf 'GET comments\nColumns: comment\nFilter: host_name = %s\nFilter: service_description = %s\n' "$NAGIOS_HOSTNAME" "$NAGIOS_SERVICEDESC"| /usr/local/bin/unixcat /tmp/live.sock)
printf 'Der int Wert ist %i und das ist ein Text: %s\n' 10 "der Text"

gruß heinz

Benutzeravatar
rene04
Beiträge: 1751
Registriert: 26.08.2004 08:46:39
Wohnort: Kaiserslautern

Re: problem mit variable in script

Beitrag von rene04 » 10.06.2010 16:51:26

hallo heinz,

genau so ist es. vielen dank, es funktioniert.

gruesse rene

Antworten