Creating Diagnostic with Parameter from monitor

Hi

Trying to create a diagnostic task with that runs a Powershell script to get some more information.

My troubble is that i need a parameter from the Alert/Health State to get the right information.
Been banging my head on google for the last day and don’t seem to be closer.

It the IIS 8 Application Pool state monitor, and i whant the instancename from the context as a paramter in the diagnostic so that i can do a

get-website | where $_.name -eq $ParameterFromAlert

But it doesn’t seem to work. I’v tried outputting just the Parameter but it’s Always empty.

Anyone have a working diagnostic/recovery that you can share ?

Hi

Not sure if this will do exactly what you want but as an example of something that might be similar.

I have a monitor that runs a PowerShell script and outputs a property bag for file count which is part of the Alert.

<AlertParameter2>$Data/Context/Property[@Name='FileCount']$</AlertParameter2>

Here then is a PowerShell diagnostic script that would take that parameter and write it to the windows application event log (automatically based on the monitor being in a warning state - the enabled and execute on state parameters which you can change as per your requirements):

    <Diagnostics>
      <Diagnostic ID="Example.WarningDiagnostic" Target="Windows!Microsoft.Windows.Server.OperatingSystem" Accessibility="Public" Enabled="true" Monitor="<<MONITORID>>Example.Monitor.Unit.FileCount" ExecuteOnState="Warning" Remotable="true" Timeout="300">
        <Category>Maintenance</Category>
        <ProbeAction ID="PA" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagProbe">
          <ScriptName>PowerShell_WriteEventLog_Diagnostic.ps1</ScriptName>
          <ScriptBody><![CDATA[
Param (
[int]$FileCount
)

If ([System.Diagnostics.EventLog]::SourceExists("Diagnostic PowerShell") -eq $False) {
New-EventLog -LogName Application -Source "Diagnostic PowerShell"
}

$Msg = "Diagnostic has completed for file count = $FileCount" 
Write-EventLog -LogName Application -Source "Diagnostic PowerShell" -EntryType Information -EventID 234 -Message $Msg ]]></ScriptBody>
          <Parameters>
            <Parameter>
              <Name>FileCount</Name>
              <Value>$Data/StateChange/DataItem/Context/DataItem/Property[@Name='FileCount']$</Value>
            </Parameter>
          </Parameters>
          <TimeoutSeconds>300</TimeoutSeconds>
        </ProbeAction>
      </Diagnostic>
    </Diagnostics>

Cheers

Graham

Hi Patrik,

I tried this, too. - I could solve my problem by taking the information I needed from the Target - parameters.

Perhaps this works for you, too?

Hi

Yea, found an example in the Windows server MP that has a recovery for defragmentation.

Seems like $Target works though several answers elsware says $Data should be used.

And i missed the Parameter ($varible) in my PS :slight_smile:

 

Thanks for the help.