overview.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict';
  2. 'require view';
  3. 'require form';
  4. 'require uci';
  5. 'require rpc';
  6. 'require poll';
  7. const callKeepalivedStatus = rpc.declare({
  8. object: 'keepalived',
  9. method: 'dump',
  10. expect: { },
  11. });
  12. return view.extend({
  13. load: function() {
  14. return Promise.all([
  15. uci.load('keepalived'),
  16. ]);
  17. },
  18. render: function() {
  19. var table =
  20. E('table', { 'class': 'table lases' }, [
  21. E('tr', { 'class': 'tr table-titles' }, [
  22. E('th', { 'class': 'th' }, _('Name')),
  23. E('th', { 'class': 'th' }, _('Interface')),
  24. E('th', { 'class': 'th' }, _('Active State/State')),
  25. E('th', { 'class': 'th' }, _('Probes Sent')),
  26. E('th', { 'class': 'th' }, _('Probes Received')),
  27. E('th', { 'class': 'th' }, _('Last Transition')),
  28. E([])
  29. ])
  30. ]);
  31. poll.add(function() {
  32. return callKeepalivedStatus().then(function(instancesInfo) {
  33. var targets = Array.isArray(instancesInfo.status) ? instancesInfo.status : [];
  34. var instances = uci.sections('keepalived', 'vrrp_instance');
  35. cbi_update_table(table,
  36. targets.map(function(target) {
  37. var state = (target.stats.become_master - target.stats.release_master) ? 'MASTER' : 'BACKUP';
  38. if (instances != '') {
  39. for (var i = 0; i < instances.length; i++) {
  40. if (instances[i]['name'] == target.data.iname) {
  41. state = state + '/' + instances[i]['state'];
  42. break;
  43. }
  44. }
  45. }
  46. return [
  47. target.data.iname,
  48. target.data.ifp_ifname,
  49. state,
  50. target.stats.advert_sent,
  51. target.stats.advert_rcvd,
  52. new Date(target.data.last_transition * 1000)
  53. ];
  54. }),
  55. E('em', _('There are no active instances'))
  56. );
  57. });
  58. });
  59. return E('div', {'class': 'cbi-map'}, [
  60. E('h2', _('VRRP')),
  61. E('div', {'class': 'cbi-map-descr'}, _('This overview shows the current status of the VRRP instances on this device.')),
  62. E('div', { 'class': 'cbi-section' }, table)
  63. ]);
  64. },
  65. handleSave: null,
  66. handleSaveApply:null,
  67. handleReset: null
  68. });