Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/module.h5
-rw-r--r--include/sysinfo.h1
-rw-r--r--src/go/internal/agent/client.go4
-rw-r--r--src/go/internal/agent/scheduler/client.go16
-rw-r--r--src/go/internal/agent/scheduler/manager.go14
-rw-r--r--src/go/internal/agent/scheduler/manager_test.go55
-rw-r--r--src/go/plugins/log/log.go3
-rw-r--r--src/go/plugins/windows/eventlog/eventlog_windows.go3
-rw-r--r--src/libs/zbxsysinfo/common/common.c99
-rw-r--r--src/libs/zbxsysinfo/common/common.h1
-rw-r--r--src/libs/zbxsysinfo/sysinfo.c94
11 files changed, 178 insertions, 117 deletions
diff --git a/include/module.h b/include/module.h
index 2e7194fd048..4cf6772157a 100644
--- a/include/module.h
+++ b/include/module.h
@@ -44,7 +44,6 @@
#define CF_HAVEPARAMS 0x01 /* item accepts either optional or mandatory parameters */
#define CF_MODULE 0x02 /* item is defined in a loadable module */
#define CF_USERPARAMETER 0x04 /* item is defined as user parameter */
-#define CF_HAVEFLAGS 0x08 /* item needs additional internal parameter with flags */
/* agent request structure */
typedef struct
@@ -76,10 +75,6 @@ zbx_log_t;
#define AR_MESSAGE 0x20
#define AR_META 0x40
-/* casts to item functions */
-#define PNOFLAGS int(*)(AGENT_REQUEST *, AGENT_RESULT *)
-#define PFLAGS int(*)(AGENT_REQUEST *, AGENT_RESULT *, unsigned)
-
/* agent return structure */
typedef struct
{
diff --git a/include/sysinfo.h b/include/sysinfo.h
index 0f970a7daa2..635a8421441 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -201,6 +201,7 @@ zbx_key_access_rule_type_t;
void init_metrics(void);
int add_metric(ZBX_METRIC *metric, char *error, size_t max_error_len);
+int add_metric_local(ZBX_METRIC *metric, char *error, size_t max_error_len);
void free_metrics(void);
void init_key_access_rules(void);
diff --git a/src/go/internal/agent/client.go b/src/go/internal/agent/client.go
index 139374392ff..d22d698c29e 100644
--- a/src/go/internal/agent/client.go
+++ b/src/go/internal/agent/client.go
@@ -23,9 +23,9 @@ import (
"sync/atomic"
)
-const ActiveChechksClientID = 100
+const ActiveChecksClientID = 100
-var lastClientID uint64 = ActiveChechksClientID
+var lastClientID uint64 = ActiveChecksClientID
// Internal client id assigned to each active server and unique passive bulk request.
// Single checks (internal and old style passive checks) has built-in client id 0.
diff --git a/src/go/internal/agent/scheduler/client.go b/src/go/internal/agent/scheduler/client.go
index 78ab5581e92..357a776dca5 100644
--- a/src/go/internal/agent/scheduler/client.go
+++ b/src/go/internal/agent/scheduler/client.go
@@ -118,7 +118,7 @@ func (c *client) addRequest(p *pluginAgent, r *plugin.Request, sink plugin.Resul
if _, ok := p.impl.(plugin.Exporter); ok {
var tacc exporterTaskAccessor
- if c.id > agent.ActiveChechksClientID {
+ if c.id > agent.ActiveChecksClientID {
var task *exporterTask
if _, err = zbxlib.GetNextcheck(r.Itemid, r.Delay, now, false, c.refreshUnsupported); err != nil {
@@ -201,7 +201,7 @@ func (c *client) addRequest(p *pluginAgent, r *plugin.Request, sink plugin.Resul
}
// Watcher plugins are not supported by direct requests
- if c.id != 0 {
+ if c.id > agent.ActiveChecksClientID {
// handle Watcher interface
if _, ok := p.impl.(plugin.Watcher); ok {
if info.watcher == nil {
@@ -264,10 +264,10 @@ func (c *client) cleanup(plugins map[string]*pluginAgent, now time.Time) (releas
}
var expiry time.Time
- // Direct requests are handled by special client with id 0. Such requests have
- // day+hour (to keep once per day checks without expiring) expiry time before
- // used plugins are released.
- if c.id != 0 {
+ // Direct requests are handled by special client with id <= ActiveChecksClientID.
+ // Such requests have day+hour (to keep once per day checks without expiring)
+ // expiry time before used plugins are released.
+ if c.id > agent.ActiveChecksClientID {
expiry = now
} else {
expiry = now.Add(-time.Hour * 25)
@@ -278,7 +278,7 @@ func (c *client) cleanup(plugins map[string]*pluginAgent, now time.Time) (releas
if info, ok := c.pluginsInfo[p]; ok {
if info.used.Before(expiry) {
// perform empty watch task before closing
- if c.id != 0 {
+ if c.id > agent.ActiveChecksClientID {
if _, ok := p.impl.(plugin.Watcher); ok {
task := &watcherTask{
taskBase: taskBase{plugin: p, active: true},
@@ -300,7 +300,7 @@ func (c *client) cleanup(plugins map[string]*pluginAgent, now time.Time) (releas
delete(c.pluginsInfo, p)
p.refcount--
// TODO: define uniform time format
- if c.id != 0 {
+ if c.id > agent.ActiveChecksClientID {
log.Debugf("[%d] released unused plugin %s", c.id, p.name())
} else {
log.Debugf("[%d] released plugin %s as not used since %s", c.id, p.name(),
diff --git a/src/go/internal/agent/scheduler/manager.go b/src/go/internal/agent/scheduler/manager.go
index 68d256333bb..e30f5c0cf20 100644
--- a/src/go/internal/agent/scheduler/manager.go
+++ b/src/go/internal/agent/scheduler/manager.go
@@ -63,7 +63,7 @@ type Scheduler interface {
UpdateTasks(clientID uint64, writer plugin.ResultWriter, refreshUnsupported int, expressions []*glexpr.Expression,
requests []*plugin.Request)
FinishTask(task performer)
- PerformTask(key string, timeout time.Duration, flags uint64) (result string, err error)
+ PerformTask(key string, timeout time.Duration, clientID uint64) (result string, err error)
Query(command string) (status string)
}
@@ -152,7 +152,7 @@ func (m *Manager) processUpdateRequest(update *updateRequest, now time.Time) {
}
if err != nil {
- if c.id != 0 {
+ if c.id > agent.ActiveChecksClientID {
if tacc, ok := c.exporters[r.Itemid]; ok {
log.Debugf("deactivate exporter task for item %d because of error: %s", r.Itemid, err)
tacc.task().deactivate()
@@ -407,17 +407,13 @@ func (r resultWriter) PersistSlotsAvailable() int {
return 1
}
-func (m *Manager) PerformTask(key string, timeout time.Duration, flags uint64) (result string, err error) {
+func (m *Manager) PerformTask(key string, timeout time.Duration, clientID uint64) (result string, err error) {
var lastLogsize uint64
var mtime int
- var clientId uint64
w := make(resultWriter, 1)
- clientId = 0
- if flags&0x1 != 0 {
- clientId = 1
- }
- m.UpdateTasks(clientId, w, 0, nil, []*plugin.Request{{Key: key, LastLogsize: &lastLogsize, Mtime: &mtime}})
+
+ m.UpdateTasks(clientID, w, 0, nil, []*plugin.Request{{Key: key, LastLogsize: &lastLogsize, Mtime: &mtime}})
select {
case r := <-w:
diff --git a/src/go/internal/agent/scheduler/manager_test.go b/src/go/internal/agent/scheduler/manager_test.go
index 13c6a5900d0..80abef4c90a 100644
--- a/src/go/internal/agent/scheduler/manager_test.go
+++ b/src/go/internal/agent/scheduler/manager_test.go
@@ -635,7 +635,7 @@ func TestTaskCreate(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -651,14 +651,13 @@ func TestTaskCreate(t *testing.T) {
Mtime: &mtime,
})
}
-
manager.processUpdateRequest(&update, time.Now())
if len(manager.pluginQueue) != 3 {
t.Errorf("Expected %d plugins queued while got %d", 3, len(manager.pluginQueue))
}
- checkExporterTasks(t, manager, 1, items)
+ checkExporterTasks(t, manager, agent.ActiveChecksClientID+1, items)
}
func TestTaskUpdate(t *testing.T) {
@@ -688,7 +687,7 @@ func TestTaskUpdate(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -726,7 +725,7 @@ func TestTaskUpdate(t *testing.T) {
t.Errorf("Expected %d plugins queued while got %d", 3, len(manager.pluginQueue))
}
- checkExporterTasks(t, manager, 1, items)
+ checkExporterTasks(t, manager, agent.ActiveChecksClientID+1, items)
}
func TestTaskUpdateInvalidInterval(t *testing.T) {
@@ -749,7 +748,7 @@ func TestTaskUpdateInvalidInterval(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -812,7 +811,7 @@ func TestTaskDelete(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -848,7 +847,7 @@ func TestTaskDelete(t *testing.T) {
t.Errorf("Expected %d tasks queued while got %d", 0, len(manager.plugins["debug3"].tasks))
}
- checkExporterTasks(t, manager, 1, items)
+ checkExporterTasks(t, manager, agent.ActiveChecksClientID+1, items)
}
func TestSchedule(t *testing.T) {
@@ -878,7 +877,7 @@ func TestSchedule(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -931,7 +930,7 @@ func TestScheduleCapacity(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -981,7 +980,7 @@ func TestScheduleUpdate(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1044,7 +1043,7 @@ func TestCollectorSchedule(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1093,7 +1092,7 @@ func TestCollectorScheduleUpdate(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1166,7 +1165,7 @@ func TestRunner(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1276,7 +1275,7 @@ func TestWatcher(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1364,7 +1363,7 @@ func TestCollectorExporterSchedule(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1417,7 +1416,7 @@ func TestRunnerWatcher(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1504,7 +1503,7 @@ func TestMultiCollectorExporterSchedule(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1521,7 +1520,7 @@ func TestMultiCollectorExporterSchedule(t *testing.T) {
})
}
manager.update(&update)
- update.clientID = 2
+ update.clientID = agent.ActiveChecksClientID + 2
manager.update(&update)
manager.mockTasks()
manager.iterate(t, 5)
@@ -1533,7 +1532,7 @@ func TestMultiCollectorExporterSchedule(t *testing.T) {
manager.iterate(t, 5)
manager.checkPluginTimeline(t, plugins, calls, 5)
- update.clientID = 1
+ update.clientID = agent.ActiveChecksClientID + 1
manager.update(&update)
manager.mockTasks()
manager.iterate(t, 5)
@@ -1564,7 +1563,7 @@ func TestMultiRunnerWatcher(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
@@ -1581,35 +1580,35 @@ func TestMultiRunnerWatcher(t *testing.T) {
})
}
manager.update(&update)
- update.clientID = 2
+ update.clientID = agent.ActiveChecksClientID + 2
manager.update(&update)
manager.mockTasks()
manager.iterate(t, 5)
manager.checkPluginTimeline(t, plugins, calls, 5)
- update.clientID = 1
+ update.clientID = agent.ActiveChecksClientID + 1
manager.update(&update)
- update.clientID = 2
+ update.clientID = agent.ActiveChecksClientID + 2
update.requests = update.requests[:0]
manager.update(&update)
manager.mockTasks()
manager.iterate(t, 5)
manager.checkPluginTimeline(t, plugins, calls, 5)
- update.clientID = 1
+ update.clientID = agent.ActiveChecksClientID + 1
manager.update(&update)
manager.mockTasks()
manager.iterate(t, 5)
manager.checkPluginTimeline(t, plugins, calls, 5)
update.requests = update.requests[:1]
- update.clientID = 2
+ update.clientID = agent.ActiveChecksClientID + 2
manager.update(&update)
manager.mockTasks()
manager.iterate(t, 5)
manager.checkPluginTimeline(t, plugins, calls, 5)
- update.clientID = 1
+ update.clientID = agent.ActiveChecksClientID + 1
manager.update(&update)
manager.mockTasks()
manager.iterate(t, 5)
@@ -1734,7 +1733,7 @@ func TestConfigurator(t *testing.T) {
var cache resultCacheMock
update := updateRequest{
- clientID: 1,
+ clientID: agent.ActiveChecksClientID + 1,
sink: &cache,
requests: make([]*plugin.Request, 0),
}
diff --git a/src/go/plugins/log/log.go b/src/go/plugins/log/log.go
index fb6a344bddb..1c3fc2e585e 100644
--- a/src/go/plugins/log/log.go
+++ b/src/go/plugins/log/log.go
@@ -25,6 +25,7 @@ import (
"time"
"unsafe"
+ "zabbix.com/internal/agent"
"zabbix.com/pkg/conf"
"zabbix.com/pkg/glexpr"
"zabbix.com/pkg/itemutil"
@@ -63,7 +64,7 @@ type metadata struct {
}
func (p *Plugin) Export(key string, params []string, ctx plugin.ContextProvider) (result interface{}, err error) {
- if ctx == nil || ctx.ClientID() == 0 {
+ if ctx == nil || ctx.ClientID() <= agent.ActiveChecksClientID {
return nil, fmt.Errorf(`The "%s" key is not supported in test or single passive check mode`, key)
}
meta := ctx.Meta()
diff --git a/src/go/plugins/windows/eventlog/eventlog_windows.go b/src/go/plugins/windows/eventlog/eventlog_windows.go
index aed9f2b1efc..95a6b248b1a 100644
--- a/src/go/plugins/windows/eventlog/eventlog_windows.go
+++ b/src/go/plugins/windows/eventlog/eventlog_windows.go
@@ -25,6 +25,7 @@ import (
"time"
"unsafe"
+ "zabbix.com/internal/agent"
"zabbix.com/pkg/conf"
"zabbix.com/pkg/glexpr"
"zabbix.com/pkg/itemutil"
@@ -63,7 +64,7 @@ func (p *Plugin) Validate(options interface{}) error {
}
func (p *Plugin) Export(key string, params []string, ctx plugin.ContextProvider) (result interface{}, err error) {
- if ctx == nil || ctx.ClientID() == 0 {
+ if ctx == nil || ctx.ClientID() <= agent.ActiveChecksClientID {
return nil, fmt.Errorf(`The "%s" key is not supported in test or single passive check mode`, key)
}
meta := ctx.Meta()
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index 9fa090f098f..62e2c63574f 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -43,45 +43,53 @@
extern int CONFIG_TIMEOUT;
static int ONLY_ACTIVE(AGENT_REQUEST *request, AGENT_RESULT *result);
-static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result, unsigned flags);
+static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result);
+static int SYSTEM_RUN_LOCAL(AGENT_REQUEST *request, AGENT_RESULT *result);
+
+ZBX_METRIC parameters_common_local[] =
+/* KEY FLAG FUNCTION TEST PARAMETERS */
+{
+ {"system.run", CF_HAVEPARAMS, SYSTEM_RUN_LOCAL, "echo test"},
+ {NULL}
+};
ZBX_METRIC parameters_common[] =
-/* KEY FLAG FUNCTION TEST PARAMETERS */
+/* KEY FLAG FUNCTION TEST PARAMETERS */
{
- {"system.localtime", CF_HAVEPARAMS, SYSTEM_LOCALTIME, "utc"},
- {"system.run", CF_HAVEPARAMS|CF_HAVEFLAGS, (PNOFLAGS)SYSTEM_RUN, "echo test"},
+ {"system.localtime", CF_HAVEPARAMS, SYSTEM_LOCALTIME, "utc"},
+ {"system.run", CF_HAVEPARAMS, SYSTEM_RUN, "echo test"},
- {"web.page.get", CF_HAVEPARAMS, WEB_PAGE_GET, "localhost,,80"},
- {"web.page.perf", CF_HAVEPARAMS, WEB_PAGE_PERF, "localhost,,80"},
- {"web.page.regexp", CF_HAVEPARAMS, WEB_PAGE_REGEXP, "localhost,,80,OK"},
+ {"web.page.get", CF_HAVEPARAMS, WEB_PAGE_GET, "localhost,,80"},
+ {"web.page.perf", CF_HAVEPARAMS, WEB_PAGE_PERF, "localhost,,80"},
+ {"web.page.regexp", CF_HAVEPARAMS, WEB_PAGE_REGEXP, "localhost,,80,OK"},
- {"vfs.file.size", CF_HAVEPARAMS, VFS_FILE_SIZE, VFS_TEST_FILE},
- {"vfs.file.time", CF_HAVEPARAMS, VFS_FILE_TIME, VFS_TEST_FILE ",modify"},
- {"vfs.file.exists", CF_HAVEPARAMS, VFS_FILE_EXISTS, VFS_TEST_FILE},
- {"vfs.file.contents", CF_HAVEPARAMS, VFS_FILE_CONTENTS, VFS_TEST_FILE},
- {"vfs.file.regexp", CF_HAVEPARAMS, VFS_FILE_REGEXP, VFS_TEST_FILE "," VFS_TEST_REGEXP},
- {"vfs.file.regmatch", CF_HAVEPARAMS, VFS_FILE_REGMATCH, VFS_TEST_FILE "," VFS_TEST_REGEXP},
- {"vfs.file.md5sum", CF_HAVEPARAMS, VFS_FILE_MD5SUM, VFS_TEST_FILE},
- {"vfs.file.cksum", CF_HAVEPARAMS, VFS_FILE_CKSUM, VFS_TEST_FILE},
+ {"vfs.file.size", CF_HAVEPARAMS, VFS_FILE_SIZE, VFS_TEST_FILE},
+ {"vfs.file.time", CF_HAVEPARAMS, VFS_FILE_TIME, VFS_TEST_FILE ",modify"},
+ {"vfs.file.exists", CF_HAVEPARAMS, VFS_FILE_EXISTS, VFS_TEST_FILE},
+ {"vfs.file.contents", CF_HAVEPARAMS, VFS_FILE_CONTENTS, VFS_TEST_FILE},
+ {"vfs.file.regexp", CF_HAVEPARAMS, VFS_FILE_REGEXP, VFS_TEST_FILE "," VFS_TEST_REGEXP},
+ {"vfs.file.regmatch", CF_HAVEPARAMS, VFS_FILE_REGMATCH, VFS_TEST_FILE "," VFS_TEST_REGEXP},
+ {"vfs.file.md5sum", CF_HAVEPARAMS, VFS_FILE_MD5SUM, VFS_TEST_FILE},
+ {"vfs.file.cksum", CF_HAVEPARAMS, VFS_FILE_CKSUM, VFS_TEST_FILE},
- {"vfs.dir.size", CF_HAVEPARAMS, VFS_DIR_SIZE, VFS_TEST_DIR},
- {"vfs.dir.count", CF_HAVEPARAMS, VFS_DIR_COUNT, VFS_TEST_DIR},
+ {"vfs.dir.size", CF_HAVEPARAMS, VFS_DIR_SIZE, VFS_TEST_DIR},
+ {"vfs.dir.count", CF_HAVEPARAMS, VFS_DIR_COUNT, VFS_TEST_DIR},
- {"net.dns", CF_HAVEPARAMS, NET_DNS, ",zabbix.com"},
- {"net.dns.record", CF_HAVEPARAMS, NET_DNS_RECORD, ",zabbix.com"},
- {"net.tcp.dns", CF_HAVEPARAMS, NET_DNS, ",zabbix.com"}, /* deprecated */
- {"net.tcp.dns.query", CF_HAVEPARAMS, NET_DNS_RECORD, ",zabbix.com"}, /* deprecated */
- {"net.tcp.port", CF_HAVEPARAMS, NET_TCP_PORT, ",80"},
+ {"net.dns", CF_HAVEPARAMS, NET_DNS, ",zabbix.com"},
+ {"net.dns.record", CF_HAVEPARAMS, NET_DNS_RECORD, ",zabbix.com"},
+ {"net.tcp.dns", CF_HAVEPARAMS, NET_DNS, ",zabbix.com"}, /* deprecated */
+ {"net.tcp.dns.query", CF_HAVEPARAMS, NET_DNS_RECORD, ",zabbix.com"}, /* deprecated */
+ {"net.tcp.port", CF_HAVEPARAMS, NET_TCP_PORT, ",80"},
- {"system.users.num", 0, SYSTEM_USERS_NUM, NULL},
+ {"system.users.num", 0, SYSTEM_USERS_NUM, NULL},
- {"log", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
- {"log.count", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
- {"logrt", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
- {"logrt.count", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
- {"eventlog", CF_HAVEPARAMS, ONLY_ACTIVE, "system"},
+ {"log", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
+ {"log.count", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
+ {"logrt", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
+ {"logrt.count", CF_HAVEPARAMS, ONLY_ACTIVE, "logfile"},
+ {"eventlog", CF_HAVEPARAMS, ONLY_ACTIVE, "system"},
- {"zabbix.stats", CF_HAVEPARAMS, ZABBIX_STATS, "127.0.0.1,10051"},
+ {"zabbix.stats", CF_HAVEPARAMS, ZABBIX_STATS, "127.0.0.1,10051"},
{NULL}
};
@@ -170,7 +178,7 @@ int EXECUTE_INT(const char *command, AGENT_RESULT *result)
return SYSINFO_RET_OK;
}
-static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result, unsigned flags)
+static int system_run(AGENT_REQUEST *request, AGENT_RESULT *result, int level)
{
char *command, *flag;
@@ -189,11 +197,7 @@ static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result, unsigned fla
return SYSINFO_RET_FAIL;
}
- if (2 == CONFIG_LOG_REMOTE_COMMANDS ||
- (1 == CONFIG_LOG_REMOTE_COMMANDS && 0 == (flags & PROCESS_LOCAL_COMMAND)) )
- zabbix_log(LOG_LEVEL_WARNING, "Executing command '%s'", command);
- else
- zabbix_log(LOG_LEVEL_DEBUG, "Executing command '%s'", command);
+ zabbix_log(level, "Executing command '%s'", command);
if (NULL == flag || '\0' == *flag || 0 == strcmp(flag, "wait")) /* default parameter */
{
@@ -217,3 +221,28 @@ static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result, unsigned fla
return SYSINFO_RET_OK;
}
+
+static int SYSTEM_RUN(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ int level;
+
+ level = LOG_LEVEL_DEBUG;
+
+ if (0 != CONFIG_LOG_REMOTE_COMMANDS)
+ level = LOG_LEVEL_WARNING;
+
+ return system_run(request, result, level);
+}
+
+static int SYSTEM_RUN_LOCAL(AGENT_REQUEST *request, AGENT_RESULT *result)
+{
+ int level;
+
+ level = LOG_LEVEL_DEBUG;
+
+ if (2 == CONFIG_LOG_REMOTE_COMMANDS)
+ level = LOG_LEVEL_WARNING;
+
+ return system_run(request, result, level);
+}
+
diff --git a/src/libs/zbxsysinfo/common/common.h b/src/libs/zbxsysinfo/common/common.h
index 3d083099d27..5bf392c63f4 100644
--- a/src/libs/zbxsysinfo/common/common.h
+++ b/src/libs/zbxsysinfo/common/common.h
@@ -23,6 +23,7 @@
#include "sysinfo.h"
extern ZBX_METRIC parameters_common[];
+extern ZBX_METRIC parameters_common_local[];
int EXECUTE_USER_PARAMETER(AGENT_REQUEST *request, AGENT_RESULT *result);
int EXECUTE_STR(const char *command, AGENT_RESULT *result);
diff --git a/src/libs/zbxsysinfo/sysinfo.c b/src/libs/zbxsysinfo/sysinfo.c
index 3c550c805a0..5afdac3d09a 100644
--- a/src/libs/zbxsysinfo/sysinfo.c
+++ b/src/libs/zbxsysinfo/sysinfo.c
@@ -57,6 +57,7 @@ extern ZBX_METRIC parameter_hostname;
#endif
static ZBX_METRIC *commands = NULL;
+static ZBX_METRIC *commands_local = NULL;
zbx_vector_ptr_t key_access_rules;
#define ZBX_COMMAND_ERROR 0
@@ -105,20 +106,14 @@ static int parse_command_dyn(const char *command, char **cmd, char **param)
return ZBX_COMMAND_WITH_PARAMS;
}
-/******************************************************************************
- * *
- * Function: add_metric *
- * *
- * Purpose: registers a new item key into the system *
- * *
- ******************************************************************************/
-int add_metric(ZBX_METRIC *metric, char *error, size_t max_error_len)
+
+static int add_to_metrics(ZBX_METRIC **metrics, ZBX_METRIC *metric, char *error, size_t max_error_len)
{
- int i = 0;
+ int i = 0;
- while (NULL != commands[i].key)
+ while (NULL != (*metrics)[i].key)
{
- if (0 == strcmp(commands[i].key, metric->key))
+ if (0 == strcmp((*metrics)[i].key, metric->key))
{
zbx_snprintf(error, max_error_len, "key \"%s\" already exists", metric->key);
return FAIL; /* metric already exists */
@@ -126,17 +121,41 @@ int add_metric(ZBX_METRIC *metric, char *error, size_t max_error_len)
i++;
}
- commands[i].key = zbx_strdup(NULL, metric->key);
- commands[i].flags = metric->flags;
- commands[i].function = metric->function;
- commands[i].test_param = (NULL == metric->test_param ? NULL : zbx_strdup(NULL, metric->test_param));
+ (*metrics)[i].key = zbx_strdup(NULL, metric->key);
+ (*metrics)[i].flags = metric->flags;
+ (*metrics)[i].function = metric->function;
+ (*metrics)[i].test_param = (NULL == metric->test_param ? NULL : zbx_strdup(NULL, metric->test_param));
- commands = (ZBX_METRIC *)zbx_realloc(commands, (i + 2) * sizeof(ZBX_METRIC));
- memset(&commands[i + 1], 0, sizeof(ZBX_METRIC));
+ (*metrics) = (ZBX_METRIC *)zbx_realloc((*metrics), (i + 2) * sizeof(ZBX_METRIC));
+ memset(&(*metrics)[i + 1], 0, sizeof(ZBX_METRIC));
return SUCCEED;
}
+/******************************************************************************
+ * *
+ * Function: add_metric *
+ * *
+ * Purpose: registers a new item key into the system *
+ * *
+ ******************************************************************************/
+int add_metric(ZBX_METRIC *metric, char *error, size_t max_error_len)
+{
+ return add_to_metrics(&commands, metric, error, max_error_len);
+}
+
+/******************************************************************************
+ * *
+ * Function: add_metric_local *
+ * *
+ * Purpose: registers a new item key as local into the system *
+ * *
+ ******************************************************************************/
+int add_metric_local(ZBX_METRIC *metric, char *error, size_t max_error_len)
+{
+ return add_to_metrics(&commands_local, metric, error, max_error_len);
+}
+
#if !defined(__MINGW32__)
int add_user_parameter(const char *itemkey, char *command, char *error, size_t max_error_len)
{
@@ -162,7 +181,7 @@ int add_user_parameter(const char *itemkey, char *command, char *error, size_t m
metric.function = &EXECUTE_USER_PARAMETER;
metric.test_param = command;
- ret = add_metric(&metric, error, max_error_len);
+ ret = add_metric( &metric, error, max_error_len);
}
else
zbx_strlcpy(error, "syntax error", max_error_len);
@@ -182,6 +201,8 @@ void init_metrics(void)
commands = (ZBX_METRIC *)zbx_malloc(commands, sizeof(ZBX_METRIC));
commands[0].key = NULL;
+ commands_local = (ZBX_METRIC *)zbx_malloc(commands_local, sizeof(ZBX_METRIC));
+ commands_local[0].key = NULL;
#ifdef WITH_AGENT_METRICS
for (i = 0; NULL != parameters_agent[i].key; i++)
@@ -203,6 +224,15 @@ void init_metrics(void)
exit(EXIT_FAILURE);
}
}
+
+ for (i = 0; NULL != parameters_common_local[i].key; i++)
+ {
+ if (SUCCEED != add_metric_local( &parameters_common_local[i], error, sizeof(error)))
+ {
+ zabbix_log(LOG_LEVEL_CRIT, "cannot add item key: %s", error);
+ exit(EXIT_FAILURE);
+ }
+ }
#endif
#ifdef WITH_SPECIFIC_METRICS
@@ -972,7 +1002,7 @@ static int replace_param(const char *cmd, const AGENT_REQUEST *request, char **o
******************************************************************************/
int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
{
- int ret = NOTSUPPORTED, rc;
+ int ret = NOTSUPPORTED;
ZBX_METRIC *command = NULL;
AGENT_REQUEST request;
@@ -1000,10 +1030,23 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
goto notsupported;
}
- for (command = commands; NULL != command->key; command++)
+ if (0 != (flags & PROCESS_LOCAL_COMMAND))
{
- if (0 == strcmp(command->key, request.key))
- break;
+ for (command = commands_local; NULL != command->key; command++)
+ {
+ if (0 == strcmp(command->key, request.key))
+ break;
+ }
+
+ }
+
+ if (NULL == command || NULL == command->key)
+ {
+ for (command = commands; NULL != command->key; command++)
+ {
+ if (0 == strcmp(command->key, request.key))
+ break;
+ }
}
/* item key not found */
@@ -1049,12 +1092,7 @@ int process(const char *in_command, unsigned flags, AGENT_RESULT *result)
}
}
- if (0 != (command->flags & CF_HAVEFLAGS))
- rc = ((PFLAGS)command->function)(&request, result, flags);
- else
- rc = command->function(&request, result);
-
- if (SYSINFO_RET_OK != rc)
+ if (SYSINFO_RET_OK != command->function(&request, result))
{
/* "return NOTSUPPORTED;" would be more appropriate here for preserving original error */
/* message in "result" but would break things relying on ZBX_NOTSUPPORTED message. */