plugin feature enhancements
- Added tmptest plugin for temporary testing - added plugin info to `checkPlugin()` function - added paramaters to `PluginManager`
This commit is contained in:
parent
92dc390be6
commit
b4ed8b4af6
7 changed files with 65 additions and 10 deletions
1
Makefile
1
Makefile
|
@ -45,6 +45,7 @@ install:
|
|||
@sudo mkdir -p "${DESTDIR}/${PLUGIN_DIR}"
|
||||
|
||||
sudo go build -buildmode=plugin -o ${DESTDIR}/${PLUGIN_DIR}/resources.so ./plugins/resources
|
||||
sudo go build -buildmode=plugin -o ${DESTDIR}/${PLUGIN_DIR}/tmptest.so ./plugins/tmptest
|
||||
@sudo mkdir -p "${DESTDIR}/${DATA_DIR}"
|
||||
|
||||
uninstall:
|
||||
|
|
|
@ -55,8 +55,11 @@ func main() {
|
|||
f := utils.OpenLogFile(LogFile)
|
||||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
// TODO Also pipe fmt.Print* commands
|
||||
|
||||
case "tmptest":
|
||||
log.Print("TEMPORARY TEST STARTED, log files are NOT redirecting!")
|
||||
PluginManager("tmptest")
|
||||
}
|
||||
} else {
|
||||
panic("Please enter a valid option !")
|
||||
|
|
|
@ -1,32 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
// General Functions/Methods that each plugin has
|
||||
type PlugGeneral interface {
|
||||
Info() map[string]string
|
||||
}
|
||||
|
||||
// plugins/resources
|
||||
type Resources interface {
|
||||
AgentInfo() map[string]interface{}
|
||||
}
|
||||
|
||||
// FILLME creating new plugin interface template
|
||||
// plugins/resources
|
||||
type TmpTest interface {
|
||||
TmpTest()
|
||||
}
|
||||
|
||||
// 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() {
|
||||
func PluginManager(params ...string) {
|
||||
chanPlug := make(chan interface{})
|
||||
|
||||
go LoadPlugin("resources", chanPlug)
|
||||
res, ok := <-chanPlug
|
||||
var resources Resources = res.(Resources)
|
||||
checkPlugin(res, ok)
|
||||
checkPlugin(resources, ok)
|
||||
|
||||
// FILLME Loading new plugin template
|
||||
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)
|
||||
|
@ -36,7 +53,7 @@ func PluginManager() {
|
|||
for {
|
||||
go logPlugin("AgentInfo", resources.AgentInfo())
|
||||
|
||||
// FILLME Running/Logout a plugin template
|
||||
// FILLME Running/Log out a plugin, template
|
||||
// go logPlugin("InfoAboutFunction", pluginName.Function() )
|
||||
|
||||
time.Sleep(30 * time.Second)
|
||||
|
@ -45,9 +62,9 @@ func PluginManager() {
|
|||
|
||||
// Logs plugin outputs.
|
||||
func logPlugin(title string, mp map[string]interface{}) {
|
||||
fmt.Printf("\n----- %v -----\n", title)
|
||||
log.Printf("\n----- %v -----\n", title)
|
||||
for i, v := range mp {
|
||||
fmt.Printf("%v: %v\n", i, v)
|
||||
log.Printf("%v: %v\n", i, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,7 +74,8 @@ func checkPlugin(plugVal interface{}, status bool) {
|
|||
if plugVal == nil {
|
||||
log.Fatal("Plugin loaded but there is no value!")
|
||||
} else {
|
||||
log.Println("Plugin loaded and ready to use")
|
||||
plugInfo := plugVal.(PlugGeneral).Info()
|
||||
log.Printf("Plugin \"%v\" loaded and ready to use, version \"%v\" ", plugInfo["name"], plugInfo["version"])
|
||||
}
|
||||
} else {
|
||||
if plugVal == nil {
|
||||
|
|
1
go.mod
1
go.mod
|
@ -10,6 +10,7 @@ require (
|
|||
require (
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.3 // indirect
|
||||
github.com/zcalusic/sysinfo v1.0.1 // indirect
|
||||
golang.org/x/text v0.12.0 // indirect
|
||||
)
|
||||
|
||||
|
|
2
go.sum
2
go.sum
|
@ -31,6 +31,8 @@ github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7Am
|
|||
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
|
||||
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/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
|
||||
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
|
@ -65,7 +65,7 @@ func (p plug) AgentInfo() map[string]interface{} {
|
|||
return data
|
||||
}
|
||||
|
||||
func Info() map[string]string {
|
||||
func (p plug) Info() map[string]string {
|
||||
inf := make(map[string]string)
|
||||
inf["name"] = "resources"
|
||||
inf["version"] = "0.0.2"
|
||||
|
|
30
plugins/tmptest/main.go
Normal file
30
plugins/tmptest/main.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/zcalusic/sysinfo"
|
||||
)
|
||||
|
||||
type plug string
|
||||
|
||||
// exported plugin Symbol
|
||||
var TmptestConnect plug
|
||||
|
||||
func (p plug) TmpTest() {
|
||||
var si sysinfo.SysInfo
|
||||
|
||||
si.GetSysInfo()
|
||||
|
||||
log.Println(si)
|
||||
}
|
||||
|
||||
func (p plug) Info() map[string]string {
|
||||
inf := make(map[string]string)
|
||||
inf["name"] = "tmptest"
|
||||
inf["version"] = "0.0.1"
|
||||
inf["support"] = "debian"
|
||||
inf["description"] = "Temporary testing"
|
||||
inf["developer"] = "asandikci@aliberksandikci.com.tr"
|
||||
return inf
|
||||
}
|
Loading…
Reference in a new issue