Page 1 of 1

Getting information out of an array.

Posted: Tue Feb 21, 2012 1:12 pm
by trsix
I am trying to get information out of an APC InfraStruXure server. Here is what I have so far.

Code: Select all

        ini_set('display_errors', 1);
        $wsdl = 'http://infrastruxureserver/integration/services/ISXCentralAlarmsService_v1_0?wsdl';
        $client = new SoapClient($wsdl, array('login' => 'mylogin',
            'password' => 'mypassword', 'trace' => true ));
        
        $alarms = array($client->getAllActiveAlarms('GetAllActiveAlarmsRequest 
            $getAllActiveAlarmsRequest'));
When I run this code, I get the response back from the server and the data is populated into $array.

The problem is the $array has only 1 entry. But, that 1 entry has everything in it, its like the response from the server is just 1 long string. How do I change the information from the server into something readable/workable?

Below is the response from the server, my question is how do I pull just the ["deviceID"] out of the response?

Code: Select all

array(1) {
  [0]=>
  object(stdClass)#2 (1) {
    ["ArrayOfISXCAlarm"]=>
    object(stdClass)#3 (1) {
      ["ISXCAlarm"]=>
      array(6) {
        [0]=>
        object(stdClass)#4 (9) {
          ["ISXCElement"]=>
          object(stdClass)#5 (2) {
            ["ISXCElementType"]=>
            string(5) "ALARM"
            ["id"]=>
            string(28) "B47c4e4_nbErrorCond_C20CD4D9"
          }
          ["activeTime"]=>
          string(29) "2012-02-17T09:48:41.837-08:00"
          ["ISXCAlarmSeverity"]=>
          string(8) "CRITICAL"
          ["ISXCAlarmState"]=>
          string(6) "ACTIVE"
          ["description"]=>
          string(56) "An automatic voltage regulator (AVR) relay fault exists."
          ["deviceID"]=>
          string(25) "B47c4e4_nbSNMPEnc8CCE6A96"
          ["recommendedAction"]=>
          string(130) "Recommended Action: An internal hardware failure exists. Contact APC Support (http://www.apc.com/go/direct/index.cfm?tag=support)."
          ["resolvedTime"]=>
          NULL
          ["sensorID"]=>
          string(0) ""
        }
        [1]=>
        object(stdClass)#6 (9) {
          ["ISXCElement"]=>
          object(stdClass)#7 (2) {
            ["ISXCElementType"]=>
            string(5) "ALARM"
            ["id"]=>
            string(28) "B47c4e4_nbErrorCond_6675CD85"
          }
          ["activeTime"]=>
          string(29) "2012-02-17T09:48:41.866-08:00"
          ["ISXCAlarmSeverity"]=>
          string(8) "CRITICAL"
          ["ISXCAlarmState"]=>
          string(6) "ACTIVE"
          ["description"]=>
          string(31) "The output power is turned off."
          ["deviceID"]=>
          string(25) "B47c4e4_nbSNMPEnc8CCE6A96"
          ["recommendedAction"]=>
          string(107) "Recommended Action: When the load equipment is ready to use the output power from the UPS, turn on the UPS."
          ["resolvedTime"]=>
          NULL
          ["sensorID"]=>
          string(0) ""
        }
        [2]=>
        object(stdClass)#8 (9) {
          ["ISXCElement"]=>
          object(stdClass)#9 (2) {
            ["ISXCElementType"]=>
            string(5) "ALARM"
            ["id"]=>
            string(28) "B02A0D8_nbErrorCond_59CD6E50"
          }
          ["activeTime"]=>
          string(29) "2012-02-20T10:50:35.600-08:00"
          ["ISXCAlarmSeverity"]=>
          string(5) "ERROR"
          ["ISXCAlarmState"]=>
          string(6) "ACTIVE"
          ["description"]=>
          string(78) "The value of 'Door Switch' (Open) indicates that a 'Error' alert has occurred."
          ["deviceID"]=>
          string(18) "B02A0D8_nbEyeEnc_0"
          ["recommendedAction"]=>
          string(0) ""
          ["resolvedTime"]=>
          NULL
          ["sensorID"]=>
          string(23) "B02A0D8_nbEyeEnc_0_DOOR"
        }
        [3]=>
        object(stdClass)#10 (9) {
          ["ISXCElement"]=>
          object(stdClass)#11 (2) {
            ["ISXCElementType"]=>
            string(5) "ALARM"
            ["id"]=>
            string(28) "B031628_nbErrorCond_51F3F9BC"
          }
          ["activeTime"]=>
          string(29) "2012-02-21T11:00:26.931-08:00"
          ["ISXCAlarmSeverity"]=>
          string(5) "ERROR"
          ["ISXCAlarmState"]=>
          string(6) "ACTIVE"
          ["description"]=>
          string(68) "The current value of 'Base Unit Temperature' (20.4 °C) is too high."
          ["deviceID"]=>
          string(19) "B031628_nbHawkEnc_0"
          ["recommendedAction"]=>
          string(0) ""
          ["resolvedTime"]=>
          NULL
          ["sensorID"]=>
          string(24) "B031628_nbHawkEnc_0_TEMP"
        }
        [4]=>
        object(stdClass)#12 (9) {
          ["ISXCElement"]=>
          object(stdClass)#13 (2) {
            ["ISXCElementType"]=>
            string(5) "ALARM"
            ["id"]=>
            string(28) "B47c4e4_nbErrorCond_4195C86A"
          }
          ["activeTime"]=>
          string(29) "2012-02-21T08:07:29.806-08:00"
          ["ISXCAlarmSeverity"]=>
          string(7) "FAILURE"
          ["ISXCAlarmState"]=>
          string(6) "ACTIVE"
          ["description"]=>
          string(60) "Communication with 'PHXUPS10(172.21.243.192)' has been lost."
          ["deviceID"]=>
          string(25) "B47c4e4_nbSNMPEnc5DB59B5C"
          ["recommendedAction"]=>
          string(0) ""
          ["resolvedTime"]=>
          NULL
          ["sensorID"]=>
          string(32) "B47c4e4_nbSNMPEnc5DB59B5C_STATUS"
        }
        [5]=>
        object(stdClass)#14 (9) {
          ["ISXCElement"]=>
          object(stdClass)#15 (2) {
            ["ISXCElementType"]=>
            string(5) "ALARM"
            ["id"]=>
            string(28) "B47c4e4_nbErrorCond_44746E71"
          }
          ["activeTime"]=>
          string(29) "2012-02-17T09:48:41.840-08:00"
          ["ISXCAlarmSeverity"]=>
          string(8) "CRITICAL"
          ["ISXCAlarmState"]=>
          string(6) "ACTIVE"
          ["description"]=>
          string(35) "At least one faulty battery exists."
          ["deviceID"]=>
          string(25) "B47c4e4_nbSNMPEncDCA7D145"
          ["recommendedAction"]=>
          string(171) "Recommended Action: Replace all faulty batteries. You can use the APC Product Selectors (http://www.apc.com/go/direct/index.cfm?tag=selectors) page to order new batteries."
          ["resolvedTime"]=>
          NULL
          ["sensorID"]=>
          string(0) ""
        }
      }
    }
  }
}

Re: Getting information out of an array.

Posted: Tue Feb 21, 2012 1:53 pm
by twinedev
Try the following... Not sure without actually having the raw data to test on.

Code: Select all

foreach ($array[0]->ArrayOfISXCAlarm->ISXCAlarm as $key=>$aryData) {
	echo "\nKey: $key : ",$aryData->deviceID;
}

Re: Getting information out of an array.

Posted: Tue Feb 21, 2012 3:51 pm
by trsix
Wow, you really know your stuff.

worked perfectly (had to change $array to my $alarms).
[text]Key: 0 : B47c4e4_nbSNMPEnc8CCE6A96 Key: 1 : B47c4e4_nbSNMPEnc8CCE6A96 Key: 2 : B47c4e4_nbSNMPEnc5DB59B5C Key: 3 : B47c4e4_nbSNMPEncDCA7D145[/text]