check_mk-fhem.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. # PNP4Nagios template for check_fhem FHEM check
  3. # Author: Jonas Nickl <kontakt@jonasnickl.de>
  4. #$defopt = "--vertical-label 'Bytes' -l0 -b 1024 ".
  5. $defopt = "--color MGRID\"#cccccc\" --color GRID\"#dddddd\" ";
  6. #$def[] = "";
  7. #$opt[] = "";
  8. # Work with names rather then numbers.
  9. global $fhem_defines;
  10. $fhem_defines = array();
  11. foreach ($NAME as $i => $n) {
  12. $fhem_defines[$n] = "DEF:$n=$RRDFILE[$i]:$DS[$i]:MAX ";
  13. }
  14. # avoid redeclaration errors if this file is include multiple times (e.g. by basket)
  15. if (!function_exists('fhem_area')) {
  16. function fhem_area($varname, $color, $title, $unit, $stacked)
  17. {
  18. return fhem_curve("AREA", $varname, $color, $title, $unit, $stacked);
  19. }
  20. function fhem_line($varname, $color, $title, $unit, $stacked)
  21. {
  22. return fhem_curve("LINE1", $varname, $color, $title, $unit, $stacked);
  23. }
  24. function fhem_curve($how, $varname, $color, $title, $unit, $stacked)
  25. {
  26. global $fhem_defines;
  27. $tit = sprintf("%-30s", $title);
  28. if (isset($fhem_defines[$varname])) {
  29. $x = $fhem_defines[$varname] . "$how:$varname#$color:\"$tit\"";
  30. if ($stacked)
  31. $x .= ":STACK";
  32. $x .= " ";
  33. # $x .= "CDEF:${varname}_gb=$varname,1073741824,/ ";
  34. $x .= "GPRINT:${varname}:LAST:\"%6.1lf ${unit} last\" ";
  35. $x .= "GPRINT:${varname}:AVERAGE:\"%6.1lf ${unit} avg\" ";
  36. $x .= "GPRINT:${varname}:MAX:\"%6.1lf ${unit} max\\n\" ";
  37. return $x;
  38. }
  39. else {
  40. return "";
  41. }
  42. }
  43. }
  44. # 1. Overview
  45. if (isset($fhem_defines['temperature']) && isset($fhem_defines['humidity']) ) {
  46. $ds_name[] = 'temperature';
  47. $opt[] = $defopt . "--title \"Temperature + Humidity\"";
  48. $def[] = ""
  49. . fhem_area("humidity", "00bfff", "Humidity", "%% ", FALSE)
  50. . fhem_area("temperature", "80ff40", "Temperature", "°C", FALSE)
  51. . fhem_line("desiredtemp", "408f20", "Desired temp", "°C", FALSE)
  52. . fhem_area("dewpoint", "B40404", "Dewpoint", "°C", FALSE)
  53. . fhem_line("valveposition", "00bfff", "Valve position", "%% ", FALSE)
  54. ;
  55. }
  56. # 2. Temperature
  57. if (isset($fhem_defines['temperature']) ) {
  58. $ds_name[] = 'temperature';
  59. $opt[] = $defopt . "--title \"Temperature\"";
  60. $def[] = ""
  61. . fhem_area("temperature", "80ff40", "Temperature", "°C", FALSE)
  62. . fhem_line("desiredtemp", "408f20", "Desired temp", "°C", FALSE)
  63. . fhem_area("dewpoint", "B40404", "Dewpoint", "°C", FALSE)
  64. . fhem_line("valveposition", "00bfff", "Valve position", "%% ", FALSE)
  65. ;
  66. }
  67. ## 2. Valveposition
  68. #if (isset($fhem_defines['valveposition']) ) {
  69. # $opt[] = $defopt . "--title \"Valveposition\"";
  70. # $def[] = ""
  71. # . fhem_area("temperature", "80ff40", "Temperature", "°C", FALSE)
  72. # . fhem_area("desiredtemp", "408f20", "Desired temp", "°C", FALSE)
  73. # . fhem_line("valveposition", "00bfff", "Valve Position", "%% ", FALSE)
  74. # ;
  75. #}
  76. # 3. BatteryLevel
  77. if (isset($fhem_defines['batteryLevel']) ) {
  78. $ds_name[] = 'batteryLevel';
  79. $opt[] = $defopt . "--title \"batteryLevel\"";
  80. $def[] = ""
  81. . fhem_area("batteryLevel", "e0e0e0", "Battery Level", "V", FALSE)
  82. ;
  83. }
  84. # 4. Power (kWh)
  85. if (isset($fhem_defines['power']) ) {
  86. $ds_name[] = 'power';
  87. $opt[] = $defopt . "--title \"Power\"";
  88. $def[] = ""
  89. . fhem_area("power", "e0e0e0", "Power", "kWh", FALSE)
  90. # . fhem_area("dewpoint", "80ff40", "", FALSE)
  91. # . fhem_area("swap_used", "408f20", "", TRUE)
  92. ;
  93. }
  94. # 5. Brightness
  95. if (isset($fhem_defines['brightness']) ) {
  96. $ds_name[] = 'brightness';
  97. $opt[] = $defopt . "--title \"Brightness\"";
  98. $def[] = ""
  99. . fhem_area("brightness", "ffb90f", "Brightness", "%%", FALSE)
  100. . fhem_line("brightness_on","551a8b", "Brightness_on", "%%", FALSE)
  101. ;
  102. }
  103. # 6. Color temperature (ct)
  104. if (isset($fhem_defines['ct']) ) {
  105. $ds_name[] = 'ct';
  106. $opt[] = $defopt . "--title \"Color temperature (ct)\"";
  107. $def[] = ""
  108. . fhem_curve("LINE2", "ct", "ff4500", "Color temperature (ct)", "K", FALSE)
  109. ;
  110. }
  111. # 7. Speedtest (down-/upload)
  112. if (isset($fhem_defines['download']) ) {
  113. $ds_name[] = 'speedtest';
  114. $opt[] = $defopt . "--title \"Speedtest\"";
  115. $def[] = ""
  116. . fhem_area("download", "00ffc0", "Download", "Mbit/s", FALSE)
  117. . fhem_area("upload", "00c0ff", "Upload", "Mbit/s", FALSE)
  118. ;
  119. }
  120. # 8. Speedtest (ping)
  121. if (isset($fhem_defines['ping']) ) {
  122. $ds_name[] = 'speedtest_ping';
  123. $opt[] = $defopt . "--title \"Speedtest Ping\"";
  124. $def[] = ""
  125. . fhem_area("ping", "2b85c8", "Ping", "ms", FALSE)
  126. ;
  127. }
  128. # 9. Traffic (duration)
  129. if (isset($fhem_defines['duration']) ) {
  130. $ds_name[] = 'duration';
  131. $opt[] = $defopt . "--title \"Traffic duration\"";
  132. $def[] = ""
  133. . fhem_area("duration", "00bfff", "Duration", "min", FALSE)
  134. . fhem_area("delay", "f78181", "Delay", "min", TRUE)
  135. . fhem_curve("LINE2", "duration_in_traffic", "B40404", "Duration in traffic", "min", FALSE)
  136. ;
  137. }
  138. # 9. Traffic (duration)
  139. if (isset($fhem_defines['presence']) ) {
  140. $ds_name[] = 'presence';
  141. $opt[] = $defopt . "--title \"Presence\"";
  142. $def[] = ""
  143. . fhem_area("presence", "00bfff", "Presence", "", FALSE)
  144. ;
  145. }
  146. ?>