package plugin import ( "golang.zabbix.com/sdk/errs" "golang.zabbix.com/sdk/metric" "golang.zabbix.com/sdk/plugin" "golang.zabbix.com/sdk/plugin/container" "onvif-agent/config" "onvif-agent/integration/zabbixagent/plugin/handler" ) var ( Name = config.Conf.Integrations.ZabbixAgent.Plugin.Name ) type onvifMetricKey string type onvifMetric struct { metric *metric.Metric handler handler.HandlerFunc } type onvifPlugin struct { plugin.Base metrics map[onvifMetricKey]*onvifMetric } // Launch launches the plugin. Blocks until plugin execution has finished. func Launch() error { p := &onvifPlugin{} err := p.registerMetrics() if err != nil { return err } h, err := container.NewHandler(Name) if err != nil { return errs.Wrap(err, "failed to create new handler") } p.Logger = &h err = h.Execute() if err != nil { return errs.Wrap(err, "failed to execute plugin handler") } return nil } // Start starts the example plugin. Is required for plugin to match runner interface. func (p *onvifPlugin) Start() { p.Logger.Infof("Start called") } // Stop stops the example plugin. Is required for plugin to match runner interface. func (p *onvifPlugin) Stop() { p.Logger.Infof("Stop called") } func (p *onvifPlugin) registerMetrics() error { //h := handler.New() p.metrics = map[onvifMetricKey]*onvifMetric{ //myIPMetric: { // metric: metric.New( // "Returns the availability groups.", // params.Params, // false, // ), // handler: handler.WithJSONResponse( // handler.WithCredentialValidation( // h.MyIP, // ), // ), //}, //goEnvMetric: { // metric: metric.New( // "Returns the result rows of a custom query.", // params.Params, // true, // ), // handler: handler.WithJSONResponse( // handler.WithCredentialValidation(handler.GoEnvironment), // ), //}, } metricSet := metric.MetricSet{} for k, m := range p.metrics { metricSet[string(k)] = m.metric } err := plugin.RegisterMetrics(p, Name, metricSet.List()...) if err != nil { return errs.Wrap(err, "failed to register metrics") } return nil }