KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Help with SSH Test expression

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
sneader



Joined: 22 Dec 2005
Posts: 90

PostPosted: Fri Jun 28, 2013 10:12 pm    Post subject: Help with SSH Test expression Reply with quote

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
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Sat Jun 29, 2013 9:05 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
sneader



Joined: 22 Dec 2005
Posts: 90

PostPosted: Sat Jun 29, 2013 9:28 am    Post subject: Reply with quote

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
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Mon Jul 01, 2013 5:35 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
sneader



Joined: 22 Dec 2005
Posts: 90

PostPosted: Tue Jul 02, 2013 1:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Tue Jul 02, 2013 2:13 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
sneader



Joined: 22 Dec 2005
Posts: 90

PostPosted: Sun Jul 07, 2013 9:55 pm    Post subject: Reply with quote

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
View user's profile Send private message
sneader



Joined: 22 Dec 2005
Posts: 90

PostPosted: Sun Jul 07, 2013 10:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Mon Jul 08, 2013 4:20 am    Post subject: Reply with quote

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

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index