no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | addons:messaging.sh [2009/12/17 11:26] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== messaging.sh ====== | ||
| + | |||
| + | ^ Author | [[ stuart@carmichael.net.au | Stuart Carmichael ]] | | ||
| + | ^ Compatibility | Xymon 4.2 | | ||
| + | ^ Requirements | linux/unix | | ||
| + | ^ Download | See Source, below | | ||
| + | ^ Last Update | 2009-12-16 | | ||
| + | |||
| + | ===== Description ===== | ||
| + | I want a way to message the sysadmin of my server. The message might be a | ||
| + | status message from a backup (success/ | ||
| + | It could be a reminder to myself (" | ||
| + | |||
| + | The way I have implemented this is as separate text files in a messaging | ||
| + | directory. When an automated job/ | ||
| + | the $MESSAGEDIR, | ||
| + | column. There may be any number of messages in the messaging directory | ||
| + | (the highest priority message will be the status of the entire group for | ||
| + | this host). A keyword ' | ||
| + | of the message. | ||
| + | |||
| + | This script continually monitors the $MESSAGEDIR, | ||
| + | details from Xymon once the message files themselves have been dealt with | ||
| + | (for example: automatically via a cron job; manually deleted/ | ||
| + | the issue has been dealt with). | ||
| + | |||
| + | If no messages appear in $MESSAGEDIR, | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== Installation ===== | ||
| + | This is a client side script. The following must be completed on all Xymon client which you | ||
| + | |||
| + | want to send messages to the server. | ||
| + | |||
| + | 1. Copy the script (see below, Source Code) into the Client' | ||
| + | |||
| + | 2. Update the client' | ||
| + | |||
| + | < | ||
| + | [messaging] | ||
| + | ENVFILE $HOBBITCLIENTHOME/ | ||
| + | CMD $HOBBITCLIENTHOME/ | ||
| + | LOGFILE $HOBBITCLIENTHOME/ | ||
| + | INTERVAL 5m | ||
| + | </ | ||
| + | |||
| + | 3. (optional) review the messaging.sh script, and change the location of $MESSAGEDIR to somewhere more appropriate to your server (default is / | ||
| + | |||
| + | 4.Create the $MESSAGEDIR directory. Ensure the xymon user can read files in this directory | ||
| + | |||
| + | |||
| + | Script will create “messaging” alerts of the appropriate severity level when text files are created in the $MESSAGEDIR directory. The first word on the first line of each text message file defines the severity level. Severity levels can be one of: green, yellow, red. Any other severity level is assumed to mean ' | ||
| + | |||
| + | ===== Source ===== | ||
| + | ==== messaging.sh ==== | ||
| + | |||
| + | Download and save the attached code into your client' | ||
| + | |||
| + | <hidden onHidden=" | ||
| + | < | ||
| + | #!/bin/sh | ||
| + | # messaging.sh - script to look for status messages posted into | ||
| + | # $MESSAGEDIR and report to Xymon. | ||
| + | # | ||
| + | # See comments at end of file for installation instructions | ||
| + | # | ||
| + | # Messages posted into $MESSAGEDIR are simple text files in the form of: | ||
| + | # Filename - name of test/class | ||
| + | # Contents of file: | ||
| + | # Field 1: Keyword RED YELLOW GREEN indicating severity | ||
| + | # Remainder of line 1: Status message to display | ||
| + | # Based on example script at http:// | ||
| + | # Restrictions: | ||
| + | # 1. message filename cannot contain spaces | ||
| + | # 2. First word of the message file must be ' | ||
| + | # If this condition is not met, ' | ||
| + | # 3. The ' | ||
| + | # 4. If $MESSAGEDIR does not exist, this script attempts to create it. The ' | ||
| + | # MUST have write access to the directory above $MESSAGEDIR in this case, or the directory | ||
| + | # | ||
| + | # | ||
| + | # Author: Stuart Carmichael stuart at carmichael dot net dot au | ||
| + | # Date: 16/12/09 v0.1 Initial version | ||
| + | # Modifications: | ||
| + | # | ||
| + | |||
| + | MESSAGEDIR=/ | ||
| + | COLUMN=messaging # | ||
| + | STAT_COLOR=clear # | ||
| + | export MSG="" | ||
| + | export LINE="" | ||
| + | |||
| + | |||
| + | |||
| + | # Create the $MESSAGEDIR if it does not exist | ||
| + | if [ ! -d $MESSAGEDIR ]; then | ||
| + | mkdir -p $MESSAGEDIR | ||
| + | fi | ||
| + | |||
| + | # Look for regular files in $MESSAGEDIR and process: | ||
| + | |||
| + | for msgfile in `ls $MESSAGEDIR`; | ||
| + | if [ " | ||
| + | STAT_COLOR=green # If I made it here, there must be message files. default colour is green | ||
| + | fi | ||
| + | |||
| + | if [ -f " | ||
| + | |||
| + | COLOR=" | ||
| + | |||
| + | # convert $COLOR to lowercase for consistency: | ||
| + | COLOR=" | ||
| + | |||
| + | case $COLOR in | ||
| + | green) | ||
| + | linestat=" | ||
| + | ;; | ||
| + | yellow) | ||
| + | linestat=" | ||
| + | ;; | ||
| + | *) | ||
| + | COLOR=" | ||
| + | linestat=" | ||
| + | ;; | ||
| + | esac | ||
| + | |||
| + | # calculate the final STAT_COLOR: | ||
| + | # if [ " | ||
| + | # | ||
| + | # fi | ||
| + | |||
| + | if [ " | ||
| + | if [ " | ||
| + | STAT_COLOR=" | ||
| + | fi | ||
| + | fi | ||
| + | |||
| + | if [ " | ||
| + | if [ " | ||
| + | STAT_COLOR=" | ||
| + | fi | ||
| + | if [ " | ||
| + | STAT_COLOR=" | ||
| + | fi | ||
| + | fi | ||
| + | # otherwise the STAT_COLOR stays green | ||
| + | |||
| + | # now form the status display: | ||
| + | # The status display is 2 parts: | ||
| + | # 1. A summary of all the message files found, including red/ | ||
| + | # and a brief status message (the $LINE variable) | ||
| + | # 2. detailed output containing the text of all the message files found | ||
| + | # (the $MSG variable) | ||
| + | LINE=" | ||
| + | & | ||
| + | |||
| + | MSG=" | ||
| + | <Font Size=+1>< | ||
| + | `cat ${MESSAGEDIR}/ | ||
| + | " | ||
| + | |||
| + | fi # end if [ -f ${messagefile} ] | ||
| + | |||
| + | done | ||
| + | # Putting it all together: | ||
| + | LINE=" | ||
| + | ${LINE} | ||
| + | |||
| + | " | ||
| + | if [ " | ||
| + | LINE=" | ||
| + | |||
| + | No messaging to report" | ||
| + | else | ||
| + | LINE=" | ||
| + | |||
| + | <Font Size=+2>< | ||
| + | <Font Size=-1> Contents of ${MESSAGEDIR} on ${MACHINE} </Font Size> | ||
| + | ${MSG} | ||
| + | " | ||
| + | fi | ||
| + | # Tell Xymon about it | ||
| + | |||
| + | # Debugging: uncomment the following line & comment out the $BB line to run interactively | ||
| + | # echo $LINE | ||
| + | $BB $BBDISP " | ||
| + | |||
| + | exit 0 | ||
| + | |||
| + | # ======================================================== | ||
| + | # Installation Instructions | ||
| + | # | ||
| + | This is a client side script. The following must be completed on amm Xymon client which you | ||
| + | want to send messages to the server. | ||
| + | 1. Copy this scriot into the Client' | ||
| + | 2. Update the client' | ||
| + | [messaging] | ||
| + | ENVFILE $HOBBITCLIENTHOME/ | ||
| + | CMD $HOBBITCLIENTHOME/ | ||
| + | LOGFILE $HOBBITCLIENTHOME/ | ||
| + | INTERVAL 5m | ||
| + | 3. (optional) review the messaging.sh script, and change the location of $MESSAGEDIR to somewhere more | ||
| + | | ||
| + | 4. Create the $MESSAGEDIR directory. Ensure the xymon user can read files in this directory | ||
| + | |||
| + | How it works: | ||
| + | Any text file created in $MESSAGEDIR is read by the script and becomes a ' | ||
| + | The first word of the first line determines the status/ | ||
| + | ' | ||
| + | Status keywords are case-insensitive. | ||
| + | |||
| + | Once this script has detected a message file in $MESSAGEDIR, | ||
| + | severity. The text included in the mesage file is displayed in the detail section of the alert. | ||
| + | |||
| + | No files in the $MESSAGEDIR sets the server status to ' | ||
| + | |||
| + | Alerts are cleared from the server once the message files have been delt with. This might be a manual operation | ||
| + | of changing the status within the file to ' | ||
| + | apprach (eg a cron job removing all files in $MESSAGEDIR at midnight. | ||
| + | |||
| + | Typical application: | ||
| + | Nightly backup completes. The script controlling the backup writes the final exit status of the backup | ||
| + | to $MESSAGEDIR/ | ||
| + | Optionally text can follow this which might give additional information (320GB backed up in 42 minutes. completed at 02:45AM) | ||
| + | |||
| + | Once the above file is readable by the xymon client user, the details are sent to the server, and the appropriate status | ||
| + | is set against this client. | ||
| + | |||
| + | If the status is red, the messaging status will flash red until the condition is rectified. | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Known Bugs and Issues ===== | ||
| + | |||
| + | ===== To Do ===== | ||
| + | |||
| + | ===== Credits ===== | ||
| + | |||
| + | ===== Changelog ===== | ||
| + | |||
| + | * **2009-12-16** | ||
| + | * Initial release | ||