寻找有关为Xymon监控服务器制作的ControlByWeb温度监控器的预制脚本的帮助。我一步一步地按照说明操作。未生成列“cbwtemp”。目前runnimg xymon 4.3.12使用此脚本http://www.revpol.com/files/xymon_cbw_temp.sh不确定新xymon服务器上的编码是否发生了更改,导致脚本无法正常运行。我检查了日志,没有与脚本有关的错误。 这是脚本:
#!/bin/bash
#
# NAME
# ----
# - xymon_cbw_temp.sh
#
# DESCRIPTION
# -----------
# - Simple Bash shell script to monitor from 1 to 4 temperature readings
# from a ControlByWeb 4-temp/2-relay module and the X-300 8-temp/3-relay
# 7-day programmable thermostat module and report status and
# temperature readings back to a Xymon server
#
# - The most current version of this script may be
# found at http://www.revpol.com/xymon_cbw_temp_script
#
# - Instructions to integrate the output of this script to be monitored
# and graphed by a Xymon server may also be found at the above URL
#
# - If you find this script useful, I'd love to know. Send me an email!
#
# William A. Arlofski
# Reverse Polarity, LLC
# 860-824-2433 Office
# http://www.revpol.com/
#
# HISTORY
# -------
# - 20100307 - Initial version release
#
# - 20100318 - Minor modifications to also work with the new
# X-300 (8-temp & thermostat) module
# - Increased the curl timeout from 3 to 10 seconds
#
# - 20100319 - Modifications to deal with a situation where a temperature
# sensor stops communicating with the module. Modified 2nd
# grep in getcurtemp() module and added testcomm() function to
# see if the current temp is "xx.x" and flag CURCOLOR and COLOR
# as red if yes
#
# - 20100322 - Added "ADMINMSG" variable to allow for an administrative
# messages to be added to the top of the report
#
# - 20100408 - Minor errors in grammar fixed
#
# - 20100520 - Modification to getcurtemp() function to catch cases where the
# whole number portion of the temperature was a single digit.
#
# - 20101014 - Added a "SCALE" variable for display output. Enter an "F" or a
# "C" to match the scale setting in your temperature module
# - Added "SCALE" variable to the end of all temperature variables
# - Rewrote the parsezone() function to add individual sensor
# information to the report via a new "ZONEMSG" variable. This
# will help end users understand why a particular sensor is in
# yellow or red condition without having to check the "ZONE"
# variable in this script
# - Renamed "HOST" variable to "MODULE" throughout script
# - Modified the default "ADMINMSG" variable to use "MACHINEDOTS"
# and "MODULE" variables as an example
# - Added the "ZONEMSG" to become part of the "MSG" variable that is
# returned to the Xymon server
# - Quoted a few more strings
#
# - 20130502 - Spelling errors, general cleanup (extra spaces etc), note that
# $HOST can be host[:port]
#
###############################################################################
#
# Copyright (C) 2010 William A. Arlofski - waa-at-revpol-dot-com
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# or visit http://www.gnu.org/licenses/gpl.txt
#
###############################################################################
#
# Set some variables
# ------------------
# Local System Binaries
# ---------------------
GREP="/bin/grep"
TR="/usr/bin/tr"
CURL="/usr/bin/curl"
# Location/device specific variables
# ----------------------------------
#
# FQDN or IP address of the ControlByWeb
# temperature monitor to pull data from
# and user login and password
# (User should be blank)
#---------------------------------------
MODULE="host.example.com:80"
USER=""
PASS="password"
# Name of Xymon test
# ------------------
COLUMN="cbwtemp"
# Define the temperature zone(s) to monitor
# -----------------------------------------
# Format is as follows:
#
# ZONE="Sensor#:TestType:Location:WarnTmp1:CritTmp1:[WarnTmp2:CritTmp2] \
# [ Sensor#:TestType:Location:WarnTmp:CritTmp:[WarnTmp2:CritTmp2] ...]"
#
# Where the fields are as follows:
# - Sensor : The sensor number from 1 to 4
# - TestType : The type of test: UP, DOWN, RANGE, IGNORE.
# If TestType is RANGE, WarnTmp2 and CritTmp2 are required
# If TestType is IGNORE, then only Sensor:TestType:Location are required
# - Location : The name of the location - Must match your Xymon definitions
# - WarnTmp1 : The value at which to set test COLOR and alert to yellow for UP or DOWN tests
# For RANGE test types, this value is used as if the test were a DOWN test
# - CritTmp1 : The value at which to set test COLOR and alert to red for UP or DOWN tests
# For RANGE test types, this value is used as if the test were a DOWN test
# - WarnTmp2 : Only used for RANGE type tests. The value at which to set test COLOR
# to yellow as temperature increases
# - CritTmp2 : Only used for RANGE type tests. The value at which to set test COLOR
# to red as temperature increases
#
#
# The ControlByWeb temperature monitor
# supports up to four temperature sensors
# and reports the temperature as XX.Y in
# either Celsius or Fahrenheit
# ---------------------------------------
#ZONES="1:UP:ServerRoom:88.0:98.0 \
# 2:IGNORE:Outside \
# 3:RANGE:Office:70.0:65.0:80.0:82.0"
# 4:DOWN:Basement:36.0:32.0"
ZONES="1:RANGE:Cellar:38.0:33.0:60.0:70.0"
# Define the scale - Only used in report text
# -------------------------------------------
SCALE="F"
# Add an administrative message to the top of the report page
# Not necessary, but can be a quick way to know what server
# is polling a ControlByWeb module, where the module is
# physically located, and perhaps some instructional
# information
# -----------------------------------------------------------
ADMINMSG="- ${MACHINEDOTS} is the host polling the ControlByWeb X-300 module ${MODULE}
- The ${MODULE} X-300 ControlByWeb module physically resides in the cellar"
###############################################################################
# --------------------------------------------------
# Nothing should need to be modified below this line
# --------------------------------------------------
###############################################################################
#
# ----------------------------
# Set required Xymon variables
# ----------------------------
COLOR="green"
MSG=""
# ----------------
# Set up functions
# ----------------
#
# Get the four sensor temperature outputs from the
# "state.xml" page from ControlByWeb temperature monitor
# ------------------------------------------------------
getdata() {
TEMPS=`"$CURL" -s -m 10 -u "$USER:$PASS" "$MODULE/state.xml"`
# If the device returns no data, or is offline, or does not respond,
# or if curl fails for any reason, then just fail and exit the script.
# Xymon will alert purple indicating that it has not seen data for this
# test after 20 minutes (default). I suppose we COULD instead force a
# yellow alert for all temps for this device during this condition...
# ---------------------------------------------------------------------
EXIT="$?"
if [ "$EXIT" != "0" ] || [ -z "$TEMPS" ]; then
exit 1
fi
}
# Separate zone components:
# - Skip all temperature values for IGNORE test types
# - Assign WarnTmp2 and CrtTmp2 for RANGE test types
# Formatting here is ugly to get resonable output in the display
# with minimal use of HTML to clutter up email and SMS reports :(
# ---------------------------------------------------------------
parsezone () {
sensornum=`echo "$zone" | cut -d':' -f1`
testtype=`echo "$zone" | cut -d':' -f2 | "$TR" [a-z] [A-Z]`
location=`echo "$zone" | cut -d':' -f3`
ZONEMSG="${ZONEMSG}
- Sensor - #$sensornum
Monitoring - $location
Test Type - $testtype"
case "$testtype" in
UP | DOWN )
warntemp1=`echo "$zone" | cut -d':' -f4` ;
crittemp1=`echo "$zone" | cut -d':' -f5` ;
ZONEMSG="${ZONEMSG}
- Warning Temp - ${warntemp1}${SCALE}, Critical Temp - ${crittemp1}${SCALE}
" ;;
RANGE )
warntemp1=`echo "$zone" | cut -d':' -f4` ;
crittemp1=`echo "$zone" | cut -d':' -f5` ;
warntemp2=`echo "$zone" | cut -d':' -f6` ;
crittemp2=`echo "$zone" | cut -d':' -f7` ;
ZONEMSG="${ZONEMSG}
LOW -- Warning Temp - ${warntemp1}${SCALE}, Critical Temp - ${crittemp1}${SCALE}
HIGH -- Warning Temp - ${warntemp2}${SCALE}, Critical Temp - ${crittemp2}${SCALE}
" ;;
IGNORE )
ZONEMSG="${ZONEMSG}
" ;;
esac
}
# Pull current zone's temperature reading out of xml tags
# -------------------------------------------------------
getcurtemp () {
# Each of the four temperatures is represented
# as a line <sensorXtemp>[-][Y]YY.Z</sensorXtemp>
# where X is the sensor number from 1 to 8,
# Y is the temp in degrees, and Z is the tenths
# We only want the numeric portion including the
# negative (hyphen) symbol between the tags for
# the current sensor we are looping for
# Also need to check for "xx.x" in case a temperature
# sensor is not communicating with the module
# ---------------------------------------------------
curtemp=`echo "$TEMPS" \
| "$GREP" -Eo "sensor$sensornum.*sensor$sensornum" \
| "$GREP" -Eo [-]*\(\(x\)\|\([0-9]\)\)\{1,3\}\.\(\(x\)\|[0-9]\)`
}
# Test to make sure that we have a numeric value and not "xx.x"
# which would mean that this temperature sensor is broken, or
# otherwise not communicating with the module. Flag this test's
# CURCOLOR red and the main test COLOR red as well.
# -------------------------------------------------------------
testcomm () {
if [ "$curtemp" == "xx.x" ]; then
CURCOLOR="red"
# Now, since red is the most critical color, just set
# the main status color for this report to red too
# ---------------------------------------------------
COLOR="red"
return 1
else
return 0
fi
}
# Test for temperature RISING and set the test's CURCOLOR
# Set the main COLOR variable for the Xymon report if necessary
# -------------------------------------------------------------
testup() {
# Is current temp greater than the critical temp?
# -----------------------------------------------
if [ `echo "$curtemp" | "$TR" -d .` -ge `echo "$crittemp1" | "$TR" -d .` ]; then
CURCOLOR="red"
# Now, since red is the most critical color, just set
# the main status color for this report to red too
# ---------------------------------------------------
COLOR="red"
# Is current temp greater than the warning temp?
# ----------------------------------------------
elif [ `echo "$curtemp" | "$TR" -d .` -ge `echo "$warntemp1" | "$TR" -d .` ]; then
CURCOLOR="yellow"
# Set main status color to yellow only if it is not already worse (red)
# ---------------------------------------------------------------------
if [ "$COLOR" != "red" ]; then
COLOR="yellow"
fi
fi
}
# Test for temperature DECREASING and set the test's CURCOLOR
# Set the main COLOR variable for the Xymon report if necessary
# -------------------------------------------------------------
testdown() {
# Is current temp less than the critical temp?
# --------------------------------------------
if [ `echo "$curtemp" | "$TR" -d .` -le `echo "$crittemp1" | "$TR" -d .` ]; then
CURCOLOR="red"
# Now, since red is the most critical color, just set
# the main status color for this report to red too
# ---------------------------------------------------
COLOR="red"
# Is current temp less than the warning temp?
# -------------------------------------------
elif [ `echo "$curtemp" | "$TR" -d .` -le `echo "$warntemp1" | "$TR" -d .` ]; then
CURCOLOR="yellow"
# Set main status color to yellow only if it is not already worse (red)
# ---------------------------------------------------------------------
if [ "$COLOR" != "red" ]; then
COLOR="yellow"
fi
fi
}
# Test for temperature being within the defined RANGE
# and set the test's CURCOLOR
# Set the main COLOR variable for the Xymon report if necessary
# -------------------------------------------------------------
testrange() {
# Is the current temp is outside of the high and low critical levels?
# -------------------------------------------------------------------
if [ `echo "$curtemp" | "$TR" -d .` -le `echo "$crittemp1" | "$TR" -d .` ] \
|| [ `echo "$curtemp" | "$TR" -d .` -ge `echo "$crittemp2" | "$TR" -d .` ]; then
CURCOLOR="red"
# Now, since red is the most critical color, just set
# the main status color for this report to red too
# ---------------------------------------------------
COLOR="red"
# Is the current temp is outside of the high and low warning levels?
# ------------------------------------------------------------------
elif [ `echo "$curtemp" | "$TR" -d .` -le `echo "$warntemp1" | "$TR" -d .` ] \
|| [ `echo "$curtemp" | "$TR" -d .` -ge `echo "$warntemp2" | "$TR" -d .` ]; then
CURCOLOR="yellow"
# Set main status color to yellow only if it is not already worse (red)
# ---------------------------------------------------------------------
if [ "$COLOR" != "red" ]; then
COLOR="yellow"
fi
fi
}
###########################################################
# -----------
# Main Script
# -----------
# Use curl to pull the data from the module
# -----------------------------------------
getdata
# Loop through the defined zones
# ------------------------------
for zone in $ZONES; do
CURCOLOR="green"
parsezone
getcurtemp
# Make sure that the sensor we are testing is
# actually communicating before we move onto the
# UP, DOWN, RANGE or IGNORE tests.
# ----------------------------------------------
if testcomm ; then
# Determine if this is an UP or DOWN test
# ---------------------------------------
case "$testtype" in
UP )
testup
;;
DOWN )
testdown
;;
RANGE )
testrange
;;
IGNORE )
# Do not test anything. Just append
# the $CURCOLOR (green), $location
# and $curtemp values to the Xymon
# Server report for this "zone"
;;
* )
exit 1
;;
esac
fi
# Build the text of the status message
# that will be sent to the Xymon Server
# -------------------------------------
MSG="${MSG}
&${CURCOLOR} ${location} : ${curtemp}${SCALE}"
done
# Prepend the administrative message to the report
# ------------------------------------------------
MSG="${ADMINMSG}
${ZONEMSG}
<hr>
${MSG}"
# Send final report to Xymon Server
# ---------------------------------
$BB $BBDISP "status $MACHINE.$COLUMN $COLOR `date`
${MSG}
"
###########################################################
答案 0 :(得分:0)
我为ControlByWeb工作,并为您解决了这个问题。我将Xymon安装到计算机上,并且能够使引用的脚本正常工作。虽然我做了一些改变。
默认情况下,Xymon将忽略发送给它的消息,除非它与host.cfg文件中的主机有关。该脚本在发送消息时使用名为$MACHINE
的变量,在我的情况下,此变量为空。因此它与hosts.cfg文件中的主机不匹配,但被忽略。
为了解决这个问题,我最后在脚本文件顶部附近添加了一行,将此变量定义为hosts.cfg文件中存在的主机名。
USER=""
PASS="webrelay"
MACHINE="xymon.example.com"
然后我将脚本文件保存在xymon / client / ext中并赋予它755权限并将用户/组设置为xymon。
除此之外,我发现最后使用的$BB
变量依赖于另一个未初始化的变量。为了解决这个问题,我将以下行添加到xymon / client / etc / xymonclient.cfg文件中:
XYMONCLIENTHOME="/home/xymon/client"
最后,我更改了/xymon/client/etc/clientlaunch.cfg文件以包含以下内容:
[cbwtemp]
ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
CMD $XYMONCLIENTHOME/ext/xymon_cbw_temp.sh
LOGFILE $XYMONCLIENTLOGS/xymon_cbw_temp.log
INTERVAL 1m
如果一切正常,它现在应该在几分钟内在您指定的主机旁边显示一个新列。
请告诉我这是否能解决您的问题。