Simon icon Simon
Flexible server monitoring

Introducing Simon 5!

Simon version 5 is now available. It is a massive update, introducing a much-requested feature: syncing the Simon data between multiple Macs, plus a Simon Status service, a Link Checker filter, improved Find filter, iMessage and Speak Error notifiers, a new app icon, and much more.

Important: please note that Simon 5 requires a minimum of macOS 10.12 (Sierra), and is a paid upgrade from Simon 4. Purchasers since September 1, 2020 automatically get a version 5 license (that also works in previous versions).

Read the Simon What's New page for details.

Can't get service script to work

I setup a script based service to check the status of a mysql server via SSH. The script itself properly echos 1 if the string "uptime" is found and 0 if it is not. Yet, Simon insists that the result is 0, even if the output window shows a 1. I tried it with both a bash and a php version of the script, but the error persists. I'm on 10.7.5. Script is attached.

mysql-via-ssh.txt516 bytes
David Sinclair's picture

Re: Can't get service script to work

Can you please provide the authentication details so I can try it myself (perhaps of a demo server if you prefer). Send privately via email. I will keep the information confidential.

David Sinclair's picture

Re: Can't get service script to work

Thanks for the info. If I remove the grep portion from the script, I get an error:

Host key verification failed.

Presumably you don't get that?

However, I think I see the likely issue. The Result of the service (Success or "Uptime not found" failure in this case) is based on the exit value of the last command in the script, not the output. So if grep exits with a value of 0 when it finds something, that's what will be used for the service Result. The count value will be the output.

Put another way, the exit value is the {ServiceResultCode} variable for the filters, and the output text (count in this case) is the {ServiceResponseText} variable.

Re: Can't get service script to work

Now this is starting to make sense. grep exits with error code 0 if it found the string and 1 if it didn't. Therefor, changing my script as follows fixed it:


# Script saved from Dejal Simon 3.4
# Saved by Tim Kaufmann on 08.02.13 01:10
# Script is for Bourne-Again Shell: /bin/bash

# Das ist die Beschreibung.

# mysql_pass:
# mysql_socket:
# mysql_user:
# remote_server:

# 0: (Success)
# 1: Uptime not found

# *** SCRIPT: ***

ssh {remote_server} "echo \"STATUS\" | mysql -u{mysql_user} -p{mysql_pass}" 2>&1 | grep -i "uptime"

Re: Can't get service script to work

That error code hint was a good one. grep exits with 0 if it found the string and 1 if it didn't. So changing (Success) to 0 and "Uptime not found" to 1 fixed it.

Yet, I can't figure out how those filters work. I consider myself to be a pretty advanced users, but I don't understand them at all. What would a filter or filter chain have looked like that analyzes {ServiceResponseText} and fixes the service status based on that? One or two screenshots would be really helpful. Currently, I'm holding back on buying Simon because I cannot make any sense from the filter section.


David Sinclair's picture

Re: Can't get service script to work

With your service script, if you only care about success or failure ("uptime not found"), you don't really need a filter.

Filters are useful to take the output and/or status of the service and do further analysis on them. For example, the common case is a Block filter to only look at a portion of the output, e.g. to avoid dynamic content. Like services, filters can be very powerful and flexible, or very simple.

Another example, instead of using grep in your service script, you could have output all of the text from the mysql command, then used a Find filter to find the "uptime" text, and result in a failure if not found.

Read the Simon Help on the Find filter for details. Here's a screenshot showing the Find filter, as an example (you'd use different values, and choose the third Result radio button):

Find Filter