#region Copyright /* * Copyright © 2014-2016 NetApp, Inc. All Rights Reserved. * * CONFIDENTIALITY NOTICE: THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION OF * NETAPP, INC. USE, DISCLOSURE OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR * EXPRESS WRITTEN PERMISSION OF NETAPP, INC. */ #endregion #region Using Directives using System; using System.ComponentModel; using System.Linq; using System.Management.Automation; using SolidFire.Core.Helpers; using System.Management.Automation.Runspaces; using SolidFire.Core; using SolidFire.Element.Api; #endregion namespace SolidFire.Cluster.Add { /// /// /// [Cmdlet(VerbsCommon.Add, "SFSnmpTrapRecipient", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.None)] public class AddSFSnmpTrapRecipient : SFCmdlet { #region Private Data /// /// Member used to host a nested Pipeline for calling other CmdLets /// private Pipeline pipeline = null; #endregion #region Parameters /// /// The IP address or host name of the target network management station /// [Parameter(Position = 0, Mandatory = true, HelpMessage = "The IP address or host name of the target network management station.")] public new String Host { get; set; } /// /// The IP address or host name of the target network management station /// [Parameter(Position = 1, Mandatory = true, HelpMessage = "SNMP community string..")] public String Community { get; set; } /// /// The UDP port number on the host where the trap is to be sent. Valid range is 1 – 65535. 0 (zero) is not a valid port number. Default is 162 /// [Parameter(Position = 2, Mandatory = true, HelpMessage = "The UDP port number on the host where the trap is to be sent. Valid range is 1 – 65535. 0 (zero) is not a valid port number. Most SNMP ports are at 162.")] public int Port { get; set; } #endregion #region Cmdlet Overrides protected override void BeginProcessing() { base.BeginProcessing(); CheckConnection(); pipeline = Runspace.DefaultRunspace.CreateNestedPipeline(); } protected override void EndProcessing() { base.EndProcessing(); var command = new Command("Get-SFSnmpTrapInfo"); pipeline.Commands.Add(command); // Send it to the pipline WriteObject(pipeline.Invoke(), true); pipeline = null; } /// /// Implementation for processing the execution of the cmdlet. /// protected override void ProcessRecord() { base.ProcessRecord(); // Get the current TrapRecipients var objsFromAPI = SendRequest("GetSnmpTrapInfo"); foreach (var obj in objsFromAPI) { var recipients = obj.Result.TrapRecipients.ToList(); var newRecipient = new SnmpTrapRecipient(); newRecipient.Host = Host; newRecipient.Community = Community; newRecipient.Port = Port; recipients.Add(newRecipient); // Assemble the parameters object with unique recipients var request = new SetSnmpTrapInfoRequest(); request.ClusterEventTrapsEnabled = obj.Result.ClusterEventTrapsEnabled; request.ClusterFaultResolvedTrapsEnabled = obj.Result.ClusterFaultResolvedTrapsEnabled; request.ClusterFaultTrapsEnabled = obj.Result.ClusterFaultTrapsEnabled; request.TrapRecipients = recipients.ToArray(); if (WhatIfShouldProcessHandler(String.Format(obj.Target.Target))) { var objFromAPI = SingleConnectionRequest("SetSnmpTrapInfo", obj.Target, request); if (SolidFireUtilities.HasAPIError(objFromAPI.Error, this)) return; } } } #endregion } }