Working with json output
// This is how I went through the json output to extract all the details.
public function ProsessIloData($arr, $IPv4Addr, $indent) {
$Output = '';
if ($arr) {
foreach ($arr as $key => $value) {
if (is_array($value)) {
//
ProsessIloData($value, $IPv4Addr, $indent . $key . '_');
} else {
// Output
$Output = $Output . "
Key: " . $indent . $key . ' Value: ' . $value . "
";
// Remove the rem statment from the line below to show all the keys and the values.
// echo "
Key: " . $key . ' Value: ' . $value . "
";
// Create a new elseif statment for each key you want the value for.
if($indent . $key == "AssetTag"){
$AssetTag = '';
$AssetTag = $value;
Update_sql("`AssetTag`= '" . $AssetTag . "'", $IPv4Addr);
}elseif($indent . $key == "BiosVersion"){
$BiosVersion = '';
$BiosVersion = $value;
Update_sql("`BiosVersion`= '" . $BiosVersion . "'", $IPv4Addr);
}
}
}
}
}
// This is how I updated the database by using the IP as the WHERE
public function Update_sql($sql, $IPv4Addr){
global $wpdb;
$ilo_hardware_Table = $wpdb->prefix . 'ilo_hardware';
$ilo_hardware_update_sql = "UPDATE " . $ilo_hardware_Table . " SET
" . $sql . "
WHERE `IP_Address` = '" . $IPv4Addr . "'";
$wpdb->query($ilo_hardware_update_sql);
if ($wpdb->last_error !== '') :
$str = htmlspecialchars($wpdb->last_result, ENT_QUOTES);
$query = htmlspecialchars($wpdb->last_query, ENT_QUOTES);
print "
WordPress database error: [$str]
$query
";
endif;
}