Multiple Status Updates, No Email.

Topics: Developer Forum
Aug 8, 2013 at 6:01 PM
Hi,

I have a pretty basic Powershell monitor. It executes a SQL query, stores the results in a variable, then i do a count and alert. My question is, how can i make PolyMon throw an addition alert when a variable increases ? I know in the Notification Rules, there is the "and every n consecutive thereafter" , but the problem with that is the monitor will keep alerting regardless if my count increases. I'm looking to have PolyMon throw an alert only when the variable changes.

Here is a scenario ;
$sqlquery = @(Invoke-Sqlcmd -query "USE Blarf
GO
Select * From Table where Item = "Dog"
")

#here it will send a email, with a custom warning message...because my table has Dog in it.

if ($sqlquery.count -eq 1)  {
   $status.StatusID = 2
   $status.StatusText = $warningMsg
}

#but the next monitor cycle, say my count(so Dog got inserted another time in the Table) goes up to 2. I would expect another Warning Email. 

elseif ($sqlquery.count -ge 2) {
   $status.StatusID = 2
   $status.StatusText = $warningMsg
}
Appreciate any help!
Aug 9, 2013 at 6:55 PM
Okay, found a workaround to my issue. I ended up just flipping the statusID whenever a new value changes. That way it sends an email each time.

This worked out ;
$errors = $sqlquery.count
foreach ($err in $errors) {

if($err -eq 1 -and $err -ne 0) {
   $status.StatusID = 3
   $status.StatusText = $warningMsg
}
elseif ($err -eq 2 -and $err -ne 1) {
   $status.StatusID = 2
   $status.StatusText = $warningMsg
}
elseif ($err -ge 3 -and $err -ne 2) {
   $status.StatusID = 3
   $status.StatusText = $warningMsg
} else {
  $status.StatusID = 1
  $status.StatusText = $clear
}
Aug 9, 2013 at 7:47 PM
Excellent. I was working on a long reply, not half as elegant. Way to go.

Bob