update code
This commit is contained in:
parent
c7dc28fc44
commit
1a80ec155f
26 changed files with 302 additions and 393 deletions
77
.vscode/settings.json
vendored
77
.vscode/settings.json
vendored
|
@ -1,3 +1,78 @@
|
||||||
{
|
{
|
||||||
"go.buildFlags": ["-tags=linux"],
|
// Go
|
||||||
|
"go.buildFlags": [
|
||||||
|
"-tags=linux" // change this to "-tags=windows" when working for a windows feature
|
||||||
|
],
|
||||||
|
"go.inlayHints.assignVariableTypes": true, // see variable types inline
|
||||||
|
"go.diagnostic.vulncheck": "Imports", // ?
|
||||||
|
// -------------------------------------------
|
||||||
|
// Anchors
|
||||||
|
"commentAnchors.tags.list": [
|
||||||
|
{
|
||||||
|
"tag": "FILLME",
|
||||||
|
"iconColor": "default",
|
||||||
|
"highlightColor": "#A8C993",
|
||||||
|
"scope": "workspace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "NEXT",
|
||||||
|
"iconColor": "default",
|
||||||
|
"highlightColor": "#12449f",
|
||||||
|
"scope": "file"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "ANCHOR",
|
||||||
|
"iconColor": "default",
|
||||||
|
"highlightColor": "#A8C023",
|
||||||
|
"scope": "file"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "TODO",
|
||||||
|
"iconColor": "blue",
|
||||||
|
"highlightColor": "#3ea8ff",
|
||||||
|
"scope": "workspace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "FIXME",
|
||||||
|
"iconColor": "red",
|
||||||
|
"highlightColor": "#F44336",
|
||||||
|
"scope": "workspace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "STUB",
|
||||||
|
"iconColor": "purple",
|
||||||
|
"highlightColor": "#BA68C8",
|
||||||
|
"scope": "file"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "NOTE",
|
||||||
|
"iconColor": "orange",
|
||||||
|
"highlightColor": "#FFB300",
|
||||||
|
"scope": "file"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "REVIEW",
|
||||||
|
"iconColor": "green",
|
||||||
|
"highlightColor": "#64DD17",
|
||||||
|
"scope": "workspace"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "SECTION",
|
||||||
|
"iconColor": "blurple",
|
||||||
|
"highlightColor": "#896afc",
|
||||||
|
"scope": "workspace",
|
||||||
|
"behavior": "region"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"tag": "LINK",
|
||||||
|
"iconColor": "#2ecc71",
|
||||||
|
"highlightColor": "#2ecc71",
|
||||||
|
"scope": "workspace",
|
||||||
|
"behavior": "link"
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// LOCALIZATION
|
||||||
|
"editor.unicodeHighlight.allowedLocales": {
|
||||||
|
"tr": true
|
||||||
|
},
|
||||||
}
|
}
|
10
Makefile
10
Makefile
|
@ -49,10 +49,18 @@ install:
|
||||||
@sudo mkdir -p "${DESTDIR}/${DATA_DIR}"
|
@sudo mkdir -p "${DESTDIR}/${DATA_DIR}"
|
||||||
|
|
||||||
linux_goloader_install:
|
linux_goloader_install:
|
||||||
|
# NEXT
|
||||||
sudo go build -o ${DESTDIR}/usr/bin/${REPO_NAME} ./cmd/ahenk-go/
|
sudo go build -o ${DESTDIR}/usr/bin/${REPO_NAME} ./cmd/ahenk-go/
|
||||||
|
|
||||||
|
@echo "linux_goloader_install option also removes all datadir!"
|
||||||
|
@sudo rm -rf "${DESTDIR}/${DATA_DIR}"
|
||||||
|
|
||||||
@sudo mkdir -p "${DESTDIR}/${DATA_DIR}"
|
@sudo mkdir -p "${DESTDIR}/${DATA_DIR}"
|
||||||
sudo cp -r ./plugins "${DESTDIR}/${DATA_DIR}/"
|
sudo cp -r ./plugins "${DESTDIR}/${DATA_DIR}/"
|
||||||
|
sudo cp -r ./pkg "${DESTDIR}/${DATA_DIR}/"
|
||||||
|
sudo cp go.mod "${DESTDIR}/${DATA_DIR}/"
|
||||||
|
sudo cp go.sum "${DESTDIR}/${DATA_DIR}/"
|
||||||
|
sudo cp version "${DESTDIR}/${DATA_DIR}/"
|
||||||
|
|
||||||
|
|
||||||
windows_install:
|
windows_install:
|
||||||
|
|
|
@ -4,9 +4,10 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/cmd/plugin"
|
||||||
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/confdir"
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/confdir"
|
||||||
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/pluginmanager"
|
|
||||||
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
|
||||||
|
|
||||||
"github.com/sevlyar/go-daemon"
|
"github.com/sevlyar/go-daemon"
|
||||||
|
@ -20,6 +21,7 @@ func main() {
|
||||||
switch os.Args[1] {
|
switch os.Args[1] {
|
||||||
case "start":
|
case "start":
|
||||||
utils.CreatePath(confdir.Paths.Data)
|
utils.CreatePath(confdir.Paths.Data)
|
||||||
|
utils.CreatePath(confdir.Paths.Logs)
|
||||||
cntxt := &daemon.Context{
|
cntxt := &daemon.Context{
|
||||||
PidFileName: confdir.Paths.Pid,
|
PidFileName: confdir.Paths.Pid,
|
||||||
PidFilePerm: 0644,
|
PidFilePerm: 0644,
|
||||||
|
@ -55,12 +57,16 @@ func main() {
|
||||||
|
|
||||||
case "tmptest":
|
case "tmptest":
|
||||||
log.Print("TEMPORARY TEST STARTED, log files are NOT redirecting!")
|
log.Print("TEMPORARY TEST STARTED, log files are NOT redirecting!")
|
||||||
plugFunctions := map[string][]string{
|
plugFunctions := []string{"tmptest", "resources"}
|
||||||
"tmptest": {"TmpTest"},
|
plugin.ConnectPlugins(plugFunctions)
|
||||||
"resources": {"AhenkInfo", "ResourceUsage"},
|
|
||||||
}
|
|
||||||
pluginmanager.StartPlugins(plugFunctions)
|
|
||||||
|
|
||||||
|
plugin.Tmptest.TmpTest()
|
||||||
|
plugin.LogPlugin("Agent Info", plugin.Resources.AgentInfo(), true)
|
||||||
|
plugin.LogPlugin("Resource Usage", plugin.Resources.ResourceUsage(), true)
|
||||||
|
|
||||||
|
// comment these if you want to run usual code after tmptest
|
||||||
|
log.Println("exiting before making usual code")
|
||||||
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic("Please enter a valid option !")
|
panic("Please enter a valid option !")
|
||||||
|
@ -73,9 +79,6 @@ func main() {
|
||||||
if current.Uid != "0" {
|
if current.Uid != "0" {
|
||||||
log.Fatal("Ahenk-go requires superuser privilege")
|
log.Fatal("Ahenk-go requires superuser privilege")
|
||||||
}
|
}
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
// plugFunctions := map[string][]string{
|
log.Println("bye")
|
||||||
// "resources": {"AhenkInfo", "ResourceUsage"},
|
|
||||||
// }
|
|
||||||
// pluginmanager.StartPlugins(plugFunctions)
|
|
||||||
}
|
}
|
||||||
|
|
3
cmd/plugin/check.go
Normal file
3
cmd/plugin/check.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
// NEXT
|
|
@ -1,6 +1,6 @@
|
||||||
//go:build linux && !windows
|
//go:build linux && !windows
|
||||||
|
|
||||||
package pluginmanager
|
package plugin
|
||||||
|
|
||||||
import "github.com/eh-steve/goloader/jit"
|
import "github.com/eh-steve/goloader/jit"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//go:build windows
|
//go:build windows
|
||||||
|
|
||||||
package pluginmanager
|
package plugin
|
||||||
|
|
||||||
import "github.com/eh-steve/goloader/jit"
|
import "github.com/eh-steve/goloader/jit"
|
||||||
|
|
29
cmd/plugin/load.go
Normal file
29
cmd/plugin/load.go
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/confdir"
|
||||||
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
|
||||||
|
"github.com/eh-steve/goloader/jit"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Load Plugin placed in confdir.Paths.Plugins, returns empty interface with channel
|
||||||
|
//
|
||||||
|
// Do not forget to cast in plugin manager
|
||||||
|
func LoadPlugin(plugName string, conf jit.BuildConfig, chn chan interface{}) {
|
||||||
|
|
||||||
|
// TODO if error caugth try without relative path, this will be good for local testing
|
||||||
|
loadable, err := jit.BuildGoPackage(conf, confdir.Paths.Plugins+plugName+"/")
|
||||||
|
utils.Check(err)
|
||||||
|
|
||||||
|
module, err := loadable.Load()
|
||||||
|
utils.Check(err)
|
||||||
|
plugSymbols := module.SymbolsByPkg[loadable.ImportPath]
|
||||||
|
|
||||||
|
// TODO also allow lookup another symbol other than PlugnameConnect
|
||||||
|
plugOut := plugSymbols[(utils.FirstUpperEN(plugName) + "Connect")]
|
||||||
|
if plugOut == nil {
|
||||||
|
panic("There is no exported symbol in " + plugName)
|
||||||
|
}
|
||||||
|
|
||||||
|
chn <- plugOut
|
||||||
|
}
|
106
cmd/plugin/manager.go
Normal file
106
cmd/plugin/manager.go
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
package plugin // pluginmanager
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// General Functions/Methods that each plugin has
|
||||||
|
type PlugGeneral interface {
|
||||||
|
// Get Plugin Info
|
||||||
|
Info() map[string]interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// plugins/resources
|
||||||
|
type ResourcesI interface {
|
||||||
|
// Get Agent Info, see plugins/resources for more information
|
||||||
|
AgentInfo() map[string]interface{} // LINK plugins/resources/main.go#AgentInfo
|
||||||
|
|
||||||
|
// Get Resource Usage, see plugins/resources for more information
|
||||||
|
ResourceUsage() map[string]interface{} // LINK plugins/resources/main.go#ResourceUsage
|
||||||
|
}
|
||||||
|
|
||||||
|
// plugins/tmptest
|
||||||
|
type TmpTestI interface {
|
||||||
|
// Run temporary tests
|
||||||
|
TmpTest() // LINK plugins/tmptest/main.go#TmpTest
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILLME[epic=new-plugin-template]
|
||||||
|
// type NewPluginInterfaceI interface {
|
||||||
|
// // explanation
|
||||||
|
// PluginFunction() returnType // link plugins/pluginname/file.go#PluginFunction
|
||||||
|
// }
|
||||||
|
|
||||||
|
var Tmptest TmpTestI
|
||||||
|
var Resources ResourcesI
|
||||||
|
|
||||||
|
// FILLME[epic=new-plugin-template]
|
||||||
|
// var pluginname NewPluginInterfaceI
|
||||||
|
|
||||||
|
// Connect plugins to main code
|
||||||
|
//
|
||||||
|
// Gets plugin names as string slice
|
||||||
|
func ConnectPlugins(params []string) {
|
||||||
|
|
||||||
|
conf := getJITConf()
|
||||||
|
chanPlug := make(chan interface{})
|
||||||
|
|
||||||
|
for _, v := range params {
|
||||||
|
go LoadPlugin(v, conf, chanPlug)
|
||||||
|
plug, ok := <-chanPlug
|
||||||
|
|
||||||
|
switch v {
|
||||||
|
case "tmptest":
|
||||||
|
Tmptest = plug.(TmpTestI)
|
||||||
|
checkPlugin(Tmptest, ok)
|
||||||
|
case "resources":
|
||||||
|
Resources = plug.(ResourcesI)
|
||||||
|
checkPlugin(Resources, ok)
|
||||||
|
|
||||||
|
// FILLME[epic=new-plugin-template]
|
||||||
|
// case "pluginname":
|
||||||
|
// Pluginname = plug.(NewPluginInterfaceI)
|
||||||
|
// checkPlugin(Pluginname, ok)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logs plugin outputs.
|
||||||
|
func LogPlugin(title string, mp map[string]interface{}, toJson bool) {
|
||||||
|
log.Printf("\n----- %v -----\n", title)
|
||||||
|
if toJson {
|
||||||
|
data, err := json.MarshalIndent(&mp, "", " ")
|
||||||
|
utils.Check(err)
|
||||||
|
log.Println(string(data))
|
||||||
|
} else {
|
||||||
|
for i, v := range mp {
|
||||||
|
log.Printf("%v: %v\n", i, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks plugin status
|
||||||
|
func checkPlugin(plugVal interface{}, status bool) {
|
||||||
|
if status {
|
||||||
|
if plugVal == nil {
|
||||||
|
log.Fatal("Plugin loaded but there is no value!")
|
||||||
|
} else {
|
||||||
|
plugInfo := plugVal.(PlugGeneral).Info()
|
||||||
|
log.Printf("Plugin \"%v\" loaded and ready to use with version \"%v\" ", plugInfo["name"], plugInfo["version"])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if plugVal == nil {
|
||||||
|
log.Fatal("Plugin closed and there is no value! ")
|
||||||
|
} else {
|
||||||
|
log.Fatal("Plugin closed or there is an error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// // TODO response to Lider
|
||||||
|
// func createResponse() {
|
||||||
|
|
||||||
|
// }
|
3
cmd/plugin/refresh.go
Normal file
3
cmd/plugin/refresh.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
// NEXT
|
3
cmd/plugin/unload.go
Normal file
3
cmd/plugin/unload.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
// NEXT
|
12
go.mod
12
go.mod
|
@ -1,17 +1,17 @@
|
||||||
module git.aliberksandikci.com.tr/Liderahenk/ahenk-go
|
module git.aliberksandikci.com.tr/Liderahenk/ahenk-go
|
||||||
|
|
||||||
go 1.20
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/sevlyar/go-daemon v0.1.6
|
github.com/sevlyar/go-daemon v0.1.6
|
||||||
github.com/zcalusic/sysinfo v1.0.1
|
github.com/zcalusic/sysinfo v1.0.1
|
||||||
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b
|
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
|
||||||
golang.org/x/text v0.12.0
|
golang.org/x/text v0.13.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2 // indirect
|
github.com/eh-steve/goloader v0.0.0-20230731163325-b789213e8550 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
github.com/stretchr/testify v1.8.4 // indirect
|
github.com/stretchr/testify v1.8.4 // indirect
|
||||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||||
github.com/tklauser/numcpus v0.6.1 // indirect
|
github.com/tklauser/numcpus v0.6.1 // indirect
|
||||||
|
@ -22,5 +22,5 @@ require (
|
||||||
github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550
|
github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550
|
||||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
|
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible // direct
|
github.com/shirou/gopsutil v3.21.11+incompatible // direct
|
||||||
golang.org/x/sys v0.11.0 // direct
|
golang.org/x/sys v0.12.0 // direct
|
||||||
)
|
)
|
||||||
|
|
28
go.sum
28
go.sum
|
@ -1,13 +1,22 @@
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2 h1:0mZ2Y8x4dhPfm9eOlbzBx31YSLaECdPvKEBrL5Hc0YE=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2/go.mod h1:k7xs3CUwCvOU9aw851I6AEb6ZzZJ3nos5dZ6A/2ewM0=
|
github.com/eh-steve/goloader v0.0.0-20230731163325-b789213e8550 h1:8yXPOoUPeKZmC3QfqUY0wkerRf5OQ8YeCgSodrcC8J8=
|
||||||
|
github.com/eh-steve/goloader v0.0.0-20230731163325-b789213e8550/go.mod h1:k7xs3CUwCvOU9aw851I6AEb6ZzZJ3nos5dZ6A/2ewM0=
|
||||||
github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550 h1:clY7T47fFZdFcILcu7uksS7FStRaKMssCYGW0l/AoMo=
|
github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550 h1:clY7T47fFZdFcILcu7uksS7FStRaKMssCYGW0l/AoMo=
|
||||||
github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550/go.mod h1:p18VKcPYO8oWGYcQt/K5EGIGqak0ZT5HwVirGpUGZBg=
|
github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550/go.mod h1:p18VKcPYO8oWGYcQt/K5EGIGqak0ZT5HwVirGpUGZBg=
|
||||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
github.com/eh-steve/goloader/jit/testdata v0.0.0-20230730231803-5c95d7a5f4e2 h1:pulprUBu3Rncam2xFKzaUTf8SlbaoOHtNocYBSbvprI=
|
||||||
|
github.com/eh-steve/goloader/jit/testdata v0.0.0-20230730231803-5c95d7a5f4e2/go.mod h1:GyUY1mfY7NCdoVRo5H8+kmhLa/xE418ZcjfDfgwicXw=
|
||||||
|
github.com/eh-steve/goloader/unload v0.0.0-20230730231803-5c95d7a5f4e2 h1:XBYe9gRPYpfxBRO9kBeep/FZrbeIuxPn5d6dun2oLQU=
|
||||||
|
github.com/eh-steve/goloader/unload v0.0.0-20230730231803-5c95d7a5f4e2/go.mod h1:bA/aiceMvuZh45HAA/xzWJKT4E9EXqzmuPsB9yT/D/M=
|
||||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
|
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||||
|
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
|
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
|
||||||
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
|
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
|
||||||
|
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
|
||||||
|
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sevlyar/go-daemon v0.1.6 h1:EUh1MDjEM4BI109Jign0EaknA2izkOyi0LV3ro3QQGs=
|
github.com/sevlyar/go-daemon v0.1.6 h1:EUh1MDjEM4BI109Jign0EaknA2izkOyi0LV3ro3QQGs=
|
||||||
github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE=
|
github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE=
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
|
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
|
||||||
|
@ -22,12 +31,15 @@ github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFi
|
||||||
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||||
github.com/zcalusic/sysinfo v1.0.1 h1:cVh8q3codjh43AGRTa54dJ2Zq+qPejv8n2VWpxKViwc=
|
github.com/zcalusic/sysinfo v1.0.1 h1:cVh8q3codjh43AGRTa54dJ2Zq+qPejv8n2VWpxKViwc=
|
||||||
github.com/zcalusic/sysinfo v1.0.1/go.mod h1:LxwKwtQdbTIQc65drhjQzYzt0o7jfB80LrrZm7SWn8o=
|
github.com/zcalusic/sysinfo v1.0.1/go.mod h1:LxwKwtQdbTIQc65drhjQzYzt0o7jfB80LrrZm7SWn8o=
|
||||||
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
|
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
|
||||||
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
|
||||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
|
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||||
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
github.com/eh-steve/goloader/jit/testdata v0.0.0-20230730231803-5c95d7a5f4e2/go.mod h1:GyUY1mfY7NCdoVRo5H8+kmhLa/xE418ZcjfDfgwicXw=
|
|
||||||
github.com/eh-steve/goloader/unload v0.0.0-20230730231803-5c95d7a5f4e2/go.mod h1:bA/aiceMvuZh45HAA/xzWJKT4E9EXqzmuPsB9yT/D/M=
|
|
||||||
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
|
||||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
|
@ -7,6 +7,7 @@ type Path struct {
|
||||||
Plugins string `json:"Plugins"`
|
Plugins string `json:"Plugins"`
|
||||||
Logs string `json:"Logs"`
|
Logs string `json:"Logs"`
|
||||||
Pid string `json:"pid"`
|
Pid string `json:"pid"`
|
||||||
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var Paths Path
|
var Paths Path
|
||||||
|
|
|
@ -12,5 +12,6 @@ func getPaths() Path {
|
||||||
path.Plugins = path.Data + "plugins/"
|
path.Plugins = path.Data + "plugins/"
|
||||||
path.Logs = path.Data + "logs/"
|
path.Logs = path.Data + "logs/"
|
||||||
path.Pid = "/run/ahenk-go.pid"
|
path.Pid = "/run/ahenk-go.pid"
|
||||||
|
path.Version = path.Data + "version"
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
module git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/confdir
|
|
||||||
|
|
||||||
go 1.21.0
|
|
|
@ -1,7 +0,0 @@
|
||||||
module git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/pluginmanager
|
|
||||||
|
|
||||||
go 1.21.0
|
|
||||||
|
|
||||||
require github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550
|
|
||||||
|
|
||||||
require github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2 // indirect
|
|
|
@ -1,4 +0,0 @@
|
||||||
github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2 h1:0mZ2Y8x4dhPfm9eOlbzBx31YSLaECdPvKEBrL5Hc0YE=
|
|
||||||
github.com/eh-steve/goloader v0.0.0-20230730231803-5c95d7a5f4e2/go.mod h1:k7xs3CUwCvOU9aw851I6AEb6ZzZJ3nos5dZ6A/2ewM0=
|
|
||||||
github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550 h1:clY7T47fFZdFcILcu7uksS7FStRaKMssCYGW0l/AoMo=
|
|
||||||
github.com/eh-steve/goloader/jit v0.0.0-20230731163325-b789213e8550/go.mod h1:p18VKcPYO8oWGYcQt/K5EGIGqak0ZT5HwVirGpUGZBg=
|
|
|
@ -1,132 +0,0 @@
|
||||||
package pluginmanager
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
// General Functions/Methods that each plugin has
|
|
||||||
type PlugGeneral interface {
|
|
||||||
Info() (interface{}, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// plugins/resources
|
|
||||||
type Resources interface {
|
|
||||||
AgentInfo() (interface{}, error)
|
|
||||||
ResourceUsage() (interface{}, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type TmpTest interface {
|
|
||||||
TmpTest() (interface{}, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type anny any
|
|
||||||
|
|
||||||
// Start All plugins
|
|
||||||
func StartPlugins(params map[string][]string) {
|
|
||||||
// GeneralFunctions := []string{"Info"}
|
|
||||||
|
|
||||||
conf := getJITConf()
|
|
||||||
chanPlug := make(chan PluginStruct)
|
|
||||||
|
|
||||||
// var myint TmpTest
|
|
||||||
|
|
||||||
// for i, v := range params {
|
|
||||||
// v := append(v, GeneralFunctions...)
|
|
||||||
// go LoadPlugin2(i, v, conf, chanPlug)
|
|
||||||
// }
|
|
||||||
|
|
||||||
go LoadPlugin3("tmptest", conf, chanPlug)
|
|
||||||
a, ok := <-chanPlug
|
|
||||||
var an anny = a
|
|
||||||
fmt.Println(a, ok)
|
|
||||||
fmt.Println(an)
|
|
||||||
var aa []func() (interface{}, error)
|
|
||||||
for _, v := range a.Functions {
|
|
||||||
aa = append(aa, v)
|
|
||||||
}
|
|
||||||
fmt.Println(aa)
|
|
||||||
var loo interface{} = aa
|
|
||||||
fmt.Println(loo.(TmpTest))
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// -------------------------
|
|
||||||
// OLD PLUGIN IMPLEMENTATION
|
|
||||||
// -------------------------
|
|
||||||
//
|
|
||||||
|
|
||||||
// // FILLME creating new plugin interface, template
|
|
||||||
// // type NewPluginInterface interface {
|
|
||||||
// // PluginMethod() returnType
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// Loads Plugins and runs them concurrently.
|
|
||||||
// When you create a new plugin create a new interface and call this plugin in this function
|
|
||||||
// func PluginManager(params ...string) {
|
|
||||||
// chanPlug := make(chan interface{})
|
|
||||||
|
|
||||||
// go LoadPlugin("resources", chanPlug)
|
|
||||||
// res, ok := <-chanPlug
|
|
||||||
// var resources Resources = res.(Resources)
|
|
||||||
// checkPlugin(resources, ok)
|
|
||||||
|
|
||||||
// if len(params) > 0 && params[0] == "tmptest" {
|
|
||||||
// go LoadPlugin("tmptest", chanPlug)
|
|
||||||
// res, ok := <-chanPlug
|
|
||||||
// var tmptest TmpTest = res.(TmpTest)
|
|
||||||
// checkPlugin(res, ok)
|
|
||||||
// tmptest.TmpTest()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // FILLME Loading new plugin, template
|
|
||||||
// // go LoadPlugin("pluginName", chanPlug)
|
|
||||||
// // res, ok = <-chanPlug
|
|
||||||
// // var pluginName NewPluginInterface = res.(NewPluginInterface)
|
|
||||||
// // checkPlugin(res, ok)
|
|
||||||
|
|
||||||
// // Run plugins concurrently and log out
|
|
||||||
// go logPlugin("AgentInfo", resources.AgentInfo(), true)
|
|
||||||
// for {
|
|
||||||
// go logPlugin("ResourceUsage", resources.ResourceUsage(), true)
|
|
||||||
|
|
||||||
// // FILLME Running/Log out a plugin, template
|
|
||||||
// // go logPlugin("InfoAboutFunction", pluginName.Function(), true)
|
|
||||||
|
|
||||||
// time.Sleep(30 * time.Second)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Logs plugin outputs.
|
|
||||||
// func logPlugin(title string, mp map[string]interface{}, toJson bool) {
|
|
||||||
// log.Printf("\n----- %v -----\n", title)
|
|
||||||
// if toJson {
|
|
||||||
// data, err := json.MarshalIndent(&mp, "", " ")
|
|
||||||
// utils.Check(err)
|
|
||||||
// log.Println(string(data))
|
|
||||||
// } else {
|
|
||||||
// for i, v := range mp {
|
|
||||||
// log.Printf("%v: %v\n", i, v)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Checks plugin status
|
|
||||||
// func checkPlugin(plugVal interface{}, status bool) {
|
|
||||||
// if status {
|
|
||||||
// if plugVal == nil {
|
|
||||||
// log.Fatal("Plugin loaded but there is no value!")
|
|
||||||
// } else {
|
|
||||||
// plugInfo, _ := plugVal.(PlugGeneral).Info()
|
|
||||||
// log.Printf("Plugin \"%v\" loaded and ready to use, version \"%v\" ", plugInfo["name"], plugInfo["version"])
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// if plugVal == nil {
|
|
||||||
// log.Fatal("Plugin closed and there is no value! ")
|
|
||||||
// } else {
|
|
||||||
// log.Fatal("Plugin closed or there is an error")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // // TODO response to Lider
|
|
||||||
// // // func createResponse() {
|
|
||||||
|
|
||||||
// // // }
|
|
|
@ -1,140 +0,0 @@
|
||||||
package pluginmanager
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"plugin"
|
|
||||||
|
|
||||||
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/confdir"
|
|
||||||
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
|
|
||||||
"github.com/eh-steve/goloader/jit"
|
|
||||||
)
|
|
||||||
|
|
||||||
// type mytype func() (interface{}, error)
|
|
||||||
|
|
||||||
type PluginStruct struct {
|
|
||||||
PluginFunction map[string]interface{}
|
|
||||||
Functions map[string](func() (interface{}, error))
|
|
||||||
}
|
|
||||||
|
|
||||||
func LoadPlugin3(plugName string, conf jit.BuildConfig, chn chan PluginStruct) {
|
|
||||||
loadable, err := jit.BuildGoPackage(conf, confdir.Paths.Plugins+plugName+"/")
|
|
||||||
utils.Check(err)
|
|
||||||
module, err := loadable.Load()
|
|
||||||
utils.Check(err)
|
|
||||||
plugSymbols := module.SymbolsByPkg[loadable.ImportPath]
|
|
||||||
|
|
||||||
// fmt.Println(*deneme, *deneme2)
|
|
||||||
|
|
||||||
// var empt interface{} = plugSymbols
|
|
||||||
// a = empt.(TmpTest)
|
|
||||||
|
|
||||||
// var a TmpTest
|
|
||||||
// jit.RegisterTypes(plugSymbols["TmpTest"])
|
|
||||||
var plugMan PluginStruct
|
|
||||||
plugMan.PluginFunction = plugSymbols
|
|
||||||
fmt.Println(plugMan.PluginFunction)
|
|
||||||
plugMan.Functions = make(map[string](func() (interface{}, error)))
|
|
||||||
for i, v := range plugMan.PluginFunction {
|
|
||||||
switch f := v.(type) {
|
|
||||||
case func([]byte) (interface{}, error):
|
|
||||||
result, err := f([]byte(`{"k":"v"}`))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
fmt.Println(result)
|
|
||||||
case func() (interface{}, error):
|
|
||||||
fmt.Println(i, 1)
|
|
||||||
plugMan.Functions[i] = f
|
|
||||||
default:
|
|
||||||
fmt.Println(f)
|
|
||||||
panic("Function signature was not what was expected")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Println(plugMan.Functions)
|
|
||||||
for i, o := range plugMan.Functions {
|
|
||||||
// fmt.Println(i, o)
|
|
||||||
fmt.Println(i, &o)
|
|
||||||
// fmt.Println(i, *o)
|
|
||||||
}
|
|
||||||
// plugMan.Functions["TmpTest"]()
|
|
||||||
fmt.Println(1)
|
|
||||||
chn <- plugMan
|
|
||||||
// var empt mytype = plugSymbols["TmpTest"].(mytype)
|
|
||||||
|
|
||||||
// a := empt.(TmpTest)
|
|
||||||
// fmt.Println(empt)
|
|
||||||
|
|
||||||
// switch f := plugSymbols["MyFunc"].(type) {
|
|
||||||
// case func([]byte) (interface{}, error):
|
|
||||||
// result, err := f([]byte(`{"k":"v"}`))
|
|
||||||
// if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
// }
|
|
||||||
// fmt.Println(result)
|
|
||||||
// default:
|
|
||||||
// fmt.Println(f)
|
|
||||||
// panic("Function signature was not what was expected")
|
|
||||||
// }
|
|
||||||
|
|
||||||
// chn <- deneme
|
|
||||||
}
|
|
||||||
|
|
||||||
// func LoadPlugin2(plugName string, plugFunction []string, conf jit.BuildConfig, chn chan interface{}) {
|
|
||||||
|
|
||||||
// loadable, err := jit.BuildGoPackage(conf, confdir.Paths.Plugins+plugName+"/")
|
|
||||||
// utils.Check(err)
|
|
||||||
|
|
||||||
// module, err := loadable.Load()
|
|
||||||
|
|
||||||
// plugSymbols := module.SymbolsByPkg[loadable.ImportPath]
|
|
||||||
// utils.Check(err)
|
|
||||||
|
|
||||||
// for i, v := range plugFunction {
|
|
||||||
// var f interface{} = plugSymbols
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // switch f := plugSymbols["MyFunc"].(type) {
|
|
||||||
// // case func([]byte) (interface{}, error):
|
|
||||||
// // result, err := f([]byte(`{"k":"v"}`))
|
|
||||||
// // if err != nil {
|
|
||||||
// // panic(err)
|
|
||||||
// // }
|
|
||||||
// // fmt.Println(result)
|
|
||||||
// // default:
|
|
||||||
// // fmt.Println(f)
|
|
||||||
// // panic("Function signature was not what was expected")
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // chn <-
|
|
||||||
// }
|
|
||||||
|
|
||||||
//
|
|
||||||
// -------------------------
|
|
||||||
// OLD PLUGIN IMPLEMENTATION
|
|
||||||
// -------------------------
|
|
||||||
//
|
|
||||||
|
|
||||||
// Load Plugin placed in PluginDir, returns empty interface with channel
|
|
||||||
// Do not forget to cast in plugin manager
|
|
||||||
//
|
|
||||||
// Give Plugin Name as argument and be sure you compiled plugins with `-buildmode=plugin` to PluginDir as `pluginname.so`
|
|
||||||
func LoadPlugin(plugName string, chn chan interface{}) {
|
|
||||||
|
|
||||||
// TODO if error caugth try without relative path, this will be good for local testing
|
|
||||||
plug, err := plugin.Open(confdir.Paths.Plugins + plugName + ".so")
|
|
||||||
utils.Check(err)
|
|
||||||
|
|
||||||
// TODO also allow lookup another symbol other than PlugnameConnect
|
|
||||||
symPlug, err := plug.Lookup(utils.FirstUpperEN(plugName) + "Connect")
|
|
||||||
utils.Check(err)
|
|
||||||
|
|
||||||
var plugOut interface{}
|
|
||||||
plugOut, ok := symPlug.(interface{})
|
|
||||||
if !ok {
|
|
||||||
fmt.Println("unexpected type from module symbol")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
chn <- plugOut
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
module git.aliberksandikci.com.tr/Liderahenk/ahenk-go/plugins/resources
|
|
||||||
|
|
||||||
go 1.21.0
|
|
||||||
|
|
||||||
require git.aliberksandikci.com.tr/Liderahenk/ahenk-go v0.0.0-20230831165035-c1bc30d83082
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
|
|
||||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
|
||||||
github.com/tklauser/numcpus v0.6.1 // indirect
|
|
||||||
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
|
||||||
github.com/zcalusic/sysinfo v1.0.1 // indirect
|
|
||||||
golang.org/x/sys v0.11.0 // indirect
|
|
||||||
golang.org/x/text v0.12.0 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
||||||
)
|
|
|
@ -1,29 +0,0 @@
|
||||||
git.aliberksandikci.com.tr/Liderahenk/ahenk-go v0.0.0-20230831165035-c1bc30d83082 h1:xSuQQVwNcORPGt23VKivLIhOipz0hx9e5evxxiyV/No=
|
|
||||||
git.aliberksandikci.com.tr/Liderahenk/ahenk-go v0.0.0-20230831165035-c1bc30d83082/go.mod h1:CsfyC8E2IhrkmUf84/GvIDaofgSxtYdw3lojgQ8YMYc=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
|
||||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
|
|
||||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
||||||
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
|
|
||||||
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
|
|
||||||
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
|
|
||||||
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
|
|
||||||
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
|
|
||||||
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
|
||||||
github.com/zcalusic/sysinfo v1.0.1 h1:cVh8q3codjh43AGRTa54dJ2Zq+qPejv8n2VWpxKViwc=
|
|
||||||
github.com/zcalusic/sysinfo v1.0.1/go.mod h1:LxwKwtQdbTIQc65drhjQzYzt0o7jfB80LrrZm7SWn8o=
|
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
|
||||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
|
|
||||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
|
@ -1,14 +1,14 @@
|
||||||
package resources
|
package resources
|
||||||
|
|
||||||
func Info() (interface{}, error) {
|
func (p plug) Info() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"name": "resources",
|
"name": "resources",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"support": map[string]interface{}{
|
"support": map[string]interface{}{
|
||||||
"linux": "debian",
|
"linux": []string{"debian", "pardus23"},
|
||||||
"windows": "10",
|
"windows": "10",
|
||||||
},
|
},
|
||||||
"description": "Resource Usage Information and Controls",
|
"description": "Resource Usage Information and Controls",
|
||||||
"developer": "asandikci@aliberksandikci.com.tr",
|
"developer": "asandikci@aliberksandikci.com.tr",
|
||||||
}, nil
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,28 @@
|
||||||
package resources
|
package resources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/confdir"
|
||||||
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/osinfo"
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/osinfo"
|
||||||
|
"git.aliberksandikci.com.tr/Liderahenk/ahenk-go/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type plug string
|
||||||
|
|
||||||
|
// exported plugin Symbol
|
||||||
|
var ResourcesConnect plug
|
||||||
|
|
||||||
// return instant resource usage information
|
// return instant resource usage information
|
||||||
func ResourceUsage() (interface{}, error) {
|
func (p plug) ResourceUsage() map[string]interface{} { // ANCHOR[id=ResourceUsage]
|
||||||
var system osinfo.System
|
var system osinfo.System
|
||||||
system.GetSystemInfo()
|
system.GetSystemInfo()
|
||||||
|
|
||||||
data := map[string]interface{}{
|
return map[string]interface{}{
|
||||||
// CPU Information
|
// CPU Information
|
||||||
"CPU Physical Core Count": system.CPU.Cores,
|
"CPU Physical Core Count": system.CPU.Cores,
|
||||||
// "CPU Logical Core Count": system.CPU.Logical_core_count, // TODO
|
"CPU Logical Core Count": system.CPU.Threads,
|
||||||
// "CPU Actual Hz": system.CPU.ActualHz, // TODO
|
// "CPU Actual Hz": system.CPU.ActualHz, // TODO
|
||||||
// "CPU Advertised Hz": system.CPU.Hz_advertised, // TODO
|
// "CPU Advertised Hz": system.CPU.Hz_advertised, // TODO
|
||||||
// "Processor": system.CPU.Brand, // TODO
|
// "Processor": system.CPU.Brand, // TODO
|
||||||
|
@ -28,35 +36,32 @@ func ResourceUsage() (interface{}, error) {
|
||||||
"Usage Disk": system.Disk.Used,
|
"Usage Disk": system.Disk.Used,
|
||||||
"Device": system.Disk.Devices,
|
"Device": system.Disk.Devices,
|
||||||
}
|
}
|
||||||
|
// see https://github.com/Pardus-LiderAhenk/ahenk/blob/master/src/plugins/resource-usage/resource_info_fetcher.py
|
||||||
// TODO see https://github.com/Pardus-LiderAhenk/ahenk/blob/master/src/plugins/resource-usage/resource_info_fetcher.py
|
|
||||||
return data, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// return general Agent system information
|
// return general Agent system information
|
||||||
//
|
//
|
||||||
// these values changes rarely, see ResourceUsage() function for instant resource usage information
|
// these values changes rarely, see ResourceUsage() function for instant resource usage information
|
||||||
func AgentInfo() (interface{}, error) {
|
func (p plug) AgentInfo() map[string]interface{} { // ANCHOR[id=AgentInfo]
|
||||||
var system osinfo.System
|
var system osinfo.System
|
||||||
system.GetSystemInfo()
|
system.GetSystemInfo()
|
||||||
|
ver, err := os.ReadFile(confdir.Paths.Version)
|
||||||
|
utils.Check(err)
|
||||||
|
|
||||||
// Common data
|
// Common data
|
||||||
data := map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"System": runtime.GOOS,
|
"System": runtime.GOOS,
|
||||||
"DiskSpaceTotal": system.Disk.Total,
|
"AhenkVersion": string(ver),
|
||||||
"MemoryTotal": system.Memory.Total,
|
"Hostname": system.Node.Hostname,
|
||||||
// TODO "AhenkVersion": get Ahenk self version here
|
"KernelVersion": system.Kernel.Version,
|
||||||
|
"KernelRelease": system.Kernel.Release,
|
||||||
"Name": system.OS.Name,
|
"Name": system.OS.Name,
|
||||||
"Distribution": system.OS.Distro,
|
"Distribution": system.OS.Distro,
|
||||||
"Arch": system.OS.Arch,
|
"Arch": system.OS.Arch,
|
||||||
"Version": system.OS.Version,
|
"Version": system.OS.Version,
|
||||||
"Hostname": system.Node.Hostname,
|
|
||||||
"KernelVersion": system.Kernel.Version,
|
|
||||||
"KernelRelease": system.Kernel.Release,
|
|
||||||
}
|
|
||||||
|
|
||||||
// REVIEW is calling all functions one by one slow downs code?
|
"DiskSpaceTotal": system.Disk.Total,
|
||||||
// TODO see https://github.com/Pardus-LiderAhenk/ahenk/blob/master/src/plugins/resource-usage/agent_info.py
|
"MemoryTotal": system.Memory.Total,
|
||||||
return data, nil
|
}
|
||||||
|
// see https://github.com/Pardus-LiderAhenk/ahenk/blob/master/src/plugins/resource-usage/agent_info.py
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
module git.aliberksandikci.com.tr/Liderahenk/ahenk-go/plugins/tmptest
|
|
||||||
|
|
||||||
go 1.21.0
|
|
1
version
Normal file
1
version
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0.0.2
|
Loading…
Reference in a new issue