summaryrefslogtreecommitdiff
path: root/hostname.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-21 02:23:47 -0600
committerJeff Carr <[email protected]>2024-01-21 02:23:47 -0600
commit433d83e63678e4483e1d8af2e522c7b05c7d7909 (patch)
tree7a6168fd19f27c5af9b241c45d0fe33ef9be21d7 /hostname.go
parentfdac7e7b8944d51b8207c1797edd0be9450de7b8 (diff)
fix name changesv0.5.6
new gadgets correct go mod updated paths Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'hostname.go')
-rw-r--r--hostname.go76
1 files changed, 47 insertions, 29 deletions
diff --git a/hostname.go b/hostname.go
index c36541a..2a2742c 100644
--- a/hostname.go
+++ b/hostname.go
@@ -4,6 +4,7 @@ package linuxstatus
import (
"io/ioutil"
+
"go.wit.com/log"
// will try to get this hosts FQDN
@@ -11,65 +12,81 @@ import (
)
func (ls *LinuxStatus) GetDomainName() string {
- if ! me.Ready() {return ""}
- return me.domainname.Get()
+ if !me.Ready() {
+ return ""
+ }
+ return me.domainname.String()
}
func (ls *LinuxStatus) setDomainName() {
- if ! me.Ready() {return}
+ if !me.Ready() {
+ return
+ }
dn := run("domainname")
- if (me.domainname.Get() != dn) {
+ if me.domainname.String() != dn {
log.Log(CHANGE, "domainname has changed from", me.GetDomainName(), "to", dn)
- me.domainname.Set(dn)
+ me.domainname.SetValue(dn)
me.changed = true
}
}
func (ls *LinuxStatus) GetHostname() string {
- if ! me.Ready() {return ""}
- return me.hostname.Get()
+ if !me.Ready() {
+ return ""
+ }
+ return me.hostname.String()
}
func (ls *LinuxStatus) ValidHostname() bool {
- if ! me.Ready() {return false}
- if me.hostnameStatus.Get() == "WORKING" {
+ if !me.Ready() {
+ return false
+ }
+ if me.hostnameStatus.String() == "WORKING" {
return true
}
return false
}
func (ls *LinuxStatus) setHostname(newname string) {
- if ! me.Ready() {return}
- if newname == me.hostname.Get() {
+ if !me.Ready() {
+ return
+ }
+ if newname == me.hostname.String() {
return
}
log.Log(CHANGE, "hostname has changed from", me.GetHostname(), "to", newname)
- me.hostname.Set(newname)
+ me.hostname.SetValue(newname)
me.changed = true
}
func (ls *LinuxStatus) GetHostShort() string {
- if ! me.Ready() {return ""}
- return me.hostshort.Get()
+ if !me.Ready() {
+ return ""
+ }
+ return me.hostshort.String()
}
func (ls *LinuxStatus) setHostShort() {
- if ! me.Ready() {return}
+ if !me.Ready() {
+ return
+ }
hshort := run("hostname -s")
- if (me.hostshort.Get() != hshort) {
- log.Log(CHANGE, "hostname -s has changed from", me.hostshort.Get(), "to", hshort)
- me.hostshort.Set(hshort)
+ if me.hostshort.String() != hshort {
+ log.Log(CHANGE, "hostname -s has changed from", me.hostshort.String(), "to", hshort)
+ me.hostshort.SetValue(hshort)
me.changed = true
}
}
func lookupHostname() {
- if ! me.Ready() {return}
+ if !me.Ready() {
+ return
+ }
var err error
var hostfqdn string = "broken"
hostfqdn, err = fqdn.FqdnHostname()
- if (err != nil) {
+ if err != nil {
log.Error(err, "FQDN hostname error")
return
}
@@ -82,8 +99,8 @@ func lookupHostname() {
// 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`
+ hshort := me.GetHostShort() // from `hostname -s`
+ dn := me.GetDomainName() // from `domanname`
hostname := me.GetHostname() // from `hostname -f`
if hostfqdn != hostname {
@@ -96,17 +113,17 @@ func lookupHostname() {
me.setHostname(test)
- if (hostname != test) {
+ if hostname != test {
log.Log(CHANGE, "hostname", hostname, "does not equal", test)
- if (me.hostnameStatus.Get() != "BROKEN") {
+ if me.hostnameStatus.String() != "BROKEN" {
log.Log(CHANGE, "hostname", hostname, "does not equal", test)
me.changed = true
- me.hostnameStatus.Set("BROKEN")
+ me.hostnameStatus.SetValue("BROKEN")
}
} else {
- if (me.hostnameStatus.Get() != "WORKING") {
+ if me.hostnameStatus.String() != "WORKING" {
log.Log(CHANGE, "hostname", hostname, "is valid")
- me.hostnameStatus.Set("WORKING")
+ me.hostnameStatus.SetValue("WORKING")
me.changed = true
}
}
@@ -115,7 +132,8 @@ func lookupHostname() {
// returns true if the hostname is good
// check that all the OS settings are correct here
// On Linux, /etc/hosts, /etc/hostname
-// and domainname and hostname
+//
+// and domainname and hostname
func goodHostname() bool {
content, err := ioutil.ReadFile("/etc/hostname")
if err != nil {
@@ -132,7 +150,7 @@ func goodHostname() bool {
log.Log(NOW, "hostname short =", hs, "domainname =", dn)
tmp := hs + "." + dn
- if (hostname == tmp) {
+ if hostname == tmp {
log.Log(NOW, "hostname seems to be good", hostname)
return true
}