apcups.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Licensed to the public under the Apache License 2.0. */
  2. 'use strict';
  3. 'require baseclass';
  4. return baseclass.extend({
  5. title: _('APC UPS'),
  6. rrdargs: function(graph, host, plugin, plugin_instance, dtype) {
  7. var rv = [];
  8. /*
  9. * Types and instances supported by APC UPS
  10. * e.g. ups_types -> [ 'timeleft', 'charge', 'percent', 'voltage' ]
  11. * e.g. ups_inst['voltage'] -> [ 'input', 'battery' ]
  12. */
  13. var ups_types = graph.dataTypes(host, plugin, plugin_instance),
  14. ups_inst = {};
  15. for (var i = 0; i < ups_types.length; i++)
  16. ups_inst[ups_types[i]] = graph.dataInstances(host, plugin, plugin_instance, ups_types[i]);
  17. /* Check if hash table or array is empty or nil-filled */
  18. function empty(t) {
  19. for (var k in t)
  20. if (t[k] != null)
  21. return false;
  22. return true;
  23. }
  24. /* Append graph definition but only types/instances which are */
  25. /* supported and available to the plugin and UPS. */
  26. function add_supported(t, defs) {
  27. var def_inst = defs['data']['instances'];
  28. if (L.isObject(def_inst)) {
  29. for (var k in def_inst) {
  30. if (ups_types.filter(function(t) { return t == k }).length) {
  31. for (var i = def_inst[k].length - 1; i >= 0; i--)
  32. if (!ups_inst[k].filter(function(n) { return n == def_inst[k][i] }).length)
  33. def_inst[k].splice(i, 1);
  34. if (def_inst[k].length == 0)
  35. def_inst[k] = null; /* can't assign v: immutable */
  36. }
  37. else {
  38. def_inst[k] = null; /* can't assign v: immutable */
  39. }
  40. }
  41. if (empty(def_inst))
  42. return;
  43. }
  44. t.push(defs);
  45. }
  46. /* Graph definitions for APC UPS measurements MUST use only 'instances': */
  47. /* e.g. instances = { voltage = { "input", "output" } } */
  48. var voltagesdc = {
  49. title: "%H: Voltages on APC UPS - Battery",
  50. vlabel: "Volts DC",
  51. alt_autoscale: true,
  52. number_format: "%5.1lfV",
  53. data: {
  54. instances: {
  55. voltage: [ "battery" ]
  56. },
  57. options: {
  58. voltage: { title: "Battery voltage", noarea: true }
  59. }
  60. }
  61. };
  62. add_supported(rv, voltagesdc);
  63. var voltagesac = {
  64. title: "%H: Voltages on APC UPS - AC",
  65. vlabel: "Volts AC",
  66. alt_autoscale: true,
  67. number_format: "%5.1lfV",
  68. data: {
  69. instances: {
  70. voltage: [ "input", "output" ]
  71. },
  72. options: {
  73. voltage_output : { color: "00e000", title: "Output voltage", noarea: true, overlay: true },
  74. voltage_input : { color: "ffb000", title: "Input voltage", noarea: true, overlay: true }
  75. }
  76. }
  77. };
  78. add_supported(rv, voltagesac);
  79. var percentload = {
  80. title: "%H: Load on APC UPS ",
  81. vlabel: "Percent",
  82. y_min: "0",
  83. y_max: "100",
  84. number_format: "%5.1lf%%",
  85. data: {
  86. instances: {
  87. percent: [ "load" ]
  88. },
  89. options: {
  90. percent_load: { color: "00ff00", title: "Load level" }
  91. }
  92. }
  93. };
  94. add_supported(rv, percentload);
  95. var charge_percent = {
  96. title: "%H: Battery charge on APC UPS ",
  97. vlabel: "Percent",
  98. y_min: "0",
  99. y_max: "100",
  100. number_format: "%5.1lf%%",
  101. data: {
  102. instances: {
  103. charge: [ "" ]
  104. },
  105. options: {
  106. charge: { color: "00ff0b", title: "Charge level" }
  107. }
  108. }
  109. };
  110. add_supported(rv, charge_percent);
  111. var temperature = {
  112. title: "%H: Battery temperature on APC UPS ",
  113. vlabel: "\u00b0C",
  114. number_format: "%5.1lf\u00b0C",
  115. data: {
  116. instances: {
  117. temperature: [ "" ]
  118. },
  119. options: {
  120. temperature: { color: "ffb000", title: "Battery temperature" } }
  121. }
  122. };
  123. add_supported(rv, temperature);
  124. var timeleft = {
  125. title: "%H: Time left on APC UPS ",
  126. vlabel: "Minutes",
  127. number_format: "%.1lfm",
  128. data: {
  129. instances: {
  130. timeleft: [ "" ]
  131. },
  132. options: {
  133. timeleft: { color: "0000ff", title: "Time left" }
  134. }
  135. }
  136. };
  137. add_supported(rv, timeleft);
  138. var frequency = {
  139. title: "%H: Incoming line frequency on APC UPS ",
  140. vlabel: "Hz",
  141. number_format: "%5.0lfhz",
  142. data: {
  143. instances: {
  144. frequency: [ "input" ]
  145. },
  146. options: {
  147. frequency_input: { color: "000fff", title: "Line frequency" }
  148. }
  149. }
  150. };
  151. add_supported(rv, frequency);
  152. return rv;
  153. }
  154. });