MIDACO

AF SDK: How to get the current notification status

Discussion created by MIDACO on Oct 1, 2013
Latest reply on Oct 3, 2013 by MIDACO

Hi there,

 

I'm programmiing a simple Powershell script and can't find how to display the current Notification status.  Using the SDK, I got the "Enabled" status and can't display if it's "Running"... See code below.

 

Any clue?
Many thanks,
Michel

 

$AFServerName="TMIDVDSAF01"
$AFDatabaseName="MAV_DEFAUT"

 

# AFSDK Loading
[Reflection.Assembly]::LoadFile('C:\Program Files (x86)\PIPC\AF\PublicAssemblies\OSIsoft.AFSDK.dll')

 

# Create connection
$PISystems = new-object OSIsoft.AF.PISystems
$PISystem = $PISystems[$AFServerName]
$AFDatabase = $PISystem.Databases[$AFDatabaseName]

 

# Create the notifications collection
$AFNotifications = [OSIsoft.AF.Notification.AFNotification]::FindNotifications($AFDatabase, $null, [OSIsoft.AF.AFSearchField]::Name, 0, 0, $AFDatabase.Notifications.Count)
[string]$ErrMessage=""

 

$CptEnable=0
$CptDisable=0
$CptError=0
$CptNone=0
$CptNotReady=0
$CptNull=0

 

$counter=0

 

foreach($AFNotification in $AFNotifications)
{
    $ErrMessage=""
    Write-Host "->" $AFNotification.Status ", ErrMess: " $AFNotification.ErrorMessage
   
    switch ($AFNotification.Status)
    {
        "Disabled" {$CptDisable = $CptDisable + 1}
        "Enabled" {$CptEnable = $CptEnable + 1}
        "Error" {$CptError = $CptError + 1}
        "None" {$CptNone = $CptNone + 1}
        "NotReady" {$CptNotReady = $CptNotReady + 1}
        default {$CptNull = $CptNull + 1
                 $ErrMessage = "Status non déterminé."}
    }

 

 $activity = "BD: $AFDatabaseName" + ", Notification= " + $AFNotification.Name
 $status = "Erreur: " + $ErrMessage
 $currentOperation = "Compteur= " +  $counter + " , Status= " + $AFNotification.Status
 Write-Progress $activity  $status -PercentComplete ($counter/$AFDatabase.Notifications.Count*100) `
                 -currentOperation $currentoperation
                   
    $counter=$counter + 1
                   
}

 

Write-Host "********** R A P P O R T   N O T I F I C A T I O N  **********"
Write-Host "Date/Heure: " + Get-Date -Format s
Write-Host ""
Write-Host "Enabled: " $CptEnable
Write-Host "Disabled: "  $CptDisable
Write-Host "Error: "  $CptError
Write-Host "None: "  $CptNone
Write-Host "NotReady: "  $CptNotReady
Write-Host "Null: "  $CptNull

Outcomes