Skip to content

Commit

Permalink
mod_sonic: assume default polling-interval (20) if not in config
Browse files Browse the repository at this point in the history
  • Loading branch information
sflow committed Aug 20, 2019
1 parent cab7079 commit 10b2f32
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Linux/hsflowconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,12 @@ extern "C" {
UTStrBuf_printf(buf, "polling.%s=%u\n", appSettings->application, appSettings->polling_secs);
}
}
// agentIP can ovrride the config file here if set, but otherwise print the address we selected
// agentIP can override the config file here if set, but otherwise print the address we selected
// TODO: should avoid writing in previously set agentIP or agentDevice. Should only write that in
// if it was an override. In installSFlowSettings we have to be careful to detect that a new config
// was submitted but still print the agentIP and agent lines to /etc/hsflowd.auto. Before doing that
// however, we have to check for any change to agentIP, agent or agentCIDR, and if so run the
// selectAgentAddress election again to pick an agentIP.
SFLAddress agIP = settings->agentIP.type ? settings->agentIP : sp->agentIP;
char ipbuf[51];
UTStrBuf_printf(buf, "agentIP=%s\n", SFLAddress_print(&agIP, ipbuf, 50));
Expand Down
4 changes: 4 additions & 0 deletions src/Linux/hsflowd.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ extern "C" {
if(sp->sFlowSettings_str) fputs(sp->sFlowSettings_str, sp->f_out);
// repeat the revision number. The reader knows that if the revison number
// has not changed under his feet then he has a consistent config.

// TODO: if settings did not override agentIP, print here
// TODO: if settings did not override agent (device), print here

fprintf(sp->f_out, "rev_end=%u\n", sp->revisionNo);
fflush(sp->f_out);
// chop off anything that may be lingering from before
Expand Down
28 changes: 25 additions & 3 deletions src/Linux/mod_sonic.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern "C" {
#define HSP_SONIC_FIELD_COLLECTOR_IP "collector_ip"
#define HSP_SONIC_FIELD_COLLECTOR_PORT "collector_port"

#define HSP_SONIC_DEFAULT_POLLING_INTERVAL 20
#define HSP_SONIC_MIN_POLLING_INTERVAL 5

#define HSP_MAX_EXEC_LINELEN 1024
Expand Down Expand Up @@ -886,6 +887,10 @@ extern "C" {
myDebug(1, "sonic getSflowGlobalCB: reply=%s", db_replyStr(reply, db->replyBuf, YES));
if(reply == NULL)
return;
// first extract the latest settings
bool sflow_enable = NO;
char *sflow_agent = NULL;
uint32_t sflow_polling = HSP_SONIC_DEFAULT_POLLING_INTERVAL;;
if(reply->type == REDIS_REPLY_ARRAY
&& reply->elements > 0
&& ISEVEN(reply->elements)) {
Expand All @@ -896,16 +901,33 @@ extern "C" {
myDebug(1, "sonic sflow: %s=%s", f_name->str, db_replyStr(f_val, db->replyBuf, YES));

if(my_strequal(f_name->str, HSP_SONIC_FIELD_SFLOW_ADMIN_STATE))
mdata->sflow_enable = my_strequal(f_val->str, "enable");
sflow_enable = my_strequal(f_val->str, "enable");

if(my_strequal(f_name->str, HSP_SONIC_FIELD_SFLOW_AGENT))
mdata->sflow_agent = my_strdup(f_val->str);
sflow_agent = f_val->str;

if(my_strequal(f_name->str, HSP_SONIC_FIELD_SFLOW_POLLING))
mdata->sflow_polling = db_getU32(f_val);
sflow_polling = db_getU32(f_val);
}
}
}
// now see if there are any changes.
if(sflow_enable != mdata->sflow_enable) {
myDebug(1, "sonic sflow_enable %u -> %u", mdata->sflow_enable, sflow_enable);
mdata->sflow_enable = sflow_enable;
}
// The sflow_agent entry will disappear if it is deleted from the config, so sflow_agent
// may still be NULL here:
if(!my_strequal(sflow_agent, mdata->sflow_agent)) {
myDebug(1, "sonic sflow_agent %s -> %s",
mdata->sflow_agent ?: "<not set>",
sflow_agent ?: "<not set>");
setStr(&mdata->sflow_agent, sflow_agent);
}
if(sflow_polling != mdata->sflow_polling) {
myDebug(1, "sonic sflow_polling %u -> %u", mdata->sflow_polling, sflow_polling);
mdata->sflow_polling = sflow_polling;
}
// if this is normal startup then don't syncConfig yet (that happens when the collectors
// have been discovered for the first time). However if it was a dynamic reconfig then go
// ahead and syncConfig right away...
Expand Down

0 comments on commit 10b2f32

Please sign in to comment.