You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

\n

\n \n \n \n \n \n \n \n \n \n \n \n \n
Related DocumentationVersion of up.time affectedAffected Platforms
This article is part of a series:
\n
\nPart 1 - Creating Custom Service Monitors in up.time
\n Part 2 - Creating \nCustom Service Monitors with Retained Data Collection
\n Part 3 - Creating \nPlug-in Service Monitors in up.time \n
AllAll
\n \n

\n \n

Article \nContents \n

\n \n \n \n
\n

Overview
\n \n

\n \n

up.time provides many built in service monitors that allow \nyou to monitor and alert on a wide array of services and applications \nwithin your enterprise. However, the standard up.time service monitors \nmay not be adequate to monitor all of the systems, applications and \nproprietary devices in your environment. In some cases, you may want to \ncapture metrics that are unique to your environment. To do this, you \ncan define custom service monitors to monitor custom services and \napplications to provide the level of in depth performance monitoring \nthat you require. Using custom service monitors, you can monitor and \ngraph historical performance data \nfrom just about any device in your environment.

\n \n

This article series will focus on taking a simple command line \nscript and incorporating it into up.time. It will then demonstrate how \nto expand that script for use within a Custom with Retained Data \nservice monitor that will enable you to not only register service \noutages in the event of a failure but also graph the historical \nperformance trends. The final article in this \nseries will guide you through the steps to further expand your custom \nservice monitor so that it can be directly plugged in to the up.time \ninterface for use by your end users.

\n \n
\n

How Custom Service Monitors Work
\n \n

\n \n

In up.time, you can configure custom service monitors to run \nany application or script. The application or script can then take an \naction, including launching commands on one of your agent systems using \na built-in agent authentication protocol. Or, your script can use a \ndifferent transport method to contact other servers and applications, \nor simple run commands on the monitoring station itself. The only \nlimitation is that the application or script must return status \ninformation that up.time will then use to determine the custom service \nmonitor status.

\n \n

The built-in agent authentication protocol provides a quick \nand easy way for you to have the up.time agent run commands (or any \napplication) on your agent-side system without the fear of unknown \nusers being able to execute the same commands. The output from the \nagent-side commands will be returned to the monitoring station custom \nscript for parsing. This enables you to create a script that can \nmonitor many different agent systems without duplicating the script \nmany times. The following diagram illustrates the custom \nservice monitor process:

\n \n


\n \n

\n \n
\n \n
\n

Step 1 - Creating the Agent Side Script
\n \n

\n \n

When designing a custom service monitor, you should consider \nwhat information that you want the monitor to collect. For example:

\n \n
    \n \n
  • If you want to monitor the status of an application, you \nshould first create a command line script or utility (or \nusing an existing one) that returns the general status of a \nservice that is on the agent system. 
  • \n \n
  • If you want to gather performance metrics, ensure that the script \nto return a series of performance indicators to the console, otherwise \nsimple output a message that can later be used to validate the status \nof the service or application. 
  • \n \n
\n \n \n

Once you have written your agent-side script, you will need to \nconfigure your up.time agent to execute it. As a minimum, you must configure the following settings for each agent-side command:

\n \n
    \n \n
  • For agents running on non-Windows systems, define a password and command pair in the agent-side password file.
  • \n \n
  • For agents running on Windows, set a password via the Agent Console.
  • \n \n
  • Verify that the agent-side \ncommand permissions allow the execution of the command by the user that the \nagent is run as. If the commands within your script require additional \nsystem permissions, you may have to alter the security settings for the execution of the \nagent.
  • \n \n
\n \n

For the purpose of this example, lets assume that we have \ndesigned an agent side script that returns information about the \ntemperature and humidity levels around a given agent system. If we were \nto run this agent side script from the command line it would be \nexecuted as follows:

\n \n

NOTE: \nThese example commands are formatted for non-Windows systems. The \ncommand format is very similar on Windows systems, but require minor syntax and \npath changes.

\n \n

# su - uptime
\n \n$ /opt/uptime-agent/my-scripts/show_temp.sh
\n \ntemp 74
\n \nrh 30

\n \n

To define your password and command pair on a non-Windows \nagent system, do the following:

\n \n
    \n \n
  1. Ensure that a file named .uptmpasswd is created in the \nup.time agent bin directory -- either /opt/SPYNuptm/bin/ or \n /opt/uptime-agent/bin, depending the version of your agent. This file must \nbe owned and readable by the user that the agent is run as (ex. uptimeagent or uptime users).
  2. \n \n
  3. Open the file .uptmpasswd in a text editor.
  4. \n
  5. Enter a password and command pair for each command that you want to run on the agent \nsystem. The following is the example format \nand an example of a agent-side commands: \n

    Format: [password] [command path, no arguments]

    \n

    Example file contents:

    \n

    secretpassword /opt/uptime-agent/my-scripts/show_temp.sh
    $%^& /usr/local/bin/appstatus.sh

    \n
  6. \n
\n \n

Windows agents do not require a password file. However, you must enter the equivalent settings into the Agent Console with the following steps:

\n \n
    \n
  1. Launch the Agent Console on the system where the script will run. By default this is located in the Start Menu under “All Programs -> up.time agent -> up.time Agent Console.”
  2. \n
  3. The first step after launching the Agent console is to set a password in the ‘Agent Options’ section and click save. This password will be used to authenticate with the agent before running the script.
  4. \n
  5. After setting the password, tell the agent where the custom script is located on the server by clicking on the ‘Advanced’ option in the dropdown list and selecting ‘Custom Scripts.’
  6. \n
  7. On the Custom Scripts screen, you should see an example similar to:
      \n
    • Custom Command: dir
    • \n
    • Path to Script: cmd.exe /c "dir c:"
  8. \n
  9. To continue this show-temp example, set the parameters to something similar to: \n
    • Custom Command: temp
    • \n
    • Path to Script: cmd.exe /c “C:scriptsshow_temp.pl” \n(note: make sure to click Add/Edit before closing the window, otherwise your command will not be saved).
  10. \n
  11. If you haven’t done so yet, click Save, and Yes when asked to restart the agent. This will ensure that your new settings take effect.
  12. \n
\n \n

The following is a sample configuration. Note the additional folder named rexec_commands, which contains a key/value pair of the command key.

\n \n

NOTE: If any changes are made to the Windows agent registry please restart the \n"up.time agent" service to see these changes take effect.

\n \n

\n[HKEY_LOCAL_MACHINE\SOFTWARE\uptime software\up.time agent]
\n"CmdsTimeout"=dword:00000014
\n"Port"=dword:0000270e
\n"MaxClients"=dword:00000005
\n"Debug"=dword:00000000
\n"CmdsPassword"="secretpassword"
\n"LogFile"="log.txt"
\n
\n[HKEY_LOCAL_MACHINE\SOFTWARE\uptime software\up.time agent\rexec_commands]
\n"dir"= cmd.exe /c "dir c:"
\n"show-temp"= cmd.exe /c "C:\scripts\show_temp.pl"
\n

\n \n
\n

Step 2 - Creating the Monitoring \nStation Script
\n \n

\n \n

The next step is to write the monitoring station script that \nwill attempt to execute your agent side script, validate the output, \nand then return status or performance information to up.time.

\n \n

The monitoring station script can be written in any language \nand format, provided that it adheres to these general rules:

\n \n
    \n \n
  1. The script must return at least one line of output to the \nsystem console. up.time will use this output to determine the status of \nthe custom service monitor.
  2. \n \n
  3. The script must exit with a success status, unless \nthere has been a problem during the execution of the script or you want to \nforce a status for the service monitor. Acceptable return codes are: \n
      \n \n
    • exit 0 - The \nscript executed without any errors, all output produced from the script \nwill be parsed by up.time to determine the service monitor status.
    • \n \n
    • exit 1 - The \nservice monitor status will be set to WNG (warning) and an outage will be \nrecorded. The console output from the script will be placed in the \ncustom service monitor status message.
    • \n \n
    • exit 2 - The \nservice monitor status will be set to CRIT (critical) and an outage will be \nrecorded. The console output from the script will be placed in the \ncustom service monitor status message.
    • \n \n
    \n \n
  4. \n \n
  5. The script must accept the host name of the agent system as \nthe first argument. up.time will automatically add this argument to the \narguments that are passed to the script. \n
  6. \n \n
\n \n

In most cases, the monitoring station script will contact an agent system and attempt to run a predefined agent-side script like the one that was defined in step 1 above. You can use any transport tool -- such as rexec, rsh, or ssh -- to contact the agent system.

\n \n

However, uptime software recommends using the bundled agentcmd utility the netcat utility to contact your agent systems from your monitoring station script:

\n
    \n
  • To get started with custom scripts, or for implementations with only a handful of custom monitor instances, use agentcmd. The agentcmd utility is commonly called in the format listed below to execute a command on the agent side system. Please note that this utility is a helper tool, if you are using many custom monitor instances we recommend using an alternate tool.
    \nThis example uses the settings that were configured above to execute the agent side script: \n

    Format: /usr/local/uptime/scripts/agentcmd [-s/+s] -p [agent port] [agent hostname] rexec [password] [path]

    \n \n

    Example: /usr/local/uptime/scripts/agentcmd -p 9998 my-agent rexec secretpassword /opt/uptime-agent/my-scripts/show_temp.sh my-arguments

    \n \n

    For more information on the syntax used with agentcmd, see this Knowledge Base article.

    \n
  • If you plan on implementing a number of custom monitor instances, use netcat. netcat must be downloaded and installed on the monitoring station if it isn't already installed as part of your operating system. The netcat utility is commonly called in the format listed below to execute a command on the agent side system. \nThis example uses the settings that were configured above to execute the agent side script: \n

    Format: echo -n rexec [password] [path] | /usr/local/uptime/bin/netcat [agent \nhostname] [agent port]

    \n \n

    Example: echo -n rexec secretpassword /opt/uptime-agent/my-scripts/show_temp.sh my-arguments | /usr/local/uptime/bin/netcat my-agent 9998

    \n
  • \n \n \n
\n \n

NOTE: The 'rexec' text below does not indicate use of the 'rexec' system utility, it is simply a key word used to indicate to the agent that you are attempting to run a predefined command.

\n \n

You will normally use netcat or agentcmd in the monitoring station script to return the results of an agent-side script, validate the status of those results, and return the status to up.time. The following is an example of a monitoring station script:

\n \n

\n#!/bin/sh
\n \n
\n \n# This script takes the following arguments:
\n# check_temp.sh hostname port [temp|rh] wng crit
\n# Example execution:
\n# ./check_temp.sh my-agent 9998 temp 60 80
\n# ./check_temp.sh my-agent 9998 rh 20 30
\n \n
\n \n# This script can be placed anywhere on the monitoring station system as long as it is
\n# executable by the uptime user.
\n \n
\n \n#First, collect our arguments
\n \nAGENT=$1
\nPORT=$2
\nTYPE=$3
\nWNG=$4
\nCRIT=$5
\n
\nTMPFILE=/tmp/$$.temp
\n
\n \n# now use the info above to contact our agent, store the output in a file for parsing
\n \n`echo -n rexec secretpassword /opt/uptime-agent/my-scripts/show_temp.sh \nmy-arguments | /usr/local/uptime4/bin/netcat $AGENT $PORT > $TMPFILE`

\n \n

Note: The syntax to use agentcmd is different than netcat. When using agentcmd, the above netcat example would like this:

\n \n

'/usr/local/uptime/scripts/agentcmd my-agent -p 9998 rexec secretpassword /opt/uptime-agent/my-scripts/show_temp.sh my-arguments > $TMPFILE'

\n \n

\n# we have the output from the agent. If it is ERR that means there was \na problem running the script on the agent
\n \n`grep ERR $TMPFILE`
\n \nif [ $? -eq 0 ]
\n \nthen
\n \necho "Could not execute agent side script!"
\n \n# by exiting with a 2 we are forcing a CRIT service outage
\n \nexit 2
\n \nfi
\n \n
\n \n# given our parameters we can now extract the correct value from the \nagent output
\n \nif [ $TYPE -eq "temp" ]
\n \nthen
\n \nVALUE=`head -1 $TMPFILE | awk '{print $2}'`
\n \nMSG="temperature"
\n \nelse
\n \nVALUE=`tail -1 $TMPFILE | awk '{print $2}'`
\n \nMSG="humidity"
\n \nfi
\n \n
\n \n# now lets check our values to see if they are over the thresholds and \nset our status message
\n \nRET="OK - $msg is $VALUE on $AGENT"
\n \n
\n \nif [ $VALUE -ge "$WNG" ]
\n \nthen
\n \n# this is our warning message
\n \n# include WARNING for use in the web interface thresholds
\n \nRET="WARNING - $MSG is $VALUE on $AGENT"
\n \nfi
\n \nif [ $VALUE -ge "$CRIT" ]
\n \nthen
\n \n# this is our critical message
\n \n# include CRITICAL for use in the web interface thresholds
\n \necho "CRITICAL - $MSG is $VALUE on $AGENT"
\n \nfi
\n \n
\n \n# here we simply print our status message to the console and exit with \na 0,
\n \n# the thresholds provided in the up.time web interface will be used to \nset the monitor status
\n \nrm $TMPFILE
\n \necho "$RET"
\n \nexit 0
\n \n

\n \n
\n

Step 3 - Adding your Custom \nService Monitor to up.time
\n \n

\n \n

The next step is to add a custom service monitor to the up.time Web interface using the same process \nthat you would use to add a standard custom service monitor to up.time. \nThe Custom monitor option is found in the List Other Monitors \nsection of the Add New \nService Instance page..

\n \n

The Custom service monitor template has the following \nmonitor specific settings available:
\n \n
\n \n

\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Option \nNameDescriptionExample
Script NameThe script name \nis the path to your monitoring station script, this is the script that \nup.time will execute when running this service monitor. Be sure to use \nthe complete path wherever possible and that the path is to a locally \nmounted volume. For Windows script paths you must use UNIX style \ndirectory separators (/ instead of \) and also place double quotes \naround the entire script nameUNIX/Linux \nExample:
\n \n/usr/local/uptime/check_temp.sh
\n \n
\n \nWindows Example:
\n \n"C:/my scripts/check_temp.bat"
ArgumentsThese are the \narguments that you would like up.time to pass into your monitoring \nstation script. No arguments are required but please be aware that \nup.time will automatically include the selected hostname as the first \nargument to your script.temp 60 80
Output WarningThis is the \nwarning threshold used against the output returned from your monitoring \nstation script. This is a textual comparison. You must select both a \ncomparison method and a search string to enable the warning level \nthresholdOutput \ncontains: "warning"
Output CriticalThis is the \ncritical threshold used against the output returned from your \nmonitoring station script. This is a textual comparison. You must \nselect both a comparison method and a search string to enable the \ncritical level thresholdOutput \ncontains: "critical"
\n \n
\n \n

Based on the settings used in the example monitoring station script, configure the monitor with the following setting: \n

\n \n
    \n \n
  • Enter a name \nand description for the monitor.
  • \n
  • Select a host from \nthe dropdown menu. Be sure to select the same host that your agent side \nscript is on
  • \n
  • In the Script Name field, \nenter the path to the custom script on your monitoring station. On \nWindows systems be sure to use UNIX style / instead of \ \nand put quotation marks around your path. For example: "C:/my files/check_temp.bat" \n
  • \n
  • In the Arguments field, \nenter the arguments for the script. up.time adds the agent name as the \nfirst argument automatically so do not include it.
  • \n
  • Select contains from the Warning dropdown and \nenter WARNING \nas the search text.
  • \n
  • Select contains from the Critical drop down \nand enter CRITICAL \nas the search text.
  • \n
  • Complete the \nremainder of the monitor template as you would for a normal service \nmonitor.
  • \n
\n \n

Example \nmonitor configuration

\n \n

The image below illustrates a sample monitor configuration. \nThis service monitor will indicate a WARN or CRIT whenever \nthe monitoring station \ncustom script returns WARNING \nor CRITICAL \nin its output.

\n \n

\n
  • No labels