Showing posts with label Solarwinds. Show all posts
Showing posts with label Solarwinds. Show all posts

Wednesday, October 17, 2012

Using The Solarwinds IPmonitor API WSDL Webservice With SOAP And XPATH

<?php
function dumpDOMnodeList($xml)
{
    //USED TO DUMP THE XPATH RESULTS
    $docTmp = new DOMDocument();
    foreach($xml as $n) $docTmp->appendChild($docTmp->importNode($n,true));
    print_r($docTmp->saveHTML());
}

$soapVersion = '1.2';
$soapLocation = 'https://domain.com/soap/status.asmx?WSDL';
$soapContext = stream_context_create(array('ssl' => array('verify_peer' => FALSE)));
$soapParameters = array (
            'location' => $soapLocation,
            'login' => 'login',
            'password' => 'password',
            'stream_context' => $soapContext
            );         

//IPM.WSDL IS A LOCAL COPY OF STATUS.ASMX?WSDL
$soapClient = new SoapClient('ipm.wsdl',$soapParameters); 

//GET GROUPS
/*
$soapRequest = '<?xml version="1.0" encoding="utf-8"?>';
$soapAction = 'http://schemas.ipmonitor.com/ipm70/GetGroups';
*/

//GET MONITORS
/*MAIN GROUP WITHIN IPM, NEVER CHANGES CAN BE OBTAINED BY USING "GetGroups" METHOD... 
IT IS THE MAIN gtGroup ID WRAPPING THE RESPONSE*/
$groupID = 'XXXXXXXXXXXX'; 
$justTrouble = 'TRUE'; // ONLY RETURN DISTRESSED MONITORS

$soapRequest = '<?xml version="1.0" encoding="utf-8"?>'.$groupID.''.$justTrouble.'';
$soapAction = 'http://schemas.ipmonitor.com/ipm70/GetMonitors';

$soapResult = $soapClient->__doRequest($soapRequest, $soapLocation, $soapAction, $soapVersion); //REQUEST, LOCATION, ACTION, VERSION

$doc = new DOMDocument();
$doc->LoadXML($soapResult);

$xpath = new DOMXpath($doc);
$xpath->registerNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
$xpath->registerNamespace('def', 'http://schemas.ipmonitor.com/ipm70/'); 

$alerts = $xpath->query("/soap:Envelope/soap:Body/def:GetMonitorsResponse/def:GetMonitorsResult/def:rtMonitor");

dumpDOMnodeList($alerts);
?>