diff options
author | Florian Eckert <fe@dev.tdt.de> | 2022-10-28 12:57:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-28 12:57:14 +0200 |
commit | a07129b191722249569a0283aa0d853381b1966b (patch) | |
tree | 13251e066dc5975cfdf57c2c01193415f80d141a /applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/overview.js | |
parent | 1d157d3a50481be21f98c896019d9426efe788f6 (diff) | |
parent | d1a82d28868678716f16472f70b46557ba99f8df (diff) |
Merge pull request #5965 from jempatel/luci-app-keepalived
luci-app-keepalived: Add LuCI for keepalived
Diffstat (limited to 'applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/overview.js')
-rw-r--r-- | applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/overview.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/overview.js b/applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/overview.js new file mode 100644 index 0000000000..7e261bf82d --- /dev/null +++ b/applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/overview.js @@ -0,0 +1,75 @@ +'use strict'; +'require view'; +'require form'; +'require uci'; +'require rpc'; +'require poll'; + +var callKeepalivedStatus = rpc.declare({ + object: 'keepalived', + method: 'dump', + expect: { }, +}); + +return view.extend({ + load: function() { + return Promise.all([ + uci.load('keepalived'), + ]); + }, + + render: function() { + var table = + E('table', { 'class': 'table lases' }, [ + E('tr', { 'class': 'tr table-titles' }, [ + E('th', { 'class': 'th' }, _('Name')), + E('th', { 'class': 'th' }, _('Interface')), + E('th', { 'class': 'th' }, _('Active State/State')), + E('th', { 'class': 'th' }, _('Probes Sent')), + E('th', { 'class': 'th' }, _('Probes Received')), + E('th', { 'class': 'th' }, _('Last Transition')), + E([]) + ]) + ]); + + poll.add(function() { + return callKeepalivedStatus().then(function(instancesInfo) { + var targets = Array.isArray(instancesInfo.status) ? instancesInfo.status : []; + var instances = uci.sections('keepalived', 'vrrp_instance'); + + cbi_update_table(table, + targets.map(function(target) { + var state = (target.stats.become_master - target.stats.release_master) ? 'MASTER' : 'BACKUP'; + if (instances != '') { + for (var i = 0; i < instances.length; i++) { + if (instances[i]['name'] == target.data.iname) { + state = state + '/' + instances[i]['state']; + break; + } + } + } + return [ + target.data.iname, + target.data.ifp_ifname, + state, + target.stats.advert_sent, + target.stats.advert_rcvd, + new Date(target.data.last_transition * 1000) + ]; + }), + E('em', _('There are no active instances')) + ); + }); + }); + + return E([ + E('h3', _('Keepalived Instances Status')), + E('br'), + table + ]); + }, + + handleSave: null, + handleSaveApply:null, + handleReset: null +}); |