Highlighted
Super Contributor.. Super Contributor..
Super Contributor..
426 views

How to check node in NNMi using SOAP API

Jump to solution

Hi Every one,

Recently I got a chance to work on a requirement where whenever an alert is generated in NNMi, we have to check whether the affected node is monitored in NNMi or and then take action accordingly. So I have created a PowerShell script to connect to NNMi SOAP and check the node availability. Below I have provided the script which I have used to complete my requirement. I thought it might be useful for someone as well.

Regards,

Naresh 

 
Labels (3)
Tags (3)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Super Contributor.. Super Contributor..
Super Contributor..
Above script extract 1000 nodes from nnmi. Use below script to check the node in NNMi.


param
(
    $deviceName = 'Devicename',
    $nnmiusername = 'system',
    $nnmipassword = 'password'
)
$Url = "https://nnm/NodeBeanService/NodeBean?wsdl"
if (-not ([System.Management.Automation.PSTypeName]'TrustAllCertsPolicy').Type) {
    Add-Type -TypeDefinition @"
        using System.Net;
        using System.Security.Cryptography.X509Certificates;
        public class TrustAllCertsPolicy : ICertificatePolicy {
            public bool CheckValidationResult(
                ServicePoint srvPoint, X509Certificate certificate,
                WebRequest request, int certificateProblem) {
                return true;
            }
        }
"@
}
[System.Net.ServicePointManager]::Expect100Continue = $false
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy -ErrorAction SilentlyContinue
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$nnmipassword = $nnmipassword | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object pscredential -ArgumentList ($nnmiusername , $nnmipassword)
$Connect_Body = @"
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
   <env:Header></env:Header>
   <env:Body>
      <ns1:getNodes xmlns:ns1='http://node.sdk.nms.ov.hp.com/'>
            <subFilters xsi:type="ns3:condition">
                <name>name</name>
                <operator>EQ</operator>
                <value>$deviceName</value>
            </subFilters>
         </arg0>
      </ns1:getNodes>
   </env:Body></env:Envelope>
"@
$Connect_Params = @{
    Uri         = $Url
    Body        = $Connect_Body
    Method      = 'POST'
    Headers     = @{
        SOAPAction = 'getNodes'
    }
    ContentType = 'text/xml;charset=UTF-8'
}
$RetrieveQueryResults_Request = Invoke-WebRequest @Connect_Params -Credential $Credentials -UseBasicParsing
$RetrieveQueryResults_Response = [xml]($RetrieveQueryResults_Request)
$devicelist = $RetrieveQueryResults_Response.Envelope.Body.getNodesResponse.return.item
$check = "DataNotFound"
foreach ($device in $devicelist) {
    if ([string]$device.name -eq [string]$deviceName) {
        $check = "DataFound"
        $result = [pscustomobject]@{
            DeviceData           = "Found"
            DeviceName           = $device.name
            DeviceSNMPVersion    = $device.snmpVersion
            DeviceManagementMode = $device.managementMode
            Devicestatus         = $device.status
        }| convertto-json
    }
}
if ($check -eq "DataFound") {
    $result 
}
else {
    [pscustomobject]@{
        DeviceData           = "NotFound"
        DeviceName           = $device.name
        DeviceSNMPVersion    = $device.snmpVersion
        DeviceManagementMode = $device.managementMode
        Devicestatus         = $device.status
    } | ConvertTo-Json
}
 
 

Regards,

Naresh

View solution in original post

0 Likes
1 Reply
Highlighted
Super Contributor.. Super Contributor..
Super Contributor..
Above script extract 1000 nodes from nnmi. Use below script to check the node in NNMi.


param
(
    $deviceName = 'Devicename',
    $nnmiusername = 'system',
    $nnmipassword = 'password'
)
$Url = "https://nnm/NodeBeanService/NodeBean?wsdl"
if (-not ([System.Management.Automation.PSTypeName]'TrustAllCertsPolicy').Type) {
    Add-Type -TypeDefinition @"
        using System.Net;
        using System.Security.Cryptography.X509Certificates;
        public class TrustAllCertsPolicy : ICertificatePolicy {
            public bool CheckValidationResult(
                ServicePoint srvPoint, X509Certificate certificate,
                WebRequest request, int certificateProblem) {
                return true;
            }
        }
"@
}
[System.Net.ServicePointManager]::Expect100Continue = $false
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy -ErrorAction SilentlyContinue
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$nnmipassword = $nnmipassword | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object pscredential -ArgumentList ($nnmiusername , $nnmipassword)
$Connect_Body = @"
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
   <env:Header></env:Header>
   <env:Body>
      <ns1:getNodes xmlns:ns1='http://node.sdk.nms.ov.hp.com/'>
            <subFilters xsi:type="ns3:condition">
                <name>name</name>
                <operator>EQ</operator>
                <value>$deviceName</value>
            </subFilters>
         </arg0>
      </ns1:getNodes>
   </env:Body></env:Envelope>
"@
$Connect_Params = @{
    Uri         = $Url
    Body        = $Connect_Body
    Method      = 'POST'
    Headers     = @{
        SOAPAction = 'getNodes'
    }
    ContentType = 'text/xml;charset=UTF-8'
}
$RetrieveQueryResults_Request = Invoke-WebRequest @Connect_Params -Credential $Credentials -UseBasicParsing
$RetrieveQueryResults_Response = [xml]($RetrieveQueryResults_Request)
$devicelist = $RetrieveQueryResults_Response.Envelope.Body.getNodesResponse.return.item
$check = "DataNotFound"
foreach ($device in $devicelist) {
    if ([string]$device.name -eq [string]$deviceName) {
        $check = "DataFound"
        $result = [pscustomobject]@{
            DeviceData           = "Found"
            DeviceName           = $device.name
            DeviceSNMPVersion    = $device.snmpVersion
            DeviceManagementMode = $device.managementMode
            Devicestatus         = $device.status
        }| convertto-json
    }
}
if ($check -eq "DataFound") {
    $result 
}
else {
    [pscustomobject]@{
        DeviceData           = "NotFound"
        DeviceName           = $device.name
        DeviceSNMPVersion    = $device.snmpVersion
        DeviceManagementMode = $device.managementMode
        Devicestatus         = $device.status
    } | ConvertTo-Json
}
 
 

Regards,

Naresh

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.