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) {
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}
}

View File

@ -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")

View File

@ -86,15 +86,17 @@ const guiList = {};
option = domlib.newAt(tr, 'td'),
edit = domlib.newAt(option, 'div');
// 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');
}
// eslint-disable-next-line no-underscore-dangle
if (!node._wireless) {
tr.classList.add('unseen');
}
lastseen.innerHTML = moment(node.lastseen).fromNow(true);
nodeID.innerHTML = node.node_id;