#!/usr/bin/php -q 5) { // if the number of arguments isnt above 5 then don't bother with the where = etc $condition_key = $argv[5]; $condition_val = escapeshellarg($argv[6]); } else { $condition_key = null; $condition_val = null; }; $wmiquery = 'SELECT '.$columns.' FROM '.$wmiclass; // basic query built if ($condition_key != null) { $wmiquery = $wmiquery.' WHERE '.$condition_key.'='.$condition_val; // if the query has a filter argument add it in }; $wmiquery = '"'.$wmiquery.'"'; // encapsulate the query in " " $wmiexec = $wmiexe.' -U '.$user.'%'.$pass.' //'.$host.' '.$wmiquery; // setup the query to be run exec($wmiexec,$wmiout); // execute the query if ($dbug == 1) { // basic debug, show output in easy to read format and display the exact execution command echo "\n\n".$wmiexec."\n\n"; $sep = "\n"; }; if ($dbug == 2) { // advanced debug, logs everything to file for full debug $dbug_log = $log_location.'dbug_'.$host.'.log'; $fp = fopen($dbug_log,'a+'); $dbug_time = date('l jS \of F Y h:i:s A'); fwrite($fp,"Time: $dbug_time\nWMI Class: $wmiclass\nCredential: $credential\nColumns: $columns\nCondition Key: $condition_key\nCondition Val: $condition_val\nQuery: $wmiquery\nExec: $wmiexec\nOutput:\n".$wmiout[0]."\n".$wmiout[1]."\n"); }; if(strstr($wmiout[0],'ERROR') != false) { exit; }; if (count($wmiout) > 0) { $names = explode('|',$wmiout[1]); // build the names list to dymanically output it for($i=2;$i 3 ) { $inc = $i-2; }; // if there are multiple rows returned add an incremental number to the returned keyname $output = $output.$names[$j++].$inc.':'.str_replace(array(':',' '),array('','_'),$item).$sep; }; }; }; if ($dbug == 2) { fwrite($fp,"Output to Cacti: $output\n\n\n"); fclose($fp); }; echo $output; ?>