|
|
|
@ -11,10 +11,13 @@ import (
|
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
|
|
"github.com/rocky-linux/rpaste/modules/setting"
|
|
|
|
|
"github.com/rocky-linux/rpaste/modules/utility"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
buf bytes.Buffer
|
|
|
|
|
buf bytes.Buffer
|
|
|
|
|
osID string
|
|
|
|
|
sysInfoReturn string
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type SystemInfo struct {
|
|
|
|
@ -45,8 +48,10 @@ type SystemInfo struct {
|
|
|
|
|
YumConf string
|
|
|
|
|
LastTwentyPackages string
|
|
|
|
|
EFISupport string
|
|
|
|
|
AppArmorStatus string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Distro agnostic functions
|
|
|
|
|
func osRelease() string {
|
|
|
|
|
app := "uniq"
|
|
|
|
|
args := []string{"/etc/os-release"}
|
|
|
|
@ -82,22 +87,6 @@ func desktopInstalled() string {
|
|
|
|
|
return values
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func selinuxStatus() string {
|
|
|
|
|
app1 := "getenforce"
|
|
|
|
|
app2 := "grep -v '^#' /etc/sysconfig/selinux"
|
|
|
|
|
cmd1, _ := exec.Command(app1).CombinedOutput()
|
|
|
|
|
cmd2, _ := exec.Command("/bin/sh", "-c", app2).CombinedOutput()
|
|
|
|
|
combined := string(cmd1) + string(cmd2)
|
|
|
|
|
return combined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func selinuxErrors() string {
|
|
|
|
|
// I'm not proud of this
|
|
|
|
|
app := "journalctl --since yesterday |grep avc: | grep -Eo comm='[^ ]+' | sort |uniq -c |sort -rn"
|
|
|
|
|
cmd, _ := exec.Command("/bin/sh", "-c", app).CombinedOutput()
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func cpuInfo() string {
|
|
|
|
|
// I'm not proud of this
|
|
|
|
|
app := "grep 'model name' /proc/cpuinfo | awk -F: '{print $2}' | uniq -c | sed -re 's/^ +//'"
|
|
|
|
@ -179,6 +168,33 @@ func drmInfo() string {
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func dmesgTail() string {
|
|
|
|
|
// I'm not proud of this
|
|
|
|
|
// Maybe I can implement a tail-like function
|
|
|
|
|
app := "dmesg | tail"
|
|
|
|
|
cmd, _ := exec.Command("/bin/sh", "-c", app).CombinedOutput()
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func lastTenReboots() string {
|
|
|
|
|
app := "last"
|
|
|
|
|
args := []string{
|
|
|
|
|
"-x",
|
|
|
|
|
"-n10",
|
|
|
|
|
"reboot",
|
|
|
|
|
"runlevel",
|
|
|
|
|
}
|
|
|
|
|
cmd, _ := exec.Command(app, args...).CombinedOutput()
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func efiSupport() string {
|
|
|
|
|
app := "efibootmgr"
|
|
|
|
|
args := []string{"-v"}
|
|
|
|
|
cmd, _ := exec.Command(app, args...).CombinedOutput()
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func xorgModules() string {
|
|
|
|
|
// I'm not proud of this
|
|
|
|
|
app := "grep LoadModule /var/log/Xorg.0.log ~/.local/share/xorg/Xorg.0.log | cut -d '\"' -f 2 | xargs"
|
|
|
|
@ -201,23 +217,23 @@ func xorgErrors() string {
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func dmesgTail() string {
|
|
|
|
|
// I'm not proud of this
|
|
|
|
|
// Maybe I can implement a tail-like function
|
|
|
|
|
app := "dmesg | tail"
|
|
|
|
|
cmd, _ := exec.Command("/bin/sh", "-c", app).CombinedOutput()
|
|
|
|
|
return string(cmd)
|
|
|
|
|
// End agnostic functions
|
|
|
|
|
|
|
|
|
|
// Red Hat (EL, Fedora) specific functions that may not work elsewhere
|
|
|
|
|
// using these on non-rh distros should be used with caution.
|
|
|
|
|
func selinuxStatus() string {
|
|
|
|
|
app1 := "getenforce"
|
|
|
|
|
app2 := "grep -v '^#' /etc/sysconfig/selinux"
|
|
|
|
|
cmd1, _ := exec.Command(app1).CombinedOutput()
|
|
|
|
|
cmd2, _ := exec.Command("/bin/sh", "-c", app2).CombinedOutput()
|
|
|
|
|
combined := string(cmd1) + string(cmd2)
|
|
|
|
|
return combined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func lastTenReboots() string {
|
|
|
|
|
app := "last"
|
|
|
|
|
args := []string{
|
|
|
|
|
"-x",
|
|
|
|
|
"-n10",
|
|
|
|
|
"reboot",
|
|
|
|
|
"runlevel",
|
|
|
|
|
}
|
|
|
|
|
cmd, _ := exec.Command(app, args...).CombinedOutput()
|
|
|
|
|
func selinuxErrors() string {
|
|
|
|
|
// I'm not proud of this
|
|
|
|
|
app := "journalctl --since yesterday |grep avc: | grep -Eo comm='[^ ]+' | sort |uniq -c |sort -rn"
|
|
|
|
|
cmd, _ := exec.Command("/bin/sh", "-c", app).CombinedOutput()
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -250,14 +266,36 @@ func lastTwentyPkgs() string {
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func efiSupport() string {
|
|
|
|
|
app := "efibootmgr"
|
|
|
|
|
args := []string{"-v"}
|
|
|
|
|
cmd, _ := exec.Command(app, args...).CombinedOutput()
|
|
|
|
|
// End Red Hat functions
|
|
|
|
|
|
|
|
|
|
// SuSE specific functions
|
|
|
|
|
// End SuSE
|
|
|
|
|
|
|
|
|
|
// Debian/Ubuntu specific functions
|
|
|
|
|
// End Debian
|
|
|
|
|
|
|
|
|
|
// AppArmor, affects Debian/Ubuntu/SuSE
|
|
|
|
|
func appArmorStatus() string {
|
|
|
|
|
app := "aa-status"
|
|
|
|
|
cmd, _ := exec.Command(app).CombinedOutput()
|
|
|
|
|
return string(cmd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// End AppArmor
|
|
|
|
|
|
|
|
|
|
func SysInfoGather() string {
|
|
|
|
|
osID = utility.GetGenericDistroID()
|
|
|
|
|
switch osID {
|
|
|
|
|
case "redhat":
|
|
|
|
|
sysInfoReturn = redHatSysInfoGather()
|
|
|
|
|
case "suse":
|
|
|
|
|
sysInfoReturn = suseSysInfoGather()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sysInfoReturn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func redHatSysInfoGather() string {
|
|
|
|
|
sysInfoData := SystemInfo{
|
|
|
|
|
OsRelease: osRelease(),
|
|
|
|
|
DesktopEnvs: desktopEnvs(),
|
|
|
|
@ -289,7 +327,41 @@ func SysInfoGather() string {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t := template.New("sysinfo")
|
|
|
|
|
t, _ = t.Parse(setting.SysInfoTemplate)
|
|
|
|
|
t, _ = t.Parse(setting.RedHatSysInfoTemplate)
|
|
|
|
|
t.Execute(&buf, sysInfoData)
|
|
|
|
|
sysInfoResults := buf.String()
|
|
|
|
|
return sysInfoResults
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func suseSysInfoGather() string {
|
|
|
|
|
sysInfoData := SystemInfo{
|
|
|
|
|
OsRelease: osRelease(),
|
|
|
|
|
DesktopEnvs: desktopEnvs(),
|
|
|
|
|
DesktopInstalled: desktopInstalled(),
|
|
|
|
|
AppArmorStatus: appArmorStatus(),
|
|
|
|
|
CPUInfo: cpuInfo(),
|
|
|
|
|
Support64bit: support64Bit(),
|
|
|
|
|
VirtSupport: virtSupport(),
|
|
|
|
|
LoadAverage: loadAverage(),
|
|
|
|
|
MemUsage: memUsage(),
|
|
|
|
|
TopCPUHogs: topCPUHogs(),
|
|
|
|
|
TopMemHogs: topMemHogs(),
|
|
|
|
|
DiskUsage: diskUsage(),
|
|
|
|
|
BlockDevs: blockDevs(),
|
|
|
|
|
PciDevs: pciDevs(),
|
|
|
|
|
USBDevs: usbDevs(),
|
|
|
|
|
DRMInfo: drmInfo(),
|
|
|
|
|
XorgModules: xorgModules(),
|
|
|
|
|
GLSupport: glSupport(),
|
|
|
|
|
XorgErrors: xorgErrors(),
|
|
|
|
|
DmesgTail: dmesgTail(),
|
|
|
|
|
LastTenReboots: lastTenReboots(),
|
|
|
|
|
LastTwentyPackages: lastTwentyPkgs(),
|
|
|
|
|
EFISupport: efiSupport(),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t := template.New("sysinfo")
|
|
|
|
|
t, _ = t.Parse(setting.SuseSysInfoTemplate)
|
|
|
|
|
t.Execute(&buf, sysInfoData)
|
|
|
|
|
sysInfoResults := buf.String()
|
|
|
|
|
return sysInfoResults
|
|
|
|
|