Hi Everyone,
I've been trying to get a PHP page I've been writing to start a Discovery Profile, but it seems to be getting hung up on getting the XML Context into JSON format so that I can send it it the REST API via cURL.
Has anyone been able to do this before, and if not, does anyone have any ideas?
I am relatively new to PHP and curl, so I'm sure I've missed some obvious things.
I've set the following XML equal to the variable $core_plugin which I later try to pass into an Invoke call.
<CorePluginConfigurationContext xmlns='http://schemas.solarwinds.com/2012/Orion/Core' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'> <BulkList> <IpAddress> <Address> </Address> </IpAddress> </BulkList> <Credentials> <SharedCredentialInfo> <CredentialID>1</CredentialID> <Order>1</Order> </SharedCredentialInfo> </Credentials> <WmiRetriesCount>0</WmiRetriesCount> <WmiRetryIntervalMiliseconds>1000</WmiRetryIntervalMiliseconds></CorePluginConfigurationContext>
which I then do this is PHP
// Construct the Core Plugin XML Document, then Have Solarwinds Build the Plugin $info = simplexml_load_string($core_plugin); $info->BulkList->IpAddress->Address = "10.10.10.10"; $updated_core_plugin = $info->asXML(); $core_plugin_url = "https://solarwindsServer.com:17778/SolarWinds/InformationService/v3/Json/Invoke/Orion.Discovery/CreateCorePluginConfiguration"; $core_plugin_data = array('context' => "$updated_core_plugin"); $json_core_plugin = json_encode($core_plugin_data); $finished_core_plugin = CallAPI($core_plugin_url, $json_core_plugin); function CallAPI($url, $data = false) { $ch = curl_init(); // Authentication: curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, "username:password"); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-type: application/json', 'Content-length: ' . strlen($data) )); $result = curl_exec($ch); $response = curl_getinfo($ch, CURLINFO_HTTP_CODE); $error = curl_error($ch); $info = curl_getinfo($ch); curl_close($ch); if ($result == false) { echo "Response: " . $response . " "; echo "Error: " . $error . " "; echo "Info: " . print_r($info); die(); } return $result; }
If you need anything else from me, please let me know.
Just FYI, the curl section was from another user on Thwack.
Thanks,
Jordan