ssh update on connect + web: define unseen before offline

This commit is contained in:
Martin Geno 2017-07-06 08:03:37 +02:00
parent e02273e0ef
commit 1a7989a24e
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
3 changed files with 18 additions and 18 deletions

View File

@ -59,23 +59,17 @@ func NewNode(nodeOrigin *yanicRuntime.Node) *Node {
} }
func (n *Node) SSHUpdate(ssh *ssh.Manager, iface string, oldnode *Node) { func (n *Node) SSHUpdate(ssh *ssh.Manager, iface string, oldnode *Node) {
if oldnode == nil {
return
}
addr := n.GetAddress(iface) addr := n.GetAddress(iface)
if n.Hostname != oldnode.Hostname { if oldnode == nil || n.Hostname != oldnode.Hostname {
ssh.ExecuteOn(addr, fmt.Sprintf(SSHUpdateHostname, n.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)) 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)) 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 { func (n *Node) GetAddress(iface string) net.TCPAddr {
return net.TCPAddr{IP: n.Address, Port: 22, Zone: iface} return net.TCPAddr{IP: n.Address, Port: 22, Zone: iface}
} }

View File

@ -65,6 +65,10 @@ func (nodes *Nodes) LearnNode(n *yanic.Node) {
logger.Infof("new node with uptime: %s", uptime) logger.Infof("new node with uptime: %s", uptime)
nodes.Current[node.NodeID] = node 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) nodes.notify(node, false)
} }
@ -96,7 +100,7 @@ func (nodes *Nodes) Updater() {
defer nodes.Unlock() defer nodes.Unlock()
for nodeid, node := range nodes.List { for nodeid, node := range nodes.List {
if n, ok := nodes.Current[nodeid]; ok { 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") log.Log.Debug("updater per ssh runs")

View File

@ -45,9 +45,9 @@ const guiList = {};
case 'ChanUtil': case 'ChanUtil':
// eslint-disable-next-line id-length // eslint-disable-next-line id-length
let aMax = a.statistics.wireless.map((d) => let aMax = a.statistics.wireless.map((d) =>
d.ChanUtil d.ChanUtil
).sort(sortNumber), ).sort(sortNumber),
// eslint-disable-next-line id-length // eslint-disable-next-line id-length
bMax = b.statistics.wireless.map((d) => bMax = b.statistics.wireless.map((d) =>
d.ChanUtil d.ChanUtil
).sort(sortNumber); ).sort(sortNumber);
@ -86,15 +86,17 @@ const guiList = {};
option = domlib.newAt(tr, 'td'), option = domlib.newAt(tr, 'td'),
edit = domlib.newAt(option, 'div'); edit = domlib.newAt(option, 'div');
startdate.setMinutes(startdate.getMinutes() - config.node.offline); // eslint-disable-next-line no-underscore-dangle
if (new Date(node.lastseen) < startdate) {
tr.classList.add('offline');
}
// eslint-disable-next-line no-underscore-dangle
if (!node._wireless) { if (!node._wireless) {
tr.classList.add('unseen'); 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); lastseen.innerHTML = moment(node.lastseen).fromNow(true);
nodeID.innerHTML = node.node_id; nodeID.innerHTML = node.node_id;