Nagios email – Customize Nagios Notifications

Nagios - Customize your Nagios notifications

Add more info to your Nagios notifications

I finally got tired of getting Nagios notifications that didn’t have all the info I wanted in them. Specifically, I was guessing if the problem had been acknowledged based on the notification interval (how long since I received the last notification), or logging in to Nagios to check.
I decided to customize the Nagios email notifications by editing the # 'host-notify-by-email' command definition, which is the notification type that I’ve been using.

Before, the # 'host-notify-by-email' command definition looked like this:

command[host-notify-by-email]=/bin/echo -e "***** Nagios *****nnHost "$HOSTALIAS$" is $HOSTSTATE$!nn$HOSTADDRESS$nnDate/Time: $DATETIME$n" | /bin/mail -s 'Host $HOSTNAME$ is $HOSTSTATE$!' $CONTACTEMAIL$

which produced a notification that simply included the hostname, the state, and the date/time. I hopped on over to the Nagios Macros page at Sourceforge and grabbed what I wanted, then edited the # 'host-notify-by-email' command definition as follows:

# 'host-notify-by-email' command definition
define command{

     command_name host-notify-by-email
command_line /bin/echo -e "***** Nagios *****nnThis is a $NOTIFICATIONTYPE$ notice that "$HOSTALIAS$" is $HOSTSTATE$!nnHost IP is $HOSTADDRESS$nnDuration is $HOSTDURATION$nnDate/Time: $LONGDATETIME$nnhttp://nagios.mydomain.com/nagios/nnnNagios SummarynTotal Unhandled Host Problems:$TOTALHOSTPROBLEMSUNHANDLED$nTotal Unhandled Service Problems:$TOTALSERVICEPROBLEMSUNHANDLED$" | /bin/mail -s 'Host $HOSTNAME$ is $HOSTSTATE$!' $CONTACTEMAIL$
}

Now my Nagios email notifications look like this:

***** Nagios *****

This is a PROBLEM notice that DevServer is DOWN!

Host IP is 192.168.1.100

Duration is 0d 0h 0m 0s

Date/Time: Tue Aug 3 13:19:25 PDT 2010

http://nagios.mydomain.com/nagios/

Nagios Summary
Total Unhandled Host Problems:1
Total Unhandled Service Problems:0

The “This is a PROBLEM notice” part is created by the $NOTIFICATIONTYPE$ macro. This is nice because it tells you what kind of notification it is (“PROBLEM”, “RECOVERY”, “ACKNOWLEDGEMENT”, “FLAPPINGSTART”, “FLAPPINGSTOP”, “FLAPPINGDISABLED”, “DOWNTIMESTART”, “DOWNTIMEEND”, or “DOWNTIMECANCELLED”), which is much more useful than just getting another DOWN notice when a problem is acknowledged.

Check out my other Nagios posts, and please leave a comment if you have another tip or trick on customizing your Nagios notifications.

Share

Linux Disk Space Alerts – Cron’d Shell Script

The following steps are for setting up an email notification to alert you of low disk space on *nix boxes.

1) Write a script. I modified a script that I found at nixCraft that checks disk space and sends an email if the used space is above a specified percentage. I made some adjustments to that script, here is what I am using:


#!/bin/sh
# Shell script to monitor or watch the disk space
# It will send an email to $ADMIN, if the used percentage
# of space is >= 90%
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# ----------------------------------------------------------------------
# Linux shell script to watch disk space (should work on other UNIX oses )
# SEE URL: http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html
# set admin email so that you can get email
ADMIN="mailto:me@mydomain.com"
# set alert level 90% is default
ALERT=90
df -HP | grep -vE '^Filesystem|tmpfs|cdrom' |
  while read partition size used free perc mnt ;
  do
    usep=$(echo $perc | tr -d '%' )
    if [ $usep -ge $ALERT ]; then
      echo "Running out of space "$partition ($usep%)" on $(hostname) as
  on $(date)" |
       mail -s "Alert: Almost out of disk space - $usep%" $ADMIN
    fi
  done

2) Create a cron job. I simply copied the script into /etc/cron.hourly and set the permissions (chmod +x /etc/cron.hourly/diskalertscript). Alternatively, you can add it to crontab to further customize when it runs:
crontab -e
10 0 * * * /path/to/diskalertscript

Share

Configuring System Alerts in Windows Server 2003

Create an Alert in System Monitor to Track Free Disk Space

1. Click Start, point to Administrative Tools, and then click Performance.
2. Expand Performance Logs and Alerts.
3. Right-click Alerts, and then click New Alert Settings.
4. In the New Alert Settings box, type a name for the new alert (for example, Free disk space), and then click OK.

The AlertName dialog box appears, in which you configure settings for the alert that you created.
5. Click the General tab, and then in the Comment box, type something like Monitors free disk space on C drive.

Windows Alerts - Low Disk Space Alert

Configure the Alert

1. Click Add to open the Add Counters dialog box.
2. Click Select counters from computer, and then select your computer in the list.
3. In the Performance object box, click LogicalDisk.
4. Click Select counters from list, and then click % Free Space.
5. Click Select interfaces from list, and then click the logical drive or volume that you want to monitor.
6. Click Add to add the counter, and then click Close.
7. In the Alert when the value is box, click Under, and then type the value that you want in the Limit box. For example, to trigger an alert message when free disk space is under 9%, type 9.
8. Accept the default value of 5 seconds in the Sample data interval, or specify the value that you want.
9. Click Apply.
10. Click the Action tab, and then specify the action or actions that you want to perform when an alert occurs, as follows:

  •  If you want the Performance Logs and Alerts service to create an entry in the application log of event viewer when an alert occurs, click to select the Log an entry in the application event log check box.
  • If you want the Performance Logs and Alerts service to trigger the Messenger service to send a message, click to select the Send a network message to check box, and then type the IP address or name of the computer on which the alert should be displayed.
  • To run a counter log when an alert occurs, click to select the Start performance data log check box, and then specify the counter log that you want to run.
  • To run a command or program when an alert occurs, click to select the Run this program check box, and then type the file path and name of the program or command that you want to run. Or, click Browse to locate the file.

When an alert occurs, the service creates a process and runs the specified command file. The service also copies any command-line arguments that you define to the command line that is used to run the file. Click Command Line Arguments, and then click to select the appropriate check boxes to include the arguments that you want to implement when the program is run.
11. Click Apply.
12. Click the Schedule tab, and then specify the start and stop parameters for the scan, as follows:
          1. Under Start scan, do one of the following:

  • Click Manually if you want to manually start the scan. After you select this option, right-click the alert in the right pane, and then click Start to start the scan.
    • Click At to start the scan at a specific time and date, and then specify the time and date that you want.

              2. Under Stop scan, do one of the following:

    • Click Manually if you want to manually stop the scan. After you click this option, right-click the alert in the right pane, and then click Stop to stop the scan.
    • Click After to stop the scan after a specified duration, and then specify the time interval that you want.
    • Click At to stop the scan at a specific time and date, and then specify the time and date that you want.

              3. If you want to start a new scan after the alert scan is complete, click After, and then click to select the Start a new scan check box.

    Taken (and then edited) from the Microsoft KB

    Share