1

Looking for help with the pre-made script for the ControlByWeb Temperature Monitor made for the Xymon monitoring server. I have followed the instructions step by step. The Column "cbwtemp" is not being generated. Currently runnimg xymon 4.3.12 with this script http://www.revpol.com/files/xymon_cbw_temp.sh Not sure if there has been changes to the coding on the newer xymon server that is preventing the script to run properly. I have checked the logs and no errors pertaining the script. Here is the script:

    #!/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}
    "

    ###########################################################

1 Answers1

1

I work for ControlByWeb and looked in to this issue a bit for you. I installed Xymon onto a computer and was able to get the referenced script working. There were a few changes I had to make though.

Xymon by default will ignore messages sent to it unless it is about a host in the host.cfg file. The script uses a variable called $MACHINE when it goes to send the message and in my case, this variable was blank. Thus it didn't match a host in the hosts.cfg file and was ignored.

To fix this, I ended up adding a line near the top of the script file to define this variable to a hostname that existed in the hosts.cfg file.

USER=""
PASS="webrelay"
MACHINE="xymon.example.com"

I then saved the script file in xymon/client/ext and gave it 755 permissions and set the user/group to xymon.

In addition to this, I found the $BB variable used at the very end was dependent on another variable that wasn't initialized. To fix this, I added the following line to the xymon/client/etc/xymonclient.cfg file:

XYMONCLIENTHOME="/home/xymon/client"

Finally, I changed the /xymon/client/etc/clientlaunch.cfg file to include the following:

[cbwtemp]
    ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
    CMD $XYMONCLIENTHOME/ext/xymon_cbw_temp.sh
    LOGFILE $XYMONCLIENTLOGS/xymon_cbw_temp.log
    INTERVAL 1m

If everything worked, it should now show a new column next to the host you specified within a few minutes.

Let me know if this fixes the issue for you or not.

Trevor K
  • 26
  • 1
  • This is great It's working now. It displays the Data as it should now. Time to work on adding sensors to the zones, and add more modules. Then my next tackle will be the Graphing portion of the instructions. Again thank you for the greatly appreciated assistance. These ControlByWeb devices are great and will continue to use them. – user3140287 Jan 01 '14 at 15:45
  • Just to ask were you able to get the graphs to display? I'm working on it and just want to confirm that the instructions will cover everything I need to graph the data. – user3140287 Jan 01 '14 at 19:17
  • I was able to follow the instructions [HERE](http://www.revpol.com/xymon_cbw_temp_script#instructions) with out any big issues. Just keep in mind the file names he mentions have changed. They are as follows: hobbitserver.cfg --> xymonserver.cfg and the other is hobbitgraph.cfg --> graphs.cfg One other problem I had is there ended up being 3 lines on the graph. You will probably see what I mean before too long. I have not figured out how to remove them and might not worry about it for the time being. – Trevor K Jan 02 '14 at 15:43
  • I was able to get it working properly and Really happy with hoe it displays. I've been able to have it display all the different sensors on he web relay. I again than you for helping me out and getting this going for me. I have it monitoring 2 webrelays and displaying 6 on one and 5 on the other. I have another 12 webrelays going to going into this. With this and the phone app Controlbyweb provides we are set here. Thanks again!!! – user3140287 Jan 02 '14 at 22:07