1/*
2** Zabbix
3** Copyright (C) 2001-2021 Zabbix SIA
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18**/
19
20package oracle
21
22import (
23	"zabbix.com/pkg/conf"
24	"zabbix.com/pkg/plugin"
25)
26
27type Session struct {
28	// URI defines an address of the Oracle Net Listener.
29	URI string `conf:"name=Uri,optional"`
30
31	Password string `conf:"optional"`
32
33	User string `conf:"optional"`
34
35	// Service name that identifies a database instance
36	Service string `conf:"optional"`
37}
38
39type PluginOptions struct {
40	// ConnectTimeout is the maximum time in seconds for waiting when a connection has to be established.
41	// Default value equals to the global timeout.
42	ConnectTimeout int `conf:"optional,range=1:30"`
43
44	// CallTimeout is the maximum time in seconds for waiting when a request has to be done.
45	// Default value equals to the global agent timeout.
46	CallTimeout int `conf:"optional,range=1:30"`
47
48	// KeepAlive is a time to wait before unused connections will be closed.
49	KeepAlive int `conf:"optional,range=60:900,default=300"`
50
51	// Sessions stores pre-defined named sets of connections settings.
52	Sessions map[string]Session `conf:"optional"`
53
54	// CustomQueriesPath is a full pathname of a directory containing *.sql files with custom queries.
55	CustomQueriesPath string `conf:"optional"`
56}
57
58// Configure implements the Configurator interface.
59// Initializes configuration structures.
60func (p *Plugin) Configure(global *plugin.GlobalOptions, options interface{}) {
61	if err := conf.Unmarshal(options, &p.options); err != nil {
62		p.Errf("cannot unmarshal configuration options: %s", err)
63	}
64
65	if p.options.ConnectTimeout == 0 {
66		p.options.ConnectTimeout = global.Timeout
67	}
68
69	if p.options.CallTimeout == 0 {
70		p.options.CallTimeout = global.Timeout
71	}
72}
73
74// Validate implements the Configurator interface.
75// Returns an error if validation of a plugin's configuration is failed.
76func (p *Plugin) Validate(options interface{}) error {
77	var opts PluginOptions
78
79	return conf.Unmarshal(options, &opts)
80}
81