ssh update on connect + web: define unseen before offline
This commit is contained in:
parent
e02273e0ef
commit
1a7989a24e
|
@ -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}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
|
|
@ -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');
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-underscore-dangle
|
||||||
|
if (!node._wireless) {
|
||||||
|
tr.classList.add('unseen');
|
||||||
|
} else {
|
||||||
startdate.setMinutes(startdate.getMinutes() - config.node.offline);
|
startdate.setMinutes(startdate.getMinutes() - config.node.offline);
|
||||||
if (new Date(node.lastseen) < startdate) {
|
if (new Date(node.lastseen) < startdate) {
|
||||||
tr.classList.add('offline');
|
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);
|
lastseen.innerHTML = moment(node.lastseen).fromNow(true);
|
||||||
|
|
||||||
nodeID.innerHTML = node.node_id;
|
nodeID.innerHTML = node.node_id;
|
||||||
|
|
Loading…
Reference in New Issue