/*
* thermal_sensors.js
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
warningTemp = 9999;
criticalTemp = 100;
ajaxBusy = false;
//should be called from "thermal_sensors.widget.php"
function showThermalSensorsData(widgetKey, tsParams, firstTime) {
if (!ajaxBusy) {
ajaxBusy = true;
//get data from thermal_sensors.widget.php
url = "/widgets/widgets/thermal_sensors.widget.php?getThermalSensorsData=1"
//IE fix to disable cache when using http:// , just append timespan
+ new Date().getTime();
$.ajax(url, {
type: 'get',
success: function(data) {
var thermalSensorsData = data || "";
buildThermalSensorsData(thermalSensorsData, widgetKey, tsParams, firstTime);
firstTime = false;
},
error: function(jqXHR, status, error) {
firstTime = true;
warningTemp = 9999;
buildThermalSensorsDataRaw('Temperature data could not be read.', widgetKey);
}
});
ajaxBusy = false;
}
//call itself in 11 seconds
window.setTimeout(function(){showThermalSensorsData(widgetKey, tsParams, firstTime);}, 11000);
}
function buildThermalSensorsData(thermalSensorsData, widgetKey, tsParams, firstTime) {
if (tsParams.showRawOutput) {
buildThermalSensorsDataRaw(thermalSensorsData, widgetKey);
} else {
if (firstTime) {
buildThermalSensorsDataGraph(thermalSensorsData, tsParams, widgetKey);
}
updateThermalSensorsDataGraph(thermalSensorsData, tsParams, widgetKey);
}
}
function buildThermalSensorsDataRaw(thermalSensorsData, widgetKey) {
var thermalSensorsContent = "";
if (thermalSensorsData && thermalSensorsData != "") {
thermalSensorsContent = thermalSensorsData.replace(/\|/g, "
");
//rawData = thermalSensorsData.split("|").join("
");
}
loadThermalSensorsContainer(thermalSensorsContent, widgetKey);
}
function loadThermalSensorsContainer (thermalSensorsContent, widgetKey) {
if (thermalSensorsContent && thermalSensorsContent != "") {
//load generated graph (or raw data) into thermalSensorsContainer (thermalSensorsContainer DIV defined in "thermal_sensors.widget.php")
$('#thermalSensorsContainer-' + widgetKey).html(thermalSensorsContent);
} else {
$('#thermalSensorsContainer-' + widgetKey).html("No Thermal Sensors data available.");
}
}
function buildThermalSensorsDataGraph(thermalSensorsData, tsParams, widgetKey) {
var thermalSensorsArray = new Array();
if (thermalSensorsData && thermalSensorsData != "") {
thermalSensorsArray = thermalSensorsData.split("|");
}
var thermalSensorsHTMLContent = "";
//generate graph for each temperature sensor and append to thermalSensorsHTMLContent string
for (var i = 0; i < thermalSensorsArray.length; i++) {
var sensorDataArray = thermalSensorsArray[i].split(":");
var sensorName = sensorDataArray[0].trim();
var thermalSensorValue = getThermalSensorValue(sensorDataArray[1]);
//set thresholds
if (sensorName.indexOf("cpu") > -1) { //check CPU Threshold config settings
warningTemp = tsParams.coreWarningTempThreshold;
criticalTemp = tsParams.coreCriticalTempThreshold;
} else { //assuming sensor is for a zone, check Zone Threshold config settings
warningTemp = tsParams.zoneWarningTempThreshold;
criticalTemp = tsParams.zoneCriticalTempThreshold;
}
if (!tsParams.showFullSensorName) {
sensorName = getSensorFriendlyName(sensorName);
}
//build temperature item/row for a sensor
var thermalSensorRow = '