Help with SSH Test expression

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
sneader
Posts: 90
Joined: Thu Dec 22, 2005 3:32 pm

Help with SSH Test expression

Post by sneader »

Hi all. I would like to monitor the size of our mail server queue. I can issue a command via SSH that will return the size of the queue.

I hoped that the SSH Test could alert me if the queue size was greater than 1000. I tried this:

Test method: SSH test
Command: exim -bpc
Check for: Text output
Alert if: expression true %Reply_Integer% > 1000

However, even if the result from the command is greater than 1000, it does not alert.

I have also tried various alternate expressions...

%Reply% > 1000
'%Reply%' > 1000
> 1000

But these do not work.

As I read the manual, it seems maybe "expression true" only works with BOOLEAN operators? So, then I could only use AND NOT OR?

Sorry for my confusion... if anyone has any ideas how I might be able to do this, I'd greatly appreciate it!!

- Scott
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Quote from the manual
expression true - HostMonitor will consider provided text as boolean (logical) expression, evaluate this expression using data received from the server, and set "Bad" status when retrieved data does not satisfy the required conditions. For example: if you define expression like "'No errors' and not ('Error' or 'Warning')", then HostMonitor will mark test as "Ok" when command output contains string 'No error' and does not contain either 'Error' or 'Warning'
In the expression you may use strings (must be put in quotes (') or in double quotes (")); round brackets; logical operators "and", "or", "not".

Can you modify script and return queue size as exit code or return text like scriptres:Ok:550 ?

Regards
Alex
sneader
Posts: 90
Joined: Thu Dec 22, 2005 3:32 pm

Post by sneader »

Hi Alex.

This is an existing command from the mail server software, and when issued simply returns a number. Example:

COMMAND: exim -bpc
RESPONSE: 1234

I had hoped that HostMonitor could evaluate the response "1234" and ALERT if the response was greater than 1000.

From your reply, it does not sound possible, therefore we would have to write our own program/script to evaluate it. We were hoping for simple solution, but maybe writing a script will not be too difficult (I'm not a programmer)

- Scott
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

You need program that will translate output into errorlevel code and simple BAT file like EximErrLevel.BAT

Code: Select all

@echo off
for /f %%i in ('exim.exe -bpc') do exitcode1.exe %%i
if errorlevel 1000 goto bad1
echo scriptres:Ok:%errorlevel%
exit
:bad1
echo scriptres:Bad:%errorlevel%
Start BAT file using command line like cmd /c c:\tests\EximErrLevel.BAT
Exitcode1.exe available at www.ks-soft.net/download/other/exitcode1.zip

Regards
Alex
sneader
Posts: 90
Joined: Thu Dec 22, 2005 3:32 pm

Post by sneader »

Hi Alex. Thanks much for your help. The server in question is Linux, and I am thinking the batch file and .exe are meant for Windows, correct?

But I think I may be able to find someone to help me with a Linux-equivalent script, based on your example.

- Scott
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

On Linux its very easy. Something like
#!/bin/sh
exim -bpc | awk '{ val1=$1; if (val>1000) {printf("ScriptRes:Bad:%d\n",val)} else {printf("ScriptRes:Ok:%d\n",val)}; }'

Regards
Alex
sneader
Posts: 90
Joined: Thu Dec 22, 2005 3:32 pm

Post by sneader »

Hi Alex. This is awesome!! I am implementing now. One typo... val1=$1 -- I think this should be val=$1?

I will let you know how it works shortly...

- Scott
sneader
Posts: 90
Joined: Thu Dec 22, 2005 3:32 pm

Post by sneader »

It works!! At first, I thought I was supposed to use the Exit Code test, but that did not work. When I switched to "Shell Script Result" and it worked right away.

THANK YOU!!!

- Scott
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Yes, should be the same variable name.
You are welcome

Regards
Alex
Post Reply