From 1a7989a24eb2ce3b431fe602a5307e81123f0e57 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Thu, 6 Jul 2017 08:03:37 +0200 Subject: [PATCH] ssh update on connect + web: define unseen before offline --- runtime/node.go | 12 +++--------- runtime/nodes.go | 6 +++++- webroot/js/gui_list.js | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/runtime/node.go b/runtime/node.go index 9fe4716..f4fc257 100644 --- a/runtime/node.go +++ b/runtime/node.go @@ -59,23 +59,17 @@ func NewNode(nodeOrigin *yanicRuntime.Node) *Node { } func (n *Node) SSHUpdate(ssh *ssh.Manager, iface string, oldnode *Node) { - if oldnode == nil { - return - } addr := n.GetAddress(iface) - if n.Hostname != oldnode.Hostname { + if oldnode == nil || n.Hostname != oldnode.Hostname { ssh.ExecuteOn(addr, fmt.Sprintf(SSHUpdateHostname, n.Hostname)) } - if n.Owner != oldnode.Owner { + if oldnode == nil || n.Owner != oldnode.Owner { ssh.ExecuteOn(addr, fmt.Sprintf(SSHUpdateOwner, n.Owner)) } - if !locationEqual(&n.Location, &oldnode.Location) { + if oldnode == nil || !locationEqual(&n.Location, &oldnode.Location) { ssh.ExecuteOn(addr, fmt.Sprintf(SSHUpdateLocation, n.Location.Latitude, n.Location.Longtitude)) } } -func (n *Node) SSHSet(ssh *ssh.Manager, iface string) { - n.SSHUpdate(ssh, iface, nil) -} func (n *Node) GetAddress(iface string) net.TCPAddr { return net.TCPAddr{IP: n.Address, Port: 22, Zone: iface} } diff --git a/runtime/nodes.go b/runtime/nodes.go index 31c5b59..b8d67a3 100644 --- a/runtime/nodes.go +++ b/runtime/nodes.go @@ -65,6 +65,10 @@ func (nodes *Nodes) LearnNode(n *yanic.Node) { logger.Infof("new node with uptime: %s", uptime) nodes.Current[node.NodeID] = node + if lNode := nodes.List[node.NodeID]; lNode != nil { + lNode.Address = node.Address + go lNode.SSHUpdate(nodes.ssh, nodes.iface, node) + } nodes.notify(node, false) } @@ -96,7 +100,7 @@ func (nodes *Nodes) Updater() { defer nodes.Unlock() for nodeid, node := range nodes.List { if n, ok := nodes.Current[nodeid]; ok { - go node.SSHUpdate(nodes.ssh, nodes.iface, n) + go n.SSHUpdate(nodes.ssh, nodes.iface, node) } } log.Log.Debug("updater per ssh runs") diff --git a/webroot/js/gui_list.js b/webroot/js/gui_list.js index 8e1a4bc..7769063 100644 --- a/webroot/js/gui_list.js +++ b/webroot/js/gui_list.js @@ -45,9 +45,9 @@ const guiList = {}; case 'ChanUtil': // eslint-disable-next-line id-length let aMax = a.statistics.wireless.map((d) => - d.ChanUtil - ).sort(sortNumber), - // eslint-disable-next-line id-length + d.ChanUtil + ).sort(sortNumber), + // eslint-disable-next-line id-length bMax = b.statistics.wireless.map((d) => d.ChanUtil ).sort(sortNumber); @@ -86,15 +86,17 @@ const guiList = {}; option = domlib.newAt(tr, 'td'), edit = domlib.newAt(option, 'div'); - startdate.setMinutes(startdate.getMinutes() - config.node.offline); - if (new Date(node.lastseen) < startdate) { - tr.classList.add('offline'); - } - // eslint-disable-next-line no-underscore-dangle + // eslint-disable-next-line no-underscore-dangle if (!node._wireless) { tr.classList.add('unseen'); + } else { + startdate.setMinutes(startdate.getMinutes() - config.node.offline); + if (new Date(node.lastseen) < startdate) { + tr.classList.add('offline'); + } } + lastseen.innerHTML = moment(node.lastseen).fromNow(true); nodeID.innerHTML = node.node_id;