How to use hdd_temp class

Best Phoronix-test-suite code snippet using hdd_temp

ipmi_helpers.php

Source:ipmi_helpers.php Github

copy

Full Screen

1<?2require_once '/usr/local/emhttp/plugins/ipmi/include/ipmi_options.php';3require_once '/usr/local/emhttp/plugins/ipmi/include/ipmi_drives.php';4$action = array_key_exists('action', $_GET) ? htmlspecialchars($_GET['action']) : '';5$hdd_temp = get_highest_temp();6if (!empty($action)) {7 $state = ['Critical' => 'red', 'Warning' => 'yellow', 'Nominal' => 'green', 'N/A' => 'blue'];8 if ($action === 'ipmisensors'){9 $return = ['Sensors' => ipmi_sensors($ignore),'Network' => ($netsvc === 'enable'),'State' => $state];10 echo json_encode($return);11 }12 elseif($action === 'ipmievents'){13 $return = ['Events' => ipmi_events(),'Network' => ($netsvc === 'enable'),'State' => $state];14 echo json_encode($return);15 }16 elseif($action === 'ipmiarch'){17 $return = ['Archives' => ipmi_events(true), 'Network' => ($netsvc === 'enable'), 'State' => $state];18 echo json_encode($return);19 }20 elseif($action === 'ipmidash') {21 $return = ['Sensors' => ipmi_sensors($dignore), 'Network' => ($netsvc === 'enable'),'State' => $state];22 echo json_encode($return);23 }24}25/* get highest temp of hard drives */26function get_highest_temp(){27 global $devignore;28 $ignore = array_flip(explode(',', $devignore));29 //get UA devices30 $ua_json = '/var/state/unassigned.devices/hdd_temp.json';31 $ua_devs = file_exists($ua_json) ? json_decode(file_get_contents($ua_json), true) : [];32 //get all hard drives33 $hdds = array_merge(parse_ini_file('/var/local/emhttp/disks.ini',true), parse_ini_file('/var/local/emhttp/devs.ini',true));34 $highest_temp = 0;35 foreach ($hdds as $hdd) {36 if (!array_key_exists($hdd['id'], $ignore)) {37 if(array_key_exists('temp', $hdd))38 $temp = $hdd['temp'];39 else{40 $ua_key = "/dev/".$hdd['device'];41 $temp = (array_key_exists($ua_key, $ua_devs)) ? $ua_devs[$ua_key]['temp'] : 'N/A';42 }43 if(is_numeric($temp))44 $highest_temp = ($temp > $highest_temp) ? $temp : $highest_temp;45 }46 }47 $return = ($highest_temp === 0) ? 'N/A': $highest_temp;48 return $return;49}50/* get an array of all sensors and their values */51function ipmi_sensors($ignore=null) {52 global $ipmi, $netopts, $hdd_temp;53 // return empty array if no ipmi detected and no network options54 if(!($ipmi || !empty($netopts)))55 return [];56 $ignored = (empty($ignore)) ? '' : '-R '.escapeshellarg($ignore);57 $cmd = '/usr/sbin/ipmi-sensors --output-sensor-thresholds --comma-separated-output '.58 "--output-sensor-state --no-header-output --interpret-oem-data $netopts $ignored 2>/dev/null";59 exec($cmd, $output, $return_var=null);60 // return empty array if error61 if ($return_var)62 return [];63 // add highest hard drive temp sensor and check if hdd is ignored64 $hdd = ((preg_match('/99/', $ignore)) && !$all) ? '' :65 "99,HDD Temperature,Temperature,Nominal,$hdd_temp,C,N/A,N/A,N/A,45.00,50.00,N/A,Ok";66 if(!empty($hdd)){67 if(!empty($netopts))68 $hdd = '127.0.0.1:'.$hdd;69 $output[] = $hdd;70 }71 // test sensor72 // $output[] = "98,CPU Temp,OEM Reserved,Nominal,N/A,N/A,N/A,N/A,N/A,45.00,50.00,N/A,'Medium'";73 // key names for ipmi sensors output74 $keys = ['ID','Name','Type','State','Reading','Units','LowerNR','LowerC','LowerNC','UpperNC','UpperC','UpperNR','Event'];75 $sensors = [];76 foreach($output as $line){77 $sensor_raw = explode(",", str_replace("'",'',$line));78 $size_raw = sizeof($sensor_raw);79 // add sensor keys as keys to ipmi sensor output80 $sensor = ($size_raw < 13) ? []: array_combine($keys, array_slice($sensor_raw,0,13,true));81 if(empty($netopts))82 $sensors[$sensor['ID']] = $sensor;83 else{84 //split id into host and id85 $id = explode(':',$sensor['ID']);86 $sensor['IP'] = trim($id[0]);87 $sensor['ID'] = trim($id[1]);88 if ($sensor['IP'] === 'localhost')89 $sensor['IP'] = '127.0.0.1';90 // add sensor to array of sensors91 $sensors[ip2long($sensor['IP']).'_'.$sensor['ID']] = $sensor;92 }93 }94 return $sensors;95}96/* get array of events and their values */97function ipmi_events($archive=null){98 global $ipmi, $netopts;99 // return empty array if no ipmi detected or network options100 if(!($ipmi || !empty($netopts)))101 return [];102 if($archive) {103 $filename = "/boot/config/plugins/ipmi/archived_events.log";104 $output = is_file($filename) ? file($filename, FILE_IGNORE_NEW_LINES) : [] ;105 } else {106 $cmd = '/usr/sbin/ipmi-sel --comma-separated-output --output-event-state --no-header-output '.107 "--interpret-oem-data --output-oem-event-strings $netopts 2>/dev/null";108 exec($cmd, $output, $return_var=null);109 }110 // return empty array if error111 if ($return_var)112 return [];113 // key names for ipmi event output114 $keys = ['ID','Date','Time','Name','Type','State','Event'];115 $events = [];116 foreach($output as $line){117 $event_raw = explode(",", $line);118 $size_raw = sizeof($event_raw);119 // add event keys as keys to ipmi event output120 $event = ($size_raw < 7) ? []: array_combine($keys, array_slice($event_raw,0,7,true));121 // put time in sortable format and add unix timestamp122 $timestamp = $event['Date']." ".$event['Time'];123 if(strtotime($timestamp)) {124 if($date = Datetime::createFromFormat('M-d-Y H:i:s', $timestamp)) {125 $event['Date'] = $date->format('Y-m-d H:i:s');126 $event['Time'] = $date->format('U');127 }128 }129 if (empty($netopts)){130 if($archive)131 $events[$event['Time']."-".$event['ID']] = $event;132 else133 $events[$event['ID']] = $event;134 }else{135 //split id into host and id136 $id = explode(':',$event['ID']);137 $event['IP'] = trim($id[0]);138 if($archive)139 $event['ID'] = $event['Time'];140 else141 $event['ID'] = trim($id[1]);142 if ($event['IP'] === 'localhost')143 $event['IP'] = '127.0.0.1';144 // add event to array of events145 $events[ip2long($event['IP']).'_'.$event['ID']] = $event;146 }147 }148 return $events;149}150/* get select options for a fan and temp sensors */151function ipmi_get_options($selected=null){152 global $sensors;153 $options = "";154 foreach($sensors as $id => $sensor){155 $name = $sensor['Name'];156 $reading = ($sensor['Type'] === 'OEM Reserved') ? $sensor['Event'] : $sensor['Reading'];157 $ip = (empty($sensor['IP'])) ? '' : " (${sensor['IP']})";158 $units = is_numeric($reading) ? $sensor['Units'] : '';159 $options .= "<option value='$id'";160 // set saved option as selected161 if ($selected == $id)162 $options .= " selected";163 $options .= ">$name$ip - $reading $units</option>";164 }165 return $options;166}167/* get select options for enabled sensors */168function ipmi_get_enabled($ignore){169 global $ipmi, $netopts, $allsensors;170 // return empty array if no ipmi detected or network options171 if(!($ipmi || !empty($netopts)))172 return [];173 // create array of keyed ignored sensors174 $ignored = array_flip(explode(',', $ignore));175 foreach($allsensors as $sensor){176 $id = $sensor['ID'];177 $reading = $sensor['Reading'];178 $units = ($reading === 'N/A') ? '' : " ${sensor['Units']}";179 $ip = (empty($netopts)) ? '' : " ${sensor['IP']}";180 $options .= "<option value='$id'";181 // search for id in array to not select ignored sensors182 $options .= array_key_exists($id, $ignored) ? '' : " selected";183 $options .= ">${sensor['Name']}$ip - $reading$units</option>";184 }185 return $options;186}187// get a json array of the contents of gihub repo188function get_content_from_github($repo, $file) {189 $ch = curl_init();190 $ch_vers = curl_version();191 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);192 curl_setopt($ch, CURLOPT_TIMEOUT, 30);193 curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept: application/json', 'Content-Type: application/json']);194 curl_setopt($ch, CURLOPT_USERAGENT, 'curl/'.$ch_vers['version']);195 curl_setopt($ch, CURLOPT_URL, $repo);196 $content = curl_exec($ch);197 curl_close($ch);198 if (!empty($content) && (!is_file($file) || $content != file_get_contents($file)))199 file_put_contents($file, $content);200}201/* FAN HELPERS */202/* get fan and temp sensors array */203function ipmi_fan_sensors($ignore=null) {204 global $ipmi, $fanopts, $hdd_temp;205 // return empty array if no ipmi detected or network options206 if(!($ipmi || !empty($fanopts)))207 return [];208 $ignored = (empty($ignore)) ? '' : "-R $ignore";209 $cmd = "/usr/sbin/ipmi-sensors --comma-separated-output --no-header-output --interpret-oem-data $fanopts $ignored 2>/dev/null";210 exec($cmd, $output, $return_var=null);211 if ($return_var)212 return []; // return empty array if error213 // add highest hard drive temp sensor214 $output[] = "99,HDD Temperature,Temperature, $hdd_temp,C,Ok";215 // test sensors216 //$output[] = "700,CPU_FAN1,Fan,1200,RPM,Ok";217 //$output[] = "701,CPU_FAN2,Fan,1200,RPM,Ok";218 //$output[] = "702,SYS_FAN1,Fan,1200,RPM,Ok";219 //$output[] = "703,SYS_FAN2,Fan,1200,RPM,Ok";220 //$output[] = "704,SYS_FAN3,Fan,1200,RPM,Ok";221 // key names for ipmi sensors output222 $keys = ['ID', 'Name', 'Type', 'Reading', 'Units', 'Event'];223 $sensors = [];224 foreach($output as $line){225 // add sensor keys as keys to ipmi sensor output226 $sensor_raw = explode(",", $line);227 $size_raw = sizeof($sensor_raw);228 $sensor = ($size_raw < 6) ? []: array_combine($keys, array_slice($sensor_raw,0,6,true));...

Full Screen

Full Screen

ipmifan

Source:ipmifan Github

copy

Full Screen

...214function get_highest_temp(){215 global $hddignore;216 $ignore = array_flip(explode(',', $hddignore));217 //get UA devices218 $ua_json = '/var/state/unassigned.devices/hdd_temp.json';219 $ua_devs = file_exists($ua_json) ? json_decode(file_get_contents($ua_json), true) : [];220 //get all hard drives221 $hdds = array_merge(parse_ini_file('/var/local/emhttp/disks.ini',true), parse_ini_file('/var/local/emhttp/devs.ini',true));222 unset($hdds['flash']);223 $highest_temp = 0;224 foreach ($hdds as $hdd) {225 if (!array_key_exists($hdd['id'], $ignore)) {226 $temp = 0;227 if(array_key_exists('temp', $hdd))228 $temp = $hdd['temp'];229 elseif(!empty($ua_devs)){230 $ua_key = "/dev/".$hdd['device'];231 $temp = (array_key_exists($ua_key, $ua_devs)) ? $ua_devs[$ua_key]['temp'] : 0;232 }else233 $temp = preg_replace("/\s+/", "", shell_exec("smartctl -A -n standby /dev/${hdd} 2>/dev/null| grep -m 1 -i Temperature_Cel | awk '{print $10}'"));234 $highest_temp = ($temp > $highest_temp) ? $temp : $highest_temp;235 }236 }237 debug("Highest temp is ${highest_temp}ºC");238 return $highest_temp;239}240/* get fan and temp sensors */241function ipmi_fan_sensors() {242 global $ipmi, $fanopts, $hdd_temp;243 // return empty array if no ipmi detected or network options244 if(!$ipmi && empty($fanopts))245 return [];246 $cmd = "/usr/sbin/ipmi-sensors --comma-separated-output --no-header-output --interpret-oem-data $fanopts 2>/dev/null";247 exec($cmd, $output, $return_var=null);248 // return empty array if error249 if($return_var)250 return [];251 // add hard drive temp as a sensor252 $output[] = "99,HDD Temperature,Temperature, $hdd_temp,C,Ok";253 // key names for ipmi sensors output254 $keys = ['ID', 'Name', 'Type', 'Reading', 'Units', 'Event'];255 $sensors = [];256 foreach($output as $line){257 /// add sensor keys as keys to ipmi sensor output258 $sensor_raw = explode(",", $line);259 $size_raw = sizeof($sensor_raw);260 $sensor = ($size_raw < 6) ? []: array_combine($keys, array_slice($sensor_raw,0,6,true));261 if ($sensor['Type'] === 'Temperature' || $sensor['Type'] === 'Fan')262 $sensors[$sensor['ID']] = $sensor;263 }264 return $sensors; // sensor readings265 unset($sensors);266}267##############################268##### PROGRAM SECTION ######269##############################270$MD5 = md5_file($fancfg_file);271$hdd_temp = get_highest_temp();272$sensors = ipmi_fan_sensors();273$ipmipoll = ($fanpoll <= $hddpoll) ? $fanpoll : $hddpoll;274$fan_count = $fanpoll * 10;275$hdd_count = $hddpoll * 10;276$curent_hex = '';277$current_hex2 = '';278fanlog('Starting Fan Control');279if($board == 'Supermicro'){280 fullfan();281}282while(TRUE){ while(TRUE){283#### DO YOUR STUFF HERE ####284 /* Refresh hdds and hdd temp if hdd poll time is expired */285 if ($hdd_count <= 0) {286 $hdd_count = $hddpoll * 10;287 $hdd_temp = get_highest_temp();288 $sensors['99']['Reading'] = $hdd_temp;289 }290 /* Get sensor info if fan sensor poll time is expired */291 if ($fan_count <= 0) {292 $fan_count = $fanpoll * 10;293 $sensors = ipmi_fan_sensors();294 }295 for($i = 0; $i <= $cmd_count; $i++){296 $board0 = ($i == 0) ? $board : $board.$i;297 $raw = $board_json[$board0]['raw'];298 $fans = $board_json[$board0]['fans'];299 $hex = '';300 $msg = 'Fan:Temp';301 $cmd = '';302 $exec = false;...

Full Screen

Full Screen

hdd_temp

Using AI Code Generation

copy

Full Screen

1require_once('pts-core/pts-core.php');2$hdd_temp = new hdd_temp();3$hdd_temp->get_temperature();4$hdd_temp->get_model();5require_once('pts-core/pts-core.php');6$hdd_temp = new hdd_temp();7$hdd_temp->get_temperature();8$hdd_temp->get_model();9require_once('pts-core/pts-core.php');10$hdd_temp = new hdd_temp();11$hdd_temp->get_temperature();12$hdd_temp->get_model();13require_once('pts-core/pts-core.php');14$hdd_temp = new hdd_temp();15$hdd_temp->get_temperature();16$hdd_temp->get_model();17require_once('pts-core/pts-core.php');18$hdd_temp = new hdd_temp();19$hdd_temp->get_temperature();

Full Screen

Full Screen

hdd_temp

Using AI Code Generation

copy

Full Screen

1include_once "hdd_temp.php";2$hdd = new hdd_temp();3echo $hdd->get_temperature();4The class also provides a set_hdd() method to set the hard disk for which you want to get the temperature. This method takes the device name as argument. For example, to get the temperature of the first hard disk, you can use:5$hdd->set_hdd("sda");6$hdd->set_hdd("sdb");7echo $hdd->get_temperature();

Full Screen

Full Screen

hdd_temp

Using AI Code Generation

copy

Full Screen

1$myhdd = new HddTemp();2$myhdd->get_hdd_temp();3require_once('2.php');4require_once('2.php');5require_once('2.php');6require_once('2.php');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Phoronix-test-suite automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful