This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

401 Access Denied using the WSDL API

FormerMember
FormerMember

I am running ipMonitor 10.6 and cannot for the LIFE of me connect to the WSDL via code.

I can see the URL in my browser just fine, but, on the same machine, via code, I immediately get a 401 Access Denied error whether I use SOAP or CURL.

Documentation is dry at best and there aren't many examples out there.

$context = stream_context_create(array('ssl' => array('verify_peer' => FALSE)));

$soapURL = 'https://domain.com/soap/status.asmx?wsdl';

$soapParameters = array  (

            'login' => 'user',

            'password' => 'password',

            'WSDL' => TRUE,

            'stream_context' => $context

            );

$soapClient = new SoapClient($soapURL,$soapParameters);

And that yields:

HTTP request failed! HTTP/1.0 401 Access Denied

  • ipMonitor uses a self-signed SSL cert that the application may be having issue with. Perhaps we can try to connect without SSL to test: http://<IP>:8080/soap/config.asmx


  • FormerMember
    0 FormerMember in reply to rob.hock

    Didn't make a difference unfortunately.

    The username I'm passing is a full administrator and I've confirmed the IP's I'm coming from are both allowed in the local firewall and allowed in the IPM configuration tool for IP restrictions.

  • If you can't access the SOAP interface config (http://<IP>:8080/soap/config.asmx) then we have something else going on here besides programmatic access issues. A support ticket would likely be the best course of action. http://www.solarwinds.com/support/ticket/

  • FormerMember
    0 FormerMember in reply to rob.hock

    I've heard scary things about people asking support for API problems claiming "they don't support third party applications" but that was mainly older threads where there was once no API emoticons_wink.png

    I'll open up a ticket tomorrow when I'm back on-site and see what they have to say.

    I did try both config.asmx and status.asmx FWIW

    Curiously, on the local server I tried:

    https://localhost/soap/status.asmx

    ...and I AM prompted for HTTP auth login AND the username and password I've defined in my code DOES work.

    It's almost like it's not allowing access from outside the server.

    Is there a restriction list/setting for API access?

  • Can you telnet to 8080 from another machine to that server? If it doesn't even handshake, that would usually point to (Windows) firewall. If so, can we confirm it's off?

  • FormerMember
    0 FormerMember in reply to rob.hock

    Well I managed to get it by gleaming from some other non-related SOAP examples:

    ==========================================

    $context = stream_context_create(array('ssl' => array('verify_peer' => FALSE)));

    $soapParameters = array (

      'location' => 'https://domain.com/soap/status.asmx?WSDL',

      'uri'   => 'urn:TC',

      'login' => 'login',

      'password' => password',

      'WSDL' => TRUE,

      'stream_context' => $context

      );

    $soapClient = new SoapClient(NULL,$soapParameters);

    $soapMessage = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetGroups xmlns="http://schemas.ipmonitor.com/ipm70/" /></soap:Body></soap:Envelope>';

    $soapAction = "http://schemas.ipmonitor.com/ipm70/GetGroups";

    $result = $soapClient->send($soapMessage, $soapAction);

    echo '<pre>';

    print_r($result);

    ==========================================

    I had to move the URL to "location" in the options along with a "uri" option that I took a swing at as I didn't see any urn references.. I also had to use NULL as my first parameter for the soapClient instantiation

    So the only issue I have now is I am getting the following error:

    Uncaught SoapFault exception: [VersionMismatch] Wrong Version

    Stack trace: #0 [internal function]: SoapClient->__call('send', Array) #1 index.php(17):

    SoapClient->send('<?xml version="...', 'http://schemas....')

    I will gladly open another thread for this issue if that's the convention on these forums =)

    Thanks for the assistance thus far.

  • FormerMember
    0 FormerMember in reply to FormerMember

    Little more info...

    I wget'd the contents of status.asmx?wsdl to ipm.wsdl on my dev server and made the following changes:

    Commented:

    'uri'   => 'urn:TC',

    ^this is only needed when not using WSDL mode


    Changed the NULL reference (nonWSDL mode) to "ipm.wsdl" (so now I'm working in WSDL mode)

    A new error renders it's ugly head:

    Uncaught SoapFault exception: [Client] Function ("send") is not a valid method for this service

    I'm pushing through, I'm DETERMINED!!! =)

  • FormerMember
    0 FormerMember

    I now have a working example with GetGroups:

    $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' => 'user',

      'password' => password',

      'WSDL' => TRUE,

      'stream_context' => $soapContext

      );

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

    //GET GROUPS

    $soapRequest = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetGroups xmlns="http://schemas.ipmonitor.com/ipm70/" /></soap:Body></soap:Envelope>';

    $soapAction = "http://schemas.ipmonitor.com/ipm70/GetGroups";

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

    echo '<pre>';

    print_r($result);

  • FormerMember
    0 FormerMember in reply to FormerMember

    So the next question becomes, to get a list of all the monitors that are in distress do I have to iterate EVERY rtGroup ID over GetMonitors with the flag for TroubleOnly set...

    Hrmmmm...Do I load the result into a DOM document and xpath it for non-up statuses oooor do I iterate exhaustively over SOAP

    Stay tuned :grin:

  • FormerMember
    0 FormerMember

    Success!

    This is a full example of connecting to the webservice and returning just the monitors that are in distress:

    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

                );

              

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

    //GET GROUPS

    /*

    $soapRequest = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetGroups xmlns="http://schemas.ipmonitor.com/ipm70/" /></soap:Body></soap:Envelope>';

    $soapAction = 'http://schemas.ipmonitor.com/ipm70/GetGroups';

    */

    //GET MONITORS

    $groupID = 'XXXXXXXXXXXX'; //MAIN GROUP WITHIN IPM, NEVER CHANGES CAN BE OBTAINED BY USING "GetGroups" METHOD... IS THE MAIN gtGroup ID WRAPPING THE RESPONSE

    $justTrouble = 'TRUE'; // ONLY RETURN DISTRESSED MONITORS

    $soapRequest = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetMonitors xmlns="http://schemas.ipmonitor.com/ipm70/"><groupid>'.$groupID.'</groupid><bTroubleOnly>'.$justTrouble.'</bTroubleOnly></GetMonitors></soap:Body></soap:Envelope>';

    $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);

    Registering the "def" namespace was the only hitch and only visible after dumping the NodeList to see a different namespace than SOAP was being used inside the envelope->body of the response

    I severely hope this helps someone =)