Need help with powershell monitor

Topics: Developer Forum, User Forum
Jun 19, 2009 at 10:09 AM
Edited Jun 19, 2009 at 10:20 AM

Hi,

I'm a new user of Polymon and are experiencing a problem.

I have created a powershell monitor that loops through a list of servers and checks if services on these servers are running.

When I run a test on the script on the "Test Monitor" tab, it runs fine and as expected.

Also, when I "Run monitor now" in the dashboard it runs fine. But after the first "run" by the Polymon Manager it fails with "Exception Conversion from string "" to type 'Boolean' is not valid."

Unfortunately the error message does not contain any clue of where the error arises...

Anyone who have experienced any similar, or can explain why it runs fine when testing an rerunning, but fails when run by the Manager?

 

Developer
Jun 19, 2009 at 10:22 AM

Hi audunj,

I don't recall seeing anything like this with Polymon before, the most likely issue when something runs fine in the UI, but doesn't work when being run by a service is a permission issue.

Temporarily change the PolyMon Executive service to run as your user account and test again. If that works then I would recommend creating a service account for PolyMon to run as and set the password to never expire.

-Chris

Jun 19, 2009 at 1:00 PM

Hi,

Iam almost embarrassed I didn't think of that myself :-)

Thanks a lot.

 

Jun 19, 2009 at 2:09 PM
Edited Jun 19, 2009 at 8:59 PM

Hi again,

I have another question.

In my monitor I want to send a SMS if it fails and I do this via a third-party app installed on my server.

I am able to do this as long as the call to this app is located in my powershell monitor script. I wanted to do this in the "Action Script" tab, but this dows not seem to work. No errormsg and nothing fails, I just don't receive any SMS...

Have anyone noted any issues with running powershell scripts from "Action Script" or do you have any ideas what could be causing this?

 

Regards,

Jun 30, 2009 at 7:31 PM

1. Remember that whatever you set as the script action, it will run FROM the executive machine.  So the shell must be valid and reference files/directories that are valid on the executive machine. ("c:\smsprogram\smsprogram.exe" must exist on the executive machine, and probably should exist on the manager machine for testing consistency.)

2.  Have you checked the logic in your action script, to ensure that your trigger condition is met?

I.E.  "if ($Status.StatusID -gt 1)
  {c:\smsprogram\smsprogram.exe "Something is wrong" "john smith" "312-555-4455"}

 

Bob

Jul 3, 2009 at 10:03 AM
Edited Jul 3, 2009 at 10:50 AM

Hi,

I have Polymon installed on one single server.

This is the exact code in the Action Script (Powershell):

[string]$laststatusmessage=invoke-expression "sqlcmd -h -1 -E -d polymon -Q `"set nocount on;select top 1 rtrim(statusmessage) from monitorevent where monitorid=3 order by eventid desc`""
if($laststatusmessage.trim() -ne $Status.StatusText){
        invoke-expression "&'c:\Program Files\sysmansms\CMDclient\SysManSMS_CMD.exe' +XXXXXXX `"$($Status.StatusText)`""
}

 

The complete logic behind this script and the monitorscript will be a bit difficult to explain in detail, but the main idea is

Monitorscript:
- the monitorscript loops through a set of servers checking for specified services
- if any of these service's status is STOPPED then  $Status.StatusID=3 and $Status.StatusText lists stopped services on which servers.

Action script:
- reads the last $status.StatusText for this monitor from the database into $laststatusmessage
- if this $laststatusmessage differs from the current $Status.StatusText the SMS should be fired

The reason for checking the last statusmessage instead of statusid is that I want only one SMS fired if one specific service stops. If there is a different service that has stopped the next time the monitor runs the statusid will be the same (=3) but the statustext will differ so I will get a new SMS. If one specific service is stopped during several consecutive monitorruns I will only get a SMS on the first run.

 

When testing this in the Polymons "Test Monitor" I do not get a SMS (not sure if this test will run the actionscript).
If I test the monitorscript and then the actionscript outside Polymon I get the SMS.
If I put the invoke-expression line from the actionscript into the monitorscript (where I check for stopped services) I get the SMS.

I just don't understand why this does not work as expected?

Hope this was understandable, if not let me know.

Regards,