-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfan_temps_controller.php
175 lines (156 loc) · 5.19 KB
/
fan_temps_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* Fan_temps_controller class
*
* @package fan_temps
* @author tuxudo
**/
class Fan_temps_controller extends Module_controller
{
function __construct()
{
$this->module_path = dirname(__FILE__);
}
/**
* Default method
*
* @author AvB
**/
function index()
{
echo "You've loaded the fan_temps module!";
}
/**
* Retrieve GPU overtemp in json format
*
* @return void
* @author tuxudo
**/
public function get_gpu_overtemp()
{
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `sght` = '1' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `sght` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj = new View();
$queryobj = new Fan_temps_model();
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve fans manually set in json format
*
* @return void
* @author tuxudo
**/
public function get_fan_manually()
{
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `fnfd` = '2' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `fnfd` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj = new View();
$queryobj = new Fan_temps_model();
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve CPU hot in json format
*
* @return void
* @author tuxudo
**/
public function get_cpu_hot()
{
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `spht` = '1' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `spht` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj = new View();
$queryobj = new Fan_temps_model();
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve disc inserted in json format
*
* @return void
* @author tuxudo
**/
public function get_odd_inserted()
{
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `msdi` = '1' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `msdi` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj = new View();
$queryobj = new Fan_temps_model();
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve bad fans in json format
*
* @return void
* @author tuxudo
**/
public function get_bad_fans()
{
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `mssf` = '1' THEN 1 END) AS 'yes',
COUNT(CASE WHEN `mssf` = '0' THEN 1 END) AS 'no'
from fan_temps
LEFT JOIN reportdata USING (serial_number)
WHERE
".get_machine_group_filter('');
$obj = new View();
$queryobj = new Fan_temps_model();
$obj->view('json', array('msg' => current($queryobj->query($sql))));
}
/**
* Retrieve data in json format for client tab
*
* @return void
* @author tuxudo
**/
public function get_tab_data($serial_number = '')
{
// Remove serial number characters
$serial_number = preg_replace("/[^A-Za-z0-9_\-]]/", '', $serial_number);
$sql = "SELECT json_info FROM fan_temps WHERE serial_number = '$serial_number'";
$obj = new View();
$queryobj = new Fan_temps_model();
$fan_temps_tab = $queryobj->query($sql);
// Extract just the JSON string and make it an object
$data_json = json_decode(json_decode(json_encode($fan_temps_tab[0]),true)['json_info']);
if(!is_null($data_json)){
// Add the temperature type to the object for the client tab
if(!conf('temperature_unit')){
$data_json->TEMPERATURE_UNIT = "C";
} else {
$data_json->TEMPERATURE_UNIT = conf('temperature_unit');
}
}
$obj->view('json', array('msg' => current(array('msg' => $data_json))));
}
/**
* Retrieve data in json format
*
* @return void
* @author tuxudo
**/
public function get_data($serial_number = '')
{
$obj = new View();
$fan_temps = new Fan_temps_model;
$obj->view('json', array('msg' => $fan_temps->retrieve_records($serial_number)));
}
} // End class Fan_temps_controller