Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.96 KB | None | 0 0
  1. <?php
  2.  
  3. //fill the dropdown list
  4. $queryDropdown = "SELECT DISTINCT mac FROM location";
  5. $resultDropdown = filterFunction($queryDropdown);
  6. // if not set then filter the table with default values using this mac address
  7. $query = "SELECT mac,hostid,interface FROM location where mac='C8:50:E9:8C:E2:52' ORDER BY timestamp DESC";
  8. $result = filterFunction($query);
  9.  
  10. $variablesQuery = "SELECT DISTINCT variable,itemid FROM client_item WHERE mac='C8:50:E9:8C:E2:52' and datetime BETWEEN '2019-09-20' AND '2019-09-21'";
  11. $resultVariables = filterFunction($variablesQuery);
  12.  
  13. $variablesQuerySecondTable = "SELECT DISTINCT variable,itemid FROM client_item WHERE mac='C8:50:E9:8C:E2:52' and datetime BETWEEN '2019-09-20' AND '2019-09-21'";
  14. $resultVariablesSecondTable = filterFunction($variablesQuerySecondTable);
  15.  
  16. $variablesQueryBody = "SELECT DISTINCT variable,itemid FROM client_item WHERE mac='C8:50:E9:8C:E2:52' and datetime BETWEEN '2019-09-20' AND '2019-09-21'";
  17. $resultVariablesBody = filterFunction($variablesQueryBody);
  18.  
  19. // SQL STATEMENTS FOR THE VARIABLES THAT INCLUDE AVG MIN MAX etc.
  20. $uptimeSql = "SELECT datetime,`value` FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'Uptime' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  21. $resultUptimeSql = filterFunction($uptimeSql);
  22. $rowUptime = mysqli_fetch_row($resultUptimeSql);
  23.  
  24. $distanceSql = "SELECT datetime,`value` FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'Distance' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  25. $resultDistanceSql = filterFunction($distanceSql);
  26. $rowDistance = mysqli_fetch_row($resultDistanceSql);
  27.  
  28. $supplyVoltageAvg = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'Supply Voltage' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  29. $resultSupplyVoltageAvg = filterFunction($supplyVoltageAvg);
  30. $rowSupplyVoltage = mysqli_fetch_row($resultSupplyVoltageAvg);
  31.  
  32. $rxPowerAvg = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'RX Power' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  33. $resultRXPowerAvg = filterFunction($rxPowerAvg);
  34. $rowRXPower = mysqli_fetch_row($resultRXPowerAvg);
  35.  
  36. $temperatureAvg = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'Temperature' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  37. $resultTemperature = filterFunction($temperatureAvg);
  38. $rowTemperature = mysqli_fetch_row($resultTemperature);
  39.  
  40. $txPowerAvg = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'TX Power' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  41. $resultTXPowerAvg = filterFunction($txPowerAvg);
  42. $rowTXPower = mysqli_fetch_row($resultTXPowerAvg);
  43.  
  44. $txBiasCurrent = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'TX Bias Current' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  45. $resultTXBiasCurrent = filterFunction($txBiasCurrent);
  46. $rowTxBiasCurrent = mysqli_fetch_row($resultTXBiasCurrent);
  47.  
  48. $trafficUploadSUM = "SELECT datetime,SUM(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'Traffic_Upload' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  49. $resultTrafficUpload = filterFunction($trafficUploadSUM);
  50. $rowTrafficUpload = mysqli_fetch_row($resultTrafficUpload);
  51.  
  52. $trafficDownloadSUM = "SELECT datetime,SUM(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'Traffic_Download' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  53. $resultTrafficDownload = filterFunction($trafficDownloadSUM);
  54. $rowTrafficDownload = mysqli_fetch_row($resultTrafficDownload);
  55.  
  56. $UploadSpeed = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'Upload_Speed' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  57. $resultUploadSpeed = filterFunction($UploadSpeed);
  58. $rowUploadSpeed = mysqli_fetch_row($resultUploadSpeed);
  59.  
  60. $DownloadSpeed = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = 'C8:50:E9:8C:E2:52' AND variable = 'Download Speed' and datetime BETWEEN '2019-09-20' AND '2019-09-21' ORDER BY datetime DESC LIMIT 1";
  61. $resultDownloadSpeed = filterFunction($DownloadSpeed);
  62. $rowDownloadSpeed = mysqli_fetch_row($resultDownloadSpeed);
  63.  
  64.  
  65. if(isset($_GET['submit'])){
  66.  
  67. if(isset($_GET['dropDown'])){
  68. $selected_Val = $_GET['dropDown'];
  69. $from = $_GET['from'];
  70. $to=$_GET['to'];
  71. // make a SQL Query with the value from the dropDown list, this lists the mac addresses
  72. $query = "SELECT mac,hostid,interface FROM location where mac='".$selected_Val."' ORDER BY timestamp DESC";
  73. $result = filterFunction($query);
  74. // after finishing with the first query, fill the dropdown
  75. $queryDropdown = "SELECT DISTINCT mac FROM location";
  76. $resultDropdown = filterFunction($queryDropdown);
  77. // selecting the distinct variables from the client_item table
  78. $variablesQuery = "SELECT DISTINCT variable,itemid FROM client_item WHERE mac='".$selected_Val."' and datetime BETWEEN '".$from."' AND '".$to."' "; //".$selected_Val."
  79. $resultVariables = filterFunction($variablesQuery);
  80.  
  81. $variablesQuerySecondTable = "SELECT DISTINCT variable,itemid FROM client_item WHERE mac='".$selected_Val."' and datetime BETWEEN '".$from."' AND '".$to."'";
  82. $resultVariablesSecondTable = filterFunction($variablesQuerySecondTable);
  83.  
  84. $variablesQueryBody = "SELECT DISTINCT variable,itemid FROM client_item WHERE mac='".$selected_Val."' and datetime BETWEEN '".$from."' AND '".$to."'";
  85. $resultVariablesBody = filterFunction($variablesQueryBody);
  86.  
  87. // SQL STATEMENTS FOR THE VARIABLES THAT INCLUDE AVG MIN MAX etc.
  88. $uptimeSql = "SELECT datetime,`value` FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'Uptime' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  89. $resultUptimeSql = filterFunction($uptimeSql);
  90. $rowUptime = mysqli_fetch_row($resultUptimeSql);
  91.  
  92. $distanceSql = "SELECT datetime,`value` FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'Distance' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  93. $resultDistanceSql = filterFunction($distanceSql);
  94. $rowDistance = mysqli_fetch_row($resultDistanceSql);
  95.  
  96. $supplyVoltageAvg = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'Supply Voltage' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  97. $resultSupplyVoltageAvg = filterFunction($supplyVoltageAvg);
  98. $rowSupplyVoltage = mysqli_fetch_row($resultSupplyVoltageAvg);
  99.  
  100. $rxPowerAvg = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'RX Power' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  101. $resultRXPowerAvg = filterFunction($rxPowerAvg);
  102. $rowRXPower = mysqli_fetch_row($resultRXPowerAvg);
  103.  
  104. $temperatureAvg = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'Temperature' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  105. $resultTemperature = filterFunction($temperatureAvg);
  106. $rowTemperature = mysqli_fetch_row($resultTemperature);
  107.  
  108. $txPowerAvg = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'TX Power' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  109. $resultTXPowerAvg = filterFunction($txPowerAvg);
  110. $rowTXPower = mysqli_fetch_row($resultTXPowerAvg);
  111.  
  112. $txBiasCurrent = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'TX Bias Current' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  113. $resultTXBiasCurrent = filterFunction($txBiasCurrent);
  114. $rowTxBiasCurrent = mysqli_fetch_row($resultTXBiasCurrent);
  115.  
  116. $trafficUploadSUM = "SELECT datetime,SUM(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'Traffic_Upload' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  117. $resultTrafficUpload = filterFunction($trafficUploadSUM);
  118. $rowTrafficUpload = mysqli_fetch_row($resultTrafficUpload);
  119.  
  120. $trafficDownloadSUM = "SELECT datetime,SUM(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'Traffic_Download' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  121. $resultTrafficDownload = filterFunction($trafficDownloadSUM);
  122. $rowTrafficDownload = mysqli_fetch_row($resultTrafficDownload);
  123.  
  124. $UploadSpeed = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'Upload_Speed' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  125. $resultUploadSpeed = filterFunction($UploadSpeed);
  126. $rowUploadSpeed = mysqli_fetch_row($resultUploadSpeed);
  127.  
  128. $DownloadSpeed = "SELECT datetime,AVG(`value`) FROM `client_item` WHERE mac = '".$selected_Val."' AND variable = 'Download Speed' and datetime BETWEEN '".$from."' AND '".$to."' ORDER BY datetime DESC LIMIT 1";
  129. $resultDownloadSpeed = filterFunction($DownloadSpeed);
  130. $rowDownloadSpeed = mysqli_fetch_row($resultDownloadSpeed);
  131.  
  132.  
  133. }else{
  134. echo "<div class=\"alert alert-danger alert-dismissible fade show\">
  135. <strong>Error!</strong> Please select a mac address.
  136. <button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>
  137. </div>";
  138. }
  139.  
  140.  
  141. }
  142. function filterFunction($query){
  143. $connect = mysqli_connect("localhost","root","","praksa");
  144. $filter_query = mysqli_query($connect,$query);
  145. return $filter_query;
  146. }
  147. ?>
  148. <html>
  149. <head>
  150. <title>Zabbix</title>
  151.  
  152. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  153. <link rel="stylesheet" href="style.css">
  154. <script
  155. src="https://code.jquery.com/jquery-3.4.1.min.js"
  156. integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  157. crossorigin="anonymous"></script>
  158. <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>
  159.  
  160. </head>
  161. <body>
  162. <div class="container">
  163. <form class="form-inline" method="GET" action="index.php">
  164. <label class="my-1 mr-2" for="inlineFormCustomSelectPref">Preference</label>
  165. <select class="custom-select my-1 mr-sm-2" name="dropDown" id="inlineFormCustomSelectPref">
  166. <option selected disabled>Choose...</option>
  167. <?php while ($row = mysqli_fetch_array($resultDropdown)): ?>
  168. <option value="<?php echo $row['mac']?>"><?php echo $row['mac']?></option>
  169. <?php endwhile; ?>
  170. </select>
  171. <div class="form-group mr-2">
  172. <label for="from">From date:</label>
  173. <input type="date" class="form-control" id="from" name="from" required/>
  174. <label for="to">To date:</label>
  175. <input type="date" class="form-control" id="to" name="to" required/>
  176. </div>
  177. <button type="submit" name="submit" class="btn btn-primary my-1">Submit</button>
  178. </form>
  179. <div class="row">
  180. <div class="col-lg-4">
  181. <table>
  182. <thead>
  183. <tr>
  184. <td>Mac address</td>
  185. <td>Host</td>
  186. <td>Interface</td>
  187. </tr>
  188. </thead>
  189. <tbody>
  190. <?php while ($row = mysqli_fetch_array($result)): ?>
  191. <tr>
  192. <td><?php echo $row['mac']?></td>
  193. <td><?php echo $row['hostid']?></td>
  194. <td><?php echo $row['interface']?></td>
  195. </tr>
  196. <?php endwhile; ?>
  197. </tbody>
  198. </table>
  199. </div>
  200. <div class="col-lg-8">
  201. <table style="width: 500px;height: 40px">
  202. <thead>
  203. <tr>
  204. <?php while($row = mysqli_fetch_array($resultVariablesSecondTable)): ?>
  205. <td><?php echo $row['variable']; ?></td>
  206. <?php endwhile ; ?>
  207. </tr>
  208. </thead>
  209. <tbody>
  210. <tr>
  211. <?php while($row2 = mysqli_fetch_array($resultVariablesBody)):?>
  212. <?php if($row2['variable']=="Supply Voltage") echo "<td>" . "Supply Voltage " .round($rowSupplyVoltage[1],4)."</td>"; ?>
  213. <?php if($row2['variable']=="Distance") echo "<td>" . " Distance ".$rowDistance[1]."</td>"; ?>
  214. <?php if($row2['variable']=="RX Power") echo "<td>" . " RX Power ".round($rowRXPower[1],4)."</td>"; ?>
  215. <?php if($row2['variable']=="Temperature") echo "<td>" ." Temperature ".round($rowTemperature[1],4)."</td>"; ?>
  216. <?php if($row2['variable']=="TX Bias Current") echo "<td>"." TX Bias Current ".round($rowTxBiasCurrent[1],4)."</td>"; ?>
  217. <?php if($row2['variable']=="TX Power") echo "<td>"."TX Power ".round($rowTXPower[1],4)."</td>"; ?>
  218. <?php if($row2['variable']=="Uptime") echo "<td>"." Uptime ".$rowUptime[1]."</td>"; ?>
  219. <?php if($row2['variable']=="Traffic_Upload") echo "<td>"." Traffic Upload ".$rowTrafficUpload[1]."</td>"; ?>
  220. <?php if($row2['variable']=="Traffic_Download") echo "<td>"." Traffic Download ".$rowTrafficDownload[1]."</td>"; ?>
  221. <?php if($row2['variable']=="Upload_Speed") echo "<td>"." Upload Speed ".round($rowUploadSpeed[1],4)."</td>"; ?>
  222. <?php if($row2['variable']=="Download Speed") echo "<td>"." Download Speed ".round($rowDownloadSpeed[1],4)."</td>"; ?>
  223. <?php endwhile; ?>
  224. </tr>
  225. </tbody>
  226. </table>
  227. </div>
  228. </div>
  229. <?php
  230. if(mysqli_num_rows($resultVariables)!=0){
  231. if(isset($_GET['dropDown'])){
  232. $mac = $_GET['dropDown'];
  233. $fromDate = $_GET['from'];
  234. $toDate = $_GET['to'];
  235. }else{
  236. $mac = 'C8:50:E9:8C:E2:52';
  237. $fromDate = '2019-09-20';
  238. $toDate='2019-09-21';
  239. }
  240. $dataValues = [];
  241. $datetimeValues = [];
  242. ?>
  243. <?php while ($row = mysqli_fetch_array($resultVariables)): ?>
  244. <?php
  245.  
  246. $sql = "SELECT itemid,value,datetime FROM client_item where mac='".$mac."' AND itemid= " . $row['itemid'] . " and datetime BETWEEN '".$fromDate."' AND '".$toDate."' ";
  247. $resultStatement = filterFunction($sql);
  248. $dataValues = [];
  249. $datetimeValues = [];
  250. while($row1 = mysqli_fetch_array($resultStatement)) {
  251.  
  252. $dataValues[] = $row1['value'];
  253. $datetimeValues[] = $row1['datetime'];
  254.  
  255. } ;
  256. $dataValues = json_encode($dataValues);
  257. $datetimeValues = json_encode($datetimeValues);
  258. ?>
  259. <div class="mt-5">
  260. <h3><?php echo $row['variable'] ?></h3>
  261. <canvas id="myChart-<?php echo $row['itemid']?>"
  262. </div>
  263.  
  264.  
  265. </div>
  266. <script>
  267. $(document).ready(function () {
  268. var ctx = document.getElementById("myChart-<?php echo $row['itemid'] ?>");
  269.  
  270. var data = {
  271. labels:<?php echo $datetimeValues ?> ,
  272. datasets:[{
  273. label:"<?php echo $row['variable'] ?>",
  274. fill:false,
  275. data:<?php echo $dataValues ?>,
  276. backgroundColor:"#455C73"
  277. }],
  278.  
  279. };
  280. var myChart = new Chart(ctx,{
  281. data:data,
  282. type:'line'
  283. })
  284. })
  285. </script>
  286.  
  287. <?php endwhile; ?>
  288. <?php }
  289. else {
  290. echo "<div class=\"alert alert-warning\" role=\"alert\">
  291. No data was available for this mac address
  292. </div>";
  293. }
  294. ?>
  295.  
  296. </body>
  297. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement