LinuxStatus() detects VALID hostname
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
c6dbbc3542
commit
bd3e75e687
|
@ -15,7 +15,8 @@ func draw(ls *LinuxStatus) {
|
||||||
|
|
||||||
ls.grid.SetNext(1,1)
|
ls.grid.SetNext(1,1)
|
||||||
|
|
||||||
ls.fqdn = gadgets.NewOneLiner(ls.grid, "hostname -f")
|
ls.hostnameStatus = gadgets.NewOneLiner(ls.grid, "status")
|
||||||
|
ls.hostname = gadgets.NewOneLiner(ls.grid, "hostname -f")
|
||||||
ls.hostshort = gadgets.NewOneLiner(ls.grid, "hostname -s")
|
ls.hostshort = gadgets.NewOneLiner(ls.grid, "hostname -s")
|
||||||
ls.domainname = gadgets.NewOneLiner(ls.grid, "domain name")
|
ls.domainname = gadgets.NewOneLiner(ls.grid, "domain name")
|
||||||
ls.resolver = gadgets.NewOneLiner(ls.grid, "nameservers =")
|
ls.resolver = gadgets.NewOneLiner(ls.grid, "nameservers =")
|
||||||
|
|
|
@ -3,8 +3,6 @@
|
||||||
package linuxstatus
|
package linuxstatus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
"go.wit.com/shell"
|
"go.wit.com/shell"
|
||||||
|
|
||||||
|
@ -14,11 +12,6 @@ import (
|
||||||
|
|
||||||
func (ls *LinuxStatus) GetDomainName() string {
|
func (ls *LinuxStatus) GetDomainName() string {
|
||||||
if ! me.Ready() {return ""}
|
if ! me.Ready() {return ""}
|
||||||
if me.window == nil {
|
|
||||||
log.Log(NOW, "me.window == nil")
|
|
||||||
} else {
|
|
||||||
log.Log(NOW, "me.window exists, but has not been drawn")
|
|
||||||
}
|
|
||||||
return me.domainname.Get()
|
return me.domainname.Get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,12 +19,6 @@ func (ls *LinuxStatus) setDomainName() {
|
||||||
if ! me.Ready() {return}
|
if ! me.Ready() {return}
|
||||||
|
|
||||||
dn := run("domainname")
|
dn := run("domainname")
|
||||||
if me.window == nil {
|
|
||||||
log.Log(NOW, "me.window == nil")
|
|
||||||
} else {
|
|
||||||
log.Log(NOW, "me.window exists, but has not been drawn")
|
|
||||||
log.Log(NOW, "me.window.Draw() =")
|
|
||||||
}
|
|
||||||
if (me.domainname.Get() != dn) {
|
if (me.domainname.Get() != dn) {
|
||||||
log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn)
|
log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn)
|
||||||
me.domainname.Set(dn)
|
me.domainname.Set(dn)
|
||||||
|
@ -39,13 +26,23 @@ func (ls *LinuxStatus) setDomainName() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ls *LinuxStatus) GetHostname() string {
|
||||||
|
if ! me.Ready() {return ""}
|
||||||
|
return me.hostname.Get()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ls *LinuxStatus) setHostname(newname string) {
|
||||||
|
if ! me.Ready() {return}
|
||||||
|
if newname == me.hostname.Get() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Log(CHANGE, "hostname has changed from", me.GetHostname(), "to", newname)
|
||||||
|
me.hostname.Set(newname)
|
||||||
|
me.changed = true
|
||||||
|
}
|
||||||
|
|
||||||
func (ls *LinuxStatus) GetHostShort() string {
|
func (ls *LinuxStatus) GetHostShort() string {
|
||||||
if ! me.Ready() {return ""}
|
if ! me.Ready() {return ""}
|
||||||
if me.window == nil {
|
|
||||||
log.Log(NOW, "me.window == nil")
|
|
||||||
} else {
|
|
||||||
log.Log(NOW, "me.window exists, but has not been drawn")
|
|
||||||
}
|
|
||||||
return me.hostshort.Get()
|
return me.hostshort.Get()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,35 +59,49 @@ func (ls *LinuxStatus) setHostShort() {
|
||||||
func lookupHostname() {
|
func lookupHostname() {
|
||||||
if ! me.Ready() {return}
|
if ! me.Ready() {return}
|
||||||
var err error
|
var err error
|
||||||
var s string = "gui.Label == nil"
|
var hostfqdn string = "broken"
|
||||||
s, err = fqdn.FqdnHostname()
|
hostfqdn, err = fqdn.FqdnHostname()
|
||||||
if (err != nil) {
|
if (err != nil) {
|
||||||
log.Error(err, "FQDN hostname error")
|
log.Error(err, "FQDN hostname error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Error(errors.New("full hostname should be: " + s))
|
log.Log(NET, "full hostname should be: ", hostfqdn)
|
||||||
|
|
||||||
me.setDomainName()
|
me.setDomainName()
|
||||||
me.setHostShort()
|
me.setHostShort()
|
||||||
|
|
||||||
/*
|
// these are authoritative
|
||||||
|
// if they work wrong, your linux configuration is wrong.
|
||||||
|
// Do not complain.
|
||||||
|
// Fix your distro if your box is otherwise not working this way
|
||||||
|
hshort := me.GetHostShort() // from `hostname -s`
|
||||||
|
dn := me.GetDomainName() // from `domanname`
|
||||||
|
hostname := me.GetHostname() // from `hostname -f`
|
||||||
|
|
||||||
|
if hostfqdn != hostname {
|
||||||
|
log.Log(WARN, "hostname", hostname, "does not equal fqdn.FqdnHostname()", hostfqdn)
|
||||||
|
// TODO: figure out what is wrong
|
||||||
|
}
|
||||||
|
|
||||||
var test string
|
var test string
|
||||||
test = hshort + "." + dn
|
test = hshort + "." + dn
|
||||||
if (me.status.GetHostname() != test) {
|
|
||||||
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
|
me.setHostname(test)
|
||||||
if (me.hostnameStatus.S != "BROKEN") {
|
|
||||||
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "does not equal", test)
|
if (hostname != test) {
|
||||||
|
log.Log(CHANGE, "hostname", hostname, "does not equal", test)
|
||||||
|
if (me.hostnameStatus.Get() != "BROKEN") {
|
||||||
|
log.Log(CHANGE, "hostname", hostname, "does not equal", test)
|
||||||
me.changed = true
|
me.changed = true
|
||||||
me.hostnameStatus.SetText("BROKEN")
|
me.hostnameStatus.Set("BROKEN")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (me.hostnameStatus.S != "VALID") {
|
if (me.hostnameStatus.Get() != "VALID") {
|
||||||
log.Log(CHANGE, "me.hostname", me.status.GetHostname(), "is valid")
|
log.Log(CHANGE, "hostname", hostname, "is valid")
|
||||||
me.hostnameStatus.SetText("VALID")
|
me.hostnameStatus.Set("VALID")
|
||||||
me.changed = true
|
me.changed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if the hostname is good
|
// returns true if the hostname is good
|
||||||
|
|
|
@ -27,9 +27,10 @@ type LinuxStatus struct {
|
||||||
group *gui.Node
|
group *gui.Node
|
||||||
grid *gui.Node
|
grid *gui.Node
|
||||||
|
|
||||||
|
hostnameStatus *gadgets.OneLiner
|
||||||
|
hostname *gadgets.OneLiner
|
||||||
hostshort *gadgets.OneLiner
|
hostshort *gadgets.OneLiner
|
||||||
domainname *gadgets.OneLiner
|
domainname *gadgets.OneLiner
|
||||||
fqdn *gadgets.OneLiner
|
|
||||||
resolver *gadgets.OneLiner
|
resolver *gadgets.OneLiner
|
||||||
uid *gadgets.OneLiner
|
uid *gadgets.OneLiner
|
||||||
IPv4 *gadgets.OneLiner
|
IPv4 *gadgets.OneLiner
|
||||||
|
|
Loading…
Reference in New Issue