mirror of
https://github.com/unpoller/unpoller.git
synced 2026-10-18 22:40:03 +02:00
initial
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
# MYSQL Output Plugin Example
|
||||
|
||||
The code here, and the dynamic plugin provided shows an example of how you can
|
||||
write your own output for unifi-poller. This plugin records some very basic
|
||||
data about clients on a unifi network into a mysql database.
|
||||
|
||||
You could write outputs that do... anything. An example: They could compare current
|
||||
connected clients to a previous list (in a db, or stored in memory), and send a
|
||||
notification if it changes. The possibilities are endless.
|
||||
|
||||
You must compile your plugin using the unifi-poller source for the version you're
|
||||
using. In other words, to build a plugin for version 2.0.1, do this:
|
||||
```
|
||||
mkdir -p $GOPATH/src/github.com/davidnewhall
|
||||
cd $GOPATH/src/github.com/davidnewhall
|
||||
|
||||
git clone git@github.com:davidnewhall/unifi-poller.git
|
||||
cd unifi-poller
|
||||
|
||||
git checkout v2.0.1
|
||||
make vendor
|
||||
|
||||
cp -r <your plugin> plugins/
|
||||
GOOS=linux make plugins
|
||||
```
|
||||
The plugin you copy in *must* have a `main.go` file for `make plugins` to build it.
|
||||
@@ -1,45 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/davidnewhall/unifi-poller/pkg/poller"
|
||||
"golift.io/cnfg"
|
||||
)
|
||||
|
||||
// mysqlConfig represents the data that is unmarshalled from the up.conf config file for this plugins.
|
||||
type mysqlConfig struct {
|
||||
Interval cnfg.Duration `json:"interval" toml:"interval" xml:"interval" yaml:"interval"`
|
||||
Host string `json:"host" toml:"host" xml:"host" yaml:"host"`
|
||||
User string `json:"user" toml:"user" xml:"user" yaml:"user"`
|
||||
Pass string `json:"pass" toml:"pass" xml:"pass" yaml:"pass"`
|
||||
DB string `json:"db" toml:"db" xml:"db" yaml:"db"`
|
||||
Table string `json:"table" toml:"table" xml:"table" yaml:"table"`
|
||||
// Maps do not work with ENV VARIABLES yet, but may in the future.
|
||||
Fields []string `json:"fields" toml:"fields" xml:"field" yaml:"fields"`
|
||||
}
|
||||
|
||||
// Pointers are ignored during ENV variable unmarshal, avoid pointers to your config.
|
||||
// Only capital (exported) members are unmarshaled when passed into poller.NewOutput().
|
||||
type plugin struct {
|
||||
Config mysqlConfig `json:"mysql" toml:"mysql" xml:"mysql" yaml:"mysql"`
|
||||
}
|
||||
|
||||
func init() {
|
||||
u := &plugin{Config: mysqlConfig{}}
|
||||
|
||||
poller.NewOutput(&poller.Output{
|
||||
Name: "mysql",
|
||||
Config: u, // pass in the struct *above* your config (so it can see the struct tags).
|
||||
Method: u.Run,
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("this is a unifi-poller plugin; not an application")
|
||||
}
|
||||
|
||||
func (a *plugin) Run(c poller.Collect) error {
|
||||
c.Logf("mysql plugin is not finished")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user