Skip to content

Commit

Permalink
CHANGES: snmpd: Add -cacheTime and -execType flags to "extend" config…
Browse files Browse the repository at this point in the history
… directive

Add the following two flags to the "extend" config directive:
-cacheTime specifies the cache timeout.
-execType specifies the execution type (sh or exec).

This enables non-volatile configuration of two aspects that
so far have been configurable only temporarily via SETs.

See also https://sourceforge.net/p/net-snmp/patches/1290/.
  • Loading branch information
Jeff Gehlbach authored and bvanassche committed Jul 20, 2016
1 parent 32cc6c3 commit d8b1290
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
27 changes: 25 additions & 2 deletions agent/mibgroup/agent/extend.c
Expand Up @@ -522,8 +522,28 @@ extend_parse_config(const char *token, char *cptr)
size_t oid_len;
extend_registration_block *eptr;
int flags;
int cache_timeout = 0;
int exec_type = NS_EXTEND_ETYPE_EXEC;

cptr = copy_nword(cptr, exec_name, sizeof(exec_name));
cptr = copy_nword(cptr, exec_name, sizeof(exec_name));
if (strcmp(exec_name, "-cacheTime") == 0) {
char cache_timeout_str[32];

cptr = copy_nword(cptr, cache_timeout_str, sizeof(cache_timeout_str));
/* If atoi can't do the conversion, it returns 0 */
cache_timeout = atoi(cache_timeout_str);
cptr = copy_nword(cptr, exec_name, sizeof(exec_name));
}
if (strcmp(exec_name, "-execType") == 0) {
char exec_type_str[16];

cptr = copy_nword(cptr, exec_type_str, sizeof(exec_type_str));
if (strcmp(exec_type_str, "sh") == 0)
exec_type = NS_EXTEND_ETYPE_SHELL;
else
exec_type = NS_EXTEND_ETYPE_EXEC;
cptr = copy_nword(cptr, exec_name, sizeof(exec_name));
}
if ( *exec_name == '.' ) {
oid_len = MAX_OID_LEN - 2;
if (0 == read_objid( exec_name, oid_buf, &oid_len )) {
Expand All @@ -545,7 +565,8 @@ extend_parse_config(const char *token, char *cptr)
flags = (NS_EXTEND_FLAGS_ACTIVE | NS_EXTEND_FLAGS_CONFIG);
if (!strcmp( token, "sh" ) ||
!strcmp( token, "extend-sh" ) ||
!strcmp( token, "sh2" ))
!strcmp( token, "sh2") ||
exec_type == NS_EXTEND_ETYPE_SHELL)
flags |= NS_EXTEND_FLAGS_SHELL;
if (!strcmp( token, "execFix" ) ||
!strcmp( token, "extendfix" ) ||
Expand All @@ -566,6 +587,8 @@ extend_parse_config(const char *token, char *cptr)
extension->command = strdup( exec_command );
if (cptr)
extension->args = strdup( cptr );
if (cache_timeout != 0)
extension->cache->timeout = cache_timeout;
} else {
snmp_log(LOG_ERR, "Failed to register extend entry '%s' - possibly duplicate name.\n", exec_name );
return;
Expand Down
10 changes: 9 additions & 1 deletion man/snmpd.conf.5.def
Expand Up @@ -1284,7 +1284,7 @@ Attempting to define an unaccompanied \fIexecfix\fR directive will fail.
.PP
\fIexec\fR and \fIsh\fR extensions can only be configured via the
snmpd.conf file. They cannot be set up via SNMP SET requests.
.IP "extend [MIBOID] NAME PROG ARGS"
.IP "extend [-cacheTime TIME] [-execType TYPE] [MIBOID] NAME PROG ARGS"
works in a similar manner to the \fIexec\fR directive, but with a number
of improvements. The MIB tables (\fInsExtendConfigTable\fR
etc) are indexed by the NAME token, so are unaffected by the order in
Expand All @@ -1294,6 +1294,14 @@ containing the exit status, the first line and full output (as a single string)
for each \fIextend\fR entry, and the other (\fInsExtendOutput2Table\fR)
containing the complete output as a series of separate lines.
.IP
If -cacheTime is specified, then its argument is used as the cache timeout
(in whole seconds) for this \fIextend\fR entry. This mechanism provides a
non-volatile way to specify the cache timeout.
.IP
If -execType is specified and has a value of \fIsh\fR, then this \fIextend\fR
entry will be run in a shell. Otherwise it will be run in the default \fIexec\fR
fashion. This mechanism provides a non-volatile way to specify the exec type.
.IP
If MIBOID is specified, then the configuration and result tables will be rooted
at this point in the OID tree, but are otherwise structured in exactly
the same way. This means that several separate \fIextend\fR
Expand Down

0 comments on commit d8b1290

Please sign in to comment.