Active IQ Unified Manager Discussions

OCUM 7.2 - Powershell Script for Quota Breach Custom Email to Specific Email DL

DevoidB
7,030 Views

 

Description:

Currently customer notification of soft/hard quota breach is a manual process within my company. We recieve an alert to our storage email group (DL) and then follow up by looking up the owning customer to then email them or their email DL ourselve.

 

I would like to live in a world where this can happen automagically with a bit of setup from either existing tools within OCUM 7.2 or building a custom script in say powershell that I attach to certain groupings of qtree's based on their owners as part of the provisioning process.

 

Background Information:

I have reviewed a fair number of documents from here and Cosonok on the rules to OCUM scripting and still cant seem to wrap my head around what a simple OCUM script would look like for any situation let alone my own.

 

I have attempted to use the "Quota Email" portion in the settings to manipulate where specifically named qtrees quota breach alerts should be routed but that doesnt seem very scalable for more than a few qtree's. I have landed on scripts as they can be a bit more dynamic and pull information from other parts of my environment. I have chosen powershell as it is what I am most familiar with of the option OCUM presents for its scripts.

 

Example:

Qtree: Test1

Event: Soft Limit Breach

Owner: Customer_A@Company_A.com

 

Automatic email

 

To: Customer_A@Company_A.com

From: Storage Team

Subject:<$Event>  <$Quota_Used>

Body:

Hello Customer_A,

 

<$QTREE> has breached 95% of its maximum capacity <$Quota_Used>

 

Please either free up storage on this share or place a request for more storage.

 

Thank you,

Storage Team

 

 

 

5 REPLIES 5

DevoidB
6,763 Views

I realize now that there are a number of posts on this topic with varying levels of information and relavence. So I will attempt to document my findings as I attempt to solve my own problem.

 

So far I have learned that the OCUM virtual appliance does not accept powershell scripts but instead shell or perl.

 

as such I have found the following posts helpful in starting to learn about how to create a perl script that works for me.

 

Great article for where scripts are placed and how to review how your scripts performed: https://community.netapp.com/t5/OnCommand-Storage-Management-Software-Discussions/customizing-mails-from-ocum-7-1/m-p/131149#M23751

 

Basic perl script to start with: https://community.netapp.com/t5/OnCommand-Storage-Management-Software-Discussions/OnCommand-Unified-Manager-alert-script-integration/td-p/128784

 

perl basics for sendmail: https://community.netapp.com/t5/OnCommand-Storage-Management-Software-Discussions/OnCommand-Unified-Manager-alert-script-integration/td-p/128784

 

Alot of this info comes from @mbeattie so be sure to thank him if you'd like.

 

I will try and scrape together a rough outline of my perl script in the coming weeks and post what else I come up with.

 

Thanks all!

 

 

 

 

DevoidB
6,749 Views

Running into an issue where there is no sendmail utility pre-built into the OCUM vapp. I verified this by checking in /usr/bin/ /usr/sbin & /sbin directories for anything that had to do with sending mail. Am I under the right impression that we must download such a utility through apt-get? If so what does this do for the suportablity of our OCUM 7.2 vapp?

 

On a different Note, I am not 100% sure which ARGV is which so I am trying to play around with the sample perl script to make a bit of a map of these ARGV's. These may not work for eveything but this is what I came up with.

 

$ARGV[0] = eventID
$ARGV[1] = <eventID Results>

 

$ARGV[2] = eventName
$ARGV[3] = <eventName Results>

 

$ARGV[4] = eventSeverity
$ARGV[5] = <eventSeverity Results>

 

$ARGV[6] = eventSourceID
$ARGV[7] = <eventSourceID Results>

 

$ARGV[8] = eventSourceName
$ARGV[9] = <eventSourceName Results>

 

$ARGV[10] = eventSourceType
$ARGV[11] = <eventSource Type Results>

 

$ARGV[12] = eventState
$ARGV[13] = <eventState Results>

 

$ARGV[14] = eventArgs
$ARGV[15] = <eventArgs Results>

 

 

mbeattie
6,715 Views

Hi,

 

You will need to install the binaries. The following KB article describes the process of how to login as the diag user which will enable you to install binaries

(assuming your OCUM vApp has internet access to download the modules)

 

https://kb.netapp.com/support/s/article/ka31A00000012qfQAA/How-to-access-the-OnCommand-Virtual-Machine-DIAG-shell

 

When logged in as the diag user, the following commands which includes the PERL modules for calling WFA workflows:

 

 

sudo cpan App::cpanminus
sudo cpanm REST::Client
sudo cpanm JSON
sudo cpanm MIME::Base64
sudo cpanm Mail::Sendmail

Please note that the OCUM vApp is locked down appliance from a support perspective. Any PERL scripts you create or third party binaries that you install would NOT be supported.

I'd recommend either the RHEL or Windows versions of OCUM if you intend on using the script plugin to automate alerts.

 

If you do want to use PowerShell and you are using the OCUM vApp then i'd recommend that your PERL script calls a WFA workflow passing the EventID as a single parameter. You can then use WFA to invoke the "event-iter" OCUM ZAPI via PowerShell to enumerate the event information. This would be useful in the instance that you are integrating the OCUM vApp in a Windows environment and need your alert to intergrate with Microsoft Applications that use PowerShell. Also the ARGV variables numbers are not constant (IE the number of Arguements can change depending on the event so specifiying them by number may not provide predictable results).

 

There is an example PERL script that you might find useful in this TR. (See page 22)

 

http://www.netapp.com/us/media/tr-4585.pdf

 

Hope that helps? Please let me know if you have any questions.

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

mbeattie
6,713 Views

Hi,

 

Just FYI if you have WFA installed and you want it to connect to OCUM and enumerate the properties of an event by ID then here is the PowerShell code to do it using the OCUM "event-iter" ZAPI...

 

Param(
   [Parameter(Mandatory=$True, HelpMessage="The IP Address or FQDN of the OCUM server")]   
   [String]$Hostname,
   [Parameter(Mandatory=$True, HelpMessage="The OCUM Event ID number")]
   [Int]$EventId
)
#'------------------------------------------------------------------------------
Function ConvertFrom-UnixTimeStamp{
   [CmdletBinding()]
   Param(
      [Parameter(Position=0,
         Mandatory=$True,
         ValueFromPipeLine=$True,
         ValueFromPipeLineByPropertyName=$True)]
      [String]$Timestamp
   )
   Return (Get-Date($([TimeZone]::CurrentTimeZone.ToLocalTime(([DateTime]'1/1/1970').AddSeconds($Timestamp)))) -uformat "%Y-%m-%d %H:%M:%S");
}#End Function
#'------------------------------------------------------------------------------
Get-WFALogger -Info -Message "Processing OCUM event ID`: $EventID on server`: $Hostname"
$credentials = Get-WfaCredentials -Host $Hostname
$naServer    = New-WfaZapiServer -Host $Hostname -Type DFM -Credentials $credentials
#'------------------------------------------------------------------------------
#'Invoke the "event-iter" ZAPI to enumerate the event information.
#'------------------------------------------------------------------------------
Try{
   $naElement = New-Object NetApp.Manage.naElement("event-iter")
   $naElement.AddNewChild("event-id", $EventID)
   [Xml]$output = $naServer.InvokeElem($naElement)
}Catch{
   Throw $("Failed enumerating OnCommand Unified Manager Events on ""$Hostname"". Error " + $_.Exception.Message)
}
#'------------------------------------------------------------------------------
#'Exit if there are no events matching the event ID 
#'------------------------------------------------------------------------------
If($output.results.'num-records' -eq 0){
   Throw $("There are no events matching ID`: " + $EventID)
}
#'------------------------------------------------------------------------------
#'Display the event information
#'------------------------------------------------------------------------------
Get-WFALogger -Info -Message $("There is " + $output.results.'num-records' + " events match Event ID`: $eventID")
$event = $output.results.'records'.'event-info'
Get-WFALogger -Info -Message $("event-about`:"               + $event.'event-about')
Get-WFALogger -Info -Message $("event-category`:"            + $event.'event-category')
Get-WFALogger -Info -Message $("event-condition`:"           + $event.'event-condition')
Get-WFALogger -Info -Message $("event-id`:"                  + $event.'event-id')
Get-WFALogger -Info -Message $("event-impact-area`:"         + $event.'event-impact-area')
Get-WFALogger -Info -Message $("event-impact-level`:"        + $event.'event-impact-level')
Get-WFALogger -Info -Message $("event-name`:"                + $event.'event-name')
Get-WFALogger -Info -Message $("event-severity`:"            + $event.'event-severity')
Get-WFALogger -Info -Message $("event-source-name`:"         + $event.'event-source-name')
Get-WFALogger -Info -Message $("event-source-resource-key`:" + $event.'event-source-resource-key')
Get-WFALogger -Info -Message $("event-source-type`:"         + $event.'event-source-type')
Get-WFALogger -Info -Message $("event-state`:"               + $event.'event-state')
Get-WFALogger -Info -Message $("event-time`:"                + $event.'event-time')
Get-WFALogger -Info -Message $("event-timestamp`:"           + $(ConvertFrom-UnixTimeStamp($event.'event-time')))
Get-WFALogger -Info -Message $("event-type`:"                + $event.'event-type')
Get-WFALogger -Info -Message "event-arguments`:"
$keyPairs = $event.'event-arguments'
ForEach($keyPair In $keyPairs.'key-value-pair'){
   $argKey   = $keyPair.'key'
   $argValue = $keyPair.'value'
   Get-WFALogger -Info -Message "$argKey = $argValue"
}
#'------------------------------------------------------------------------------ 

This should help if you need to enumerate the event information and pass it to a windows application via PowerShell.

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

GidonMarcus
5,837 Views

Hi

 

Adding here  two PS lines you can use to consume the parameters into a hashtable on Alert-triggered scripts in OCUM (instead of using $args[1], $args[5] etc.) 

 

#Create hashtable, Get rid of chars that break the script, append any word that start with " -" to a hashtable index with the input following it until the next " -" as a value.
$parms=@{};" "+($args -replace "\]|\[|@"," " -join " ") -split " -"|?{$_}|%{$t=$_ -split " ",2;$parms.($t[0])=$t[1]}

#Run on $parms.eventArgs and append the first word before a "=" as a eventArgs_* index, and as the value any words after it,  until the next word that come before "=".
($parms.eventArgs -split " "|%{if($_ -match "="){".cut."}$_}) -join " " -split ".cut. "|?{$_}|%{$t=$_ -split "=";$parms.("eventArgs_"+$t[0])=$t[1]}  

Exmple of use for sending a custom email and processing it more - avail here:

 

http://community.netapp.com/t5/OnCommand-Storage-Management-Software-Discussions/HOW-TO-consume-parameters-from-OCUM-on-a-PowerShell-script-and-genera...

 

Gidi

Gidi Marcus (Linkedin) - Storage and Microsoft technologies consultant - Hydro IT LTD - UK
Public