nut_monitor.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. 'use strict';
  2. 'require form';
  3. 'require fs';
  4. 'require view';
  5. const upsmon_tool = '/usr/sbin/upsmon';
  6. function ESIFlags(o) {
  7. o.value('EXEC', _('Execute notify command'));
  8. o.value('SYSLOG', _('Write to syslog'));
  9. o.value('IGNORE', _('Ignore'));
  10. o.optional = true;
  11. o.validate = function(section, v) {
  12. if (!v) return true;
  13. if(v.includes(' ') && v.includes('IGNORE'))
  14. return _('%s is mutually exclusive to other choices'.format(_('Ignore')));
  15. return true;
  16. }
  17. return o;
  18. }
  19. return view.extend({
  20. load: function() {
  21. return Promise.all([
  22. L.resolveDefault(fs.exec_direct('/usr/bin/ldd', [upsmon_tool]), []).catch(function(err) {
  23. throw new Error(_('Unable to run ldd: %s').format(err.message));
  24. }).then(function(stdout) {
  25. return stdout.includes('libssl.so');
  26. }),
  27. ])
  28. },
  29. render: function(loaded_promises) {
  30. var m, s, o;
  31. const have_ssl_support = loaded_promises[0];
  32. m = new form.Map('nut_monitor', _('NUT Monitor'),
  33. _('Network UPS Tools Monitoring Configuration'));
  34. s = m.section(form.NamedSection, 'upsmon', 'upsmon', _('Global Settings'));
  35. s.addremove = true;
  36. s.optional = true;
  37. o = s.option(form.Value, 'runas', _('RunAs User'), _('upsmon drops privileges to this user'));
  38. o.placeholder = 'nutmon'
  39. o = s.option(form.Value, 'minsupplies', _('Minimum required number or power supplies'));
  40. o.datatype = 'uinteger'
  41. o.placeholder = 1;
  42. o.optional = true;
  43. o = s.option(form.Value, 'shutdowncmd', _('Shutdown command'));
  44. o.optional = true;
  45. o.placeholder = '/sbin/halt'
  46. o = s.option(form.Value, 'notifycmd', _('Notify command'));
  47. o.optional = true;
  48. o = s.option(form.Value, 'pollfreq', _('Poll frequency'));
  49. o.datatype = 'uinteger'
  50. o.placeholder = 5;
  51. o.optional = true;
  52. o = s.option(form.Value, 'pollfreqalert', _('Poll frequency alert'));
  53. o.datatype = 'uinteger'
  54. o.optional = true;
  55. o.placeholder = 5;
  56. o = s.option(form.Value, 'hotsync', _('Hot Sync'));
  57. o.optional = true;
  58. o.placeholder = 15;
  59. o = s.option(form.Value, 'deadtime', _('Deadtime'));
  60. o.datatype = 'uinteger'
  61. o.optional = true;
  62. o.placeholder = 15;
  63. o = s.option(form.Value, 'onlinemsg', _('Online message'));
  64. o.optional = true;
  65. o = s.option(form.Value, 'onbattmsg', _('On battery message'));
  66. o.optional = true;
  67. o = s.option(form.Value, 'lowbattmsg', _('Low battery message'));
  68. o.optional = true;
  69. o = s.option(form.Value, 'fsdmsg', _('Forced shutdown message'));
  70. o.optional = true;
  71. o = s.option(form.Value, 'comokmsg', _('Communications restored message'));
  72. o.optional = true;
  73. o = s.option(form.Value, 'combadmsg', _('Communications lost message'));
  74. o.optional = true;
  75. o = s.option(form.Value, 'shutdownmsg', _('Shutdown message'));
  76. o.optional = true;
  77. o = s.option(form.Value, 'replbattmsg', _('Replace battery message'));
  78. o.optional = true;
  79. o = s.option(form.Value, 'nocommsg', _('No communications message'));
  80. o.optional = true;
  81. o = s.option(form.Value, 'noparentmsg', _('No parent message'));
  82. o.optional = true;
  83. o = s.option(form.MultiValue, 'defaultnotify', _('Notification defaults'));
  84. ESIFlags(o);
  85. o = s.option(form.MultiValue, 'onlinenotify', _('Notify when back online'));
  86. ESIFlags(o);
  87. o = s.option(form.MultiValue, 'onbattnotify', _('Notify when on battery'));
  88. ESIFlags(o);
  89. o = s.option(form.MultiValue, 'lowbattnotify', _('Notify when low battery'));
  90. ESIFlags(o);
  91. o = s.option(form.MultiValue, 'fsdnotify', _('Notify when force shutdown'));
  92. ESIFlags(o);
  93. o = s.option(form.MultiValue, 'comoknotify', _('Notify when communications restored'));
  94. ESIFlags(o);
  95. o = s.option(form.MultiValue, 'combadnotify', _('Notify when communications lost'));
  96. ESIFlags(o);
  97. o = s.option(form.MultiValue, 'shutdownotify', _('Notify when shutting down'));
  98. ESIFlags(o);
  99. o = s.option(form.MultiValue, 'replbattnotify', _('Notify when battery needs replacing'));
  100. ESIFlags(o);
  101. o = s.option(form.MultiValue, 'nocommnotify', _('Notify when no communications'));
  102. ESIFlags(o);
  103. o = s.option(form.MultiValue, 'noparentnotify', _('Notify when no parent process'));
  104. ESIFlags(o);
  105. if (have_ssl_support) {
  106. o = s.option(form.Value, 'certpath', _('CA Certificate path'), _('Path containing ca certificates to match against host certificate'));
  107. o.optional = true;
  108. o.placeholder = '/etc/ssl/certs'
  109. o = s.option(form.Flag, 'certverify', _('Verify all connection with SSL'), _('Require SSL and make sure server CN matches hostname'));
  110. o.optional = true;
  111. o.default = false;
  112. }
  113. s = m.section(form.TypedSection, 'master', _('UPS Primary'));
  114. s.optional = true;
  115. s.addremove = true;
  116. s.anonymous = true;
  117. o = s.option(form.Value, 'upsname', _('Name of UPS'), _('As configured by NUT'));
  118. o.optional = false;
  119. o = s.option(form.Value, 'hostname', _('Hostname or address of UPS'));
  120. o.optional = false;
  121. o.datatype = 'or(host,ipaddr)';
  122. o = s.option(form.Value, 'port', _('Port'));
  123. o.optional = true;
  124. o.placeholder = 3493;
  125. o.datatype = 'port';
  126. o = s.option(form.Value, 'powervalue', _('Power value'));
  127. o.optional = false;
  128. o.datatype = 'uinteger';
  129. o.default = 1;
  130. o = s.option(form.Value, 'username', _('Username'));
  131. o.optional = false;
  132. o = s.option(form.Value, 'password', _('Password'));
  133. o.optional = false;
  134. o.password = true;
  135. s = m.section(form.TypedSection, 'slave', _('UPS Auxiliary'));
  136. s.optional = true;
  137. s.addremove = true;
  138. s.anonymous = true;
  139. o = s.option(form.Value, 'upsname', _('Name of UPS'), _('As configured by NUT'));
  140. o.optional = false;
  141. o = s.option(form.Value, 'hostname', _('Hostname or address of UPS'));
  142. o.optional = false;
  143. o.datatype = 'or(host,ipaddr)';
  144. o = s.option(form.Value, 'port', _('Port'));
  145. o.optional = true;
  146. o.placeholder = 3493;
  147. o.datatype = 'port';
  148. o = s.option(form.Value, 'powervalue', _('Power value'));
  149. o.optional = false;
  150. o.datatype = 'uinteger';
  151. o.default = 1;
  152. o = s.option(form.Value, 'username', _('Username'));
  153. o.optional = false;
  154. o = s.option(form.Value, 'password', _('Password'));
  155. o.optional = false;
  156. o.password = true;
  157. return m.render();
  158. }
  159. });