View previous topic :: View next topic |
Author |
Message |
sneader
Joined: 22 Dec 2005 Posts: 90
|
Posted: Fri Jun 28, 2013 10:12 pm Post subject: Help with SSH Test expression |
|
|
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 |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Sat Jun 29, 2013 9:05 am Post subject: |
|
|
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 |
|
Back to top |
|
|
sneader
Joined: 22 Dec 2005 Posts: 90
|
Posted: Sat Jun 29, 2013 9:28 am Post subject: |
|
|
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 |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Mon Jul 01, 2013 5:35 am Post subject: |
|
|
You need program that will translate output into errorlevel code and simple BAT file like EximErrLevel.BAT
Code: | @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 |
|
Back to top |
|
|
sneader
Joined: 22 Dec 2005 Posts: 90
|
Posted: Tue Jul 02, 2013 1:45 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Tue Jul 02, 2013 2:13 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
sneader
Joined: 22 Dec 2005 Posts: 90
|
Posted: Sun Jul 07, 2013 9:55 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
sneader
Joined: 22 Dec 2005 Posts: 90
|
Posted: Sun Jul 07, 2013 10:13 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Mon Jul 08, 2013 4:20 am Post subject: |
|
|
Yes, should be the same variable name.
You are welcome
Regards
Alex |
|
Back to top |
|
|
|