summaryrefslogtreecommitdiffstats
path: root/applications/luci-app-keepalived/htdocs/luci-static/resources/view/keepalived/overview.js
blob: 4ccd3fe7be61da205d1d8977eef3545fb5f4cdce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
'require view';
'require form';
'require uci';
'require rpc';
'require poll';

const callKeepalivedStatus = rpc.declare({
	object: 'keepalived',
	method: 'dump',
	expect: {  },
});

return view.extend({
	load() {
		return Promise.all([
			uci.load('keepalived'),
		]);
	},

	render() {
		const table =
			E('table', { 'class': 'table leases' }, [
				E('tr', { 'class': 'tr table-titles' }, [
					E('th', { 'class': 'th' }, _('Name')),
					E('th', { 'class': 'th' }, _('Interface')),
					E('th', { 'class': 'th' }, _('Active State')),
					E('th', { 'class': 'th' }, _('Initial 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) {
				const targets = Array.isArray(instancesInfo.status) ? instancesInfo.status : [];
				const instances = uci.sections('keepalived', 'vrrp_instance');

				cbi_update_table(table,
					targets.map(function(target) {
						let state;
						let state_initial;
						const instance_state = target.data.state;

						if (instance_state === 2) {
							state = 'MASTER';
						} else if (instance_state === 1) {
							state = 'BACKUP';
						} else if (instance_state === 0) {
							state = 'INIT';
						} else if (instance_state === 3) {
							state = 'FAULT';
						} else {
							state = 'UNKNOWN';
						}

						if (instances != '') {
							for (var i = 0; i < instances.length; i++) {
								if (instances[i]['name'] == target.data.iname) {
									state_initial = instances[i]['state'];
									break;
								}
							}
						}
						return  [
							target.data.iname,
							target.data.ifp_ifname,
							state,
							state_initial,
							target.stats.advert_sent,
							target.stats.advert_rcvd,
							new Date(target.data.last_transition * 1000)
						];
					}),
					E('em', _('There are no active instances'))
				);
			});
		});

		return E('div', {'class': 'cbi-map'}, [
			E('h2', _('VRRP')),
			E('div', {'class': 'cbi-map-descr'}, _('This overview shows the current status of the VRRP instances on this device.')),
			E('div', { 'class': 'cbi-section' }, table)
		]);
	},

	handleSave: null,
	handleSaveApply:null,
	handleReset: null
});