static int global_zone_maint_stats = 1;
static int global_resolver_stats = 0;
static int global_memory_stats = 1;
+static int timeout = -1;
static cb_view_t *views = NULL;
static size_t views_num = 0;
if (type_instance) {
sstrncpy(vl.type_instance, type_instance,
sizeof(vl.type_instance));
- replace_special (vl.plugin_instance, sizeof (vl.plugin_instance));
+ replace_special (vl.type_instance, sizeof (vl.type_instance));
}
plugin_dispatch_values(&vl);
} /* }}} void submit */
{
ERROR ("bind plugin: Parsing string \"%s\" to derive value failed.",
str_ptr);
+ xmlFree(str_ptr);
return (-1);
}
+ xmlFree(str_ptr);
*ret_value = value.derive;
return (0);
} /* }}} int bind_xml_read_derive */
if (child->type != XML_ELEMENT_NODE)
continue;
- if (strncmp ("counter", (char *) child->name, strlen ("counter")) == 0)
+ if (strncmp ("counter", (char *) child->name, strlen ("counter")) != 0)
+ continue;
+
+ char *attr_name;
+ value_t value;
+ int status;
+
+ attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
+ if (attr_name == NULL)
{
- char *attr_name;
- value_t value;
- int status;
-
- attr_name = (char *) xmlGetProp (child, BAD_CAST "name");
- if (attr_name == NULL)
- {
- DEBUG ("bind plugin: found <counter> without name.");
- continue;
- }
- if (ds_type == DS_TYPE_GAUGE)
- status = bind_xml_read_gauge (doc, child, &value.gauge);
- else
- status = bind_xml_read_derive (doc, child, &value.derive);
- if (status != 0)
- continue;
-
- status = (*list_callback) (attr_name, value, current_time, user_data);
- if (status == 0)
- num_entries++;
+ DEBUG ("bind plugin: found <counter> without name.");
+ continue;
}
+ if (ds_type == DS_TYPE_GAUGE)
+ status = bind_xml_read_gauge (doc, child, &value.gauge);
+ else
+ status = bind_xml_read_derive (doc, child, &value.derive);
+ if (status != 0)
+ continue;
+
+ status = (*list_callback) (attr_name, value, current_time, user_data);
+ if (status == 0)
+ num_entries++;
}
}
int i;
size_t j;
- path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
- if (path_obj == NULL)
+ if (version >= 3)
{
- ERROR ("bind plugin: xmlXPathEvalExpression failed.");
- return (-1);
+ char *n = (char *) xmlGetProp (node, BAD_CAST "name");
+ char *c = (char *) xmlGetProp (node, BAD_CAST "rdataclass");
+ if (n && c)
+ {
+ zone_name = (char *) xmlMalloc(strlen(n) + strlen(c) + 2);
+ snprintf(zone_name, strlen(n) + strlen(c) + 2, "%s/%s", n, c);
+ }
+ xmlFree(n);
+ xmlFree(c);
}
-
- for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
+ else
{
- zone_name = (char *) xmlNodeListGetString (doc,
- path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
- if (zone_name != NULL)
- break;
+ path_obj = xmlXPathEvalExpression (BAD_CAST "name", path_ctx);
+ if (path_obj == NULL)
+ {
+ ERROR ("bind plugin: xmlXPathEvalExpression failed.");
+ return (-1);
+ }
+
+ for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
+ {
+ zone_name = (char *) xmlNodeListGetString (doc,
+ path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
+ if (zone_name != NULL)
+ break;
+ }
+ xmlXPathFreeObject (path_obj);
}
if (zone_name == NULL)
{
ERROR ("bind plugin: Could not determine zone name.");
- xmlXPathFreeObject (path_obj);
return (-1);
}
xmlFree (zone_name);
zone_name = NULL;
- if (j >= views_num)
- {
- xmlXPathFreeObject (path_obj);
+ if (j >= views->zones_num)
return (0);
- }
zone_name = view->zones[j];
ssnprintf (plugin_instance, sizeof (plugin_instance), "%s-zone-%s",
view->name, zone_name);
- bind_parse_generic_value_list (/* xpath = */ "counters",
+ if (version == 3)
+ {
+ list_info_ptr_t list_info =
+ {
+ plugin_instance,
+ /* type = */ "dns_qtype"
+ };
+ bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='rcode']",
/* callback = */ bind_xml_table_callback,
/* user_data = */ &table_ptr,
doc, path_ctx, current_time, DS_TYPE_COUNTER);
+ bind_parse_generic_name_attr_value_list (/* xpath = */ "counters[@type='qtype']",
+ /* callback = */ bind_xml_list_callback,
+ /* user_data = */ &list_info,
+ doc, path_ctx, current_time, DS_TYPE_COUNTER);
+ }
+ else
+ {
+ bind_parse_generic_value_list (/* xpath = */ "counters",
+ /* callback = */ bind_xml_table_callback,
+ /* user_data = */ &table_ptr,
+ doc, path_ctx, current_time, DS_TYPE_COUNTER);
+ }
} /* }}} */
- xmlXPathFreeObject (path_obj);
-
return (0);
} /* }}} int bind_xml_stats_handle_zone */
doc, path_ctx, current_time, DS_TYPE_GAUGE);
} /* }}} */
- // v3 does not provide per-zone stats any more
- if (version < 3 && view->zones_num > 0)
+ if (view->zones_num > 0)
bind_xml_stats_search_zones (version, doc, path_ctx, node, view,
current_time);
return (0);
} /* }}} int bind_xml_stats_search_views */
-static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
- xmlXPathContext *xpathCtx, xmlNode *statsnode)
+static void bind_xml_stats_v3 (xmlDoc *doc, /* {{{ */
+ xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
{
- time_t current_time = 0;
- int status;
+ /* XPath: server/counters[@type='opcode']
+ * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
+ * Layout v3:
+ * <counters type="opcode">
+ * <counter name="A">1</counter>
+ * :
+ * </counters>
+ */
+ if (global_opcodes != 0)
+ {
+ list_info_ptr_t list_info =
+ {
+ /* plugin instance = */ "global-opcodes",
+ /* type = */ "dns_opcode"
+ };
+ bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
+ /* callback = */ bind_xml_list_callback,
+ /* user_data = */ &list_info,
+ doc, xpathCtx, current_time, DS_TYPE_COUNTER);
+ }
- xpathCtx->node = statsnode;
+ /* XPath: server/counters[@type='qtype']
+ * Variables: RESERVED0, A, NS, CNAME, SOA, MR, PTR, HINFO, MX, TXT, RP,
+ * X25, PX, AAAA, LOC, SRV, NAPTR, A6, DS, RRSIG, NSEC, DNSKEY,
+ * SPF, TKEY, IXFR, AXFR, ANY, ..., Others
+ * Layout v3:
+ * <counters type="opcode">
+ * <counter name="A">1</counter>
+ * :
+ * </counters>
+ */
+ if (global_qtypes != 0)
+ {
+ list_info_ptr_t list_info =
+ {
+ /* plugin instance = */ "global-qtypes",
+ /* type = */ "dns_qtype"
+ };
- /* TODO: Check `server/boot-time' to recognize server restarts. */
+ bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
+ /* callback = */ bind_xml_list_callback,
+ /* user_data = */ &list_info,
+ doc, xpathCtx, current_time, DS_TYPE_COUNTER);
+ }
- status = bind_xml_read_timestamp ("server/current-time",
- doc, xpathCtx, ¤t_time);
- if (status != 0)
+ /* XPath: server/counters[@type='nsstat']
+ * Variables: Requestv4, Requestv6, ReqEdns0, ReqBadEDNSVer, ReqTSIG,
+ * ReqSIG0, ReqBadSIG, ReqTCP, AuthQryRej, RecQryRej, XfrRej,
+ * UpdateRej, Response, TruncatedResp, RespEDNS0, RespTSIG,
+ * RespSIG0, QrySuccess, QryAuthAns, QryNoauthAns, QryReferral,
+ * QryNxrrset, QrySERVFAIL, QryFORMERR, QryNXDOMAIN, QryRecursion,
+ * QryDuplicate, QryDropped, QryFailure, XfrReqDone, UpdateReqFwd,
+ * UpdateRespFwd, UpdateFwdFail, UpdateDone, UpdateFail,
+ * UpdateBadPrereq
+ * Layout v3:
+ * <counters type="nsstat"
+ * <counter name="Requestv4">1</counter>
+ * <counter name="Requestv6">0</counter>
+ * :
+ * </counter>
+ */
+ if (global_server_stats)
{
- ERROR ("bind plugin: Reading `server/current-time' failed.");
- return (-1);
+ translation_table_ptr_t table_ptr =
+ {
+ nsstats_translation_table,
+ nsstats_translation_table_length,
+ /* plugin_instance = */ "global-server_stats"
+ };
+
+ bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
+ /* callback = */ bind_xml_table_callback,
+ /* user_data = */ &table_ptr,
+ doc, xpathCtx, current_time, DS_TYPE_COUNTER);
}
- DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
+
+ /* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
+ * Variables: NotifyOutv4, NotifyOutv6, NotifyInv4, NotifyInv6, NotifyRej,
+ * SOAOutv4, SOAOutv6, AXFRReqv4, AXFRReqv6, IXFRReqv4, IXFRReqv6,
+ * XfrSuccess, XfrFail
+ * Layout v3:
+ * <counters type="zonestat"
+ * <counter name="NotifyOutv4">0</counter>
+ * <counter name="NotifyOutv6">0</counter>
+ * :
+ * </counter>
+ */
+ if (global_zone_maint_stats)
+ {
+ translation_table_ptr_t table_ptr =
+ {
+ zonestats_translation_table,
+ zonestats_translation_table_length,
+ /* plugin_instance = */ "global-zone_maint_stats"
+ };
+
+ bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
+ /* callback = */ bind_xml_table_callback,
+ /* user_data = */ &table_ptr,
+ doc, xpathCtx, current_time, DS_TYPE_COUNTER);
+ }
+
+ /* XPath: server/resstats, server/counters[@type='resstat']
+ * Variables: Queryv4, Queryv6, Responsev4, Responsev6, NXDOMAIN, SERVFAIL,
+ * FORMERR, OtherError, EDNS0Fail, Mismatch, Truncated, Lame,
+ * Retry, GlueFetchv4, GlueFetchv6, GlueFetchv4Fail,
+ * GlueFetchv6Fail, ValAttempt, ValOk, ValNegOk, ValFail
+ * Layout v3:
+ * <counters type="resstat"
+ * <counter name="Queryv4">0</counter>
+ * <counter name="Queryv6">0</counter>
+ * :
+ * </counter>
+ */
+ if (global_resolver_stats != 0)
+ {
+ translation_table_ptr_t table_ptr =
+ {
+ resstats_translation_table,
+ resstats_translation_table_length,
+ /* plugin_instance = */ "global-resolver_stats"
+ };
+
+ bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
+ /* callback = */ bind_xml_table_callback,
+ /* user_data = */ &table_ptr,
+ doc, xpathCtx, current_time, DS_TYPE_COUNTER);
+ }
+} /* }}} bind_xml_stats_v3 */
+
+static void bind_xml_stats_v1_v2 (int version, xmlDoc *doc, /* {{{ */
+ xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time)
+{
/* XPath: server/requests/opcode, server/counters[@type='opcode']
* Variables: QUERY, IQUERY, NOTIFY, UPDATE, ...
* Layout V1 and V2:
* <counter>1</counter>
* </opcode>
* :
- *
- * Layout v3:
- * <counters type="opcode">
- * <counter name="A">1</counter>
- * :
- * </counters>
*/
if (global_opcodes != 0)
{
/* plugin instance = */ "global-opcodes",
/* type = */ "dns_opcode"
};
- if (version == 3)
- {
- bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='opcode']",
+
+ bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
/* callback = */ bind_xml_list_callback,
/* user_data = */ &list_info,
doc, xpathCtx, current_time, DS_TYPE_COUNTER);
- }
- else
- {
- bind_parse_generic_name_value (/* xpath = */ "server/requests/opcode",
- /* callback = */ bind_xml_list_callback,
- /* user_data = */ &list_info,
- doc, xpathCtx, current_time, DS_TYPE_COUNTER);
- }
}
/* XPath: server/queries-in/rdtype, server/counters[@type='qtype']
* <counter>1</counter>
* </rdtype>
* :
- *
- * Layout v3:
- * <counters type="opcode">
- * <counter name="A">1</counter>
- * :
- * </counters>
*/
if (global_qtypes != 0)
{
/* plugin instance = */ "global-qtypes",
/* type = */ "dns_qtype"
};
- if (version == 3)
- {
- bind_parse_generic_name_attr_value_list (/* xpath = */ "server/counters[@type='qtype']",
- /* callback = */ bind_xml_list_callback,
- /* user_data = */ &list_info,
- doc, xpathCtx, current_time, DS_TYPE_COUNTER);
- }
- else
- {
- bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
- /* callback = */ bind_xml_list_callback,
- /* user_data = */ &list_info,
- doc, xpathCtx, current_time, DS_TYPE_COUNTER);
- }
+
+ bind_parse_generic_name_value (/* xpath = */ "server/queries-in/rdtype",
+ /* callback = */ bind_xml_list_callback,
+ /* user_data = */ &list_info,
+ doc, xpathCtx, current_time, DS_TYPE_COUNTER);
}
/* XPath: server/nsstats, server/nsstat, server/counters[@type='nsstat']
* <counter>0</counter>
* </nsstat>
* :
- * Layout v3:
- * <counters type="nsstat"
- * <counter name="Requestv4">1</counter>
- * <counter name="Requestv6">0</counter>
- * :
- * </counter>
*/
if (global_server_stats)
{
translation_table_ptr_t table_ptr =
- {
+ {
nsstats_translation_table,
nsstats_translation_table_length,
/* plugin_instance = */ "global-server_stats"
/* user_data = */ &table_ptr,
doc, xpathCtx, current_time, DS_TYPE_COUNTER);
}
- else if (version == 2)
+ else
{
bind_parse_generic_name_value ("server/nsstat",
/* callback = */ bind_xml_table_callback,
/* user_data = */ &table_ptr,
doc, xpathCtx, current_time, DS_TYPE_COUNTER);
}
- else // version == 3
- {
- bind_parse_generic_name_attr_value_list ("server/counters[@type='nsstat']",
- /* callback = */ bind_xml_table_callback,
- /* user_data = */ &table_ptr,
- doc, xpathCtx, current_time, DS_TYPE_COUNTER);
- }
}
/* XPath: server/zonestats, server/zonestat, server/counters[@type='zonestat']
* <counter>0</counter>
* </zonestat>
* :
- * Layout v3:
- * <counters type="zonestat"
- * <counter name="NotifyOutv4">0</counter>
- * <counter name="NotifyOutv6">0</counter>
- * :
- * </counter>
*/
if (global_zone_maint_stats)
{
translation_table_ptr_t table_ptr =
- {
+ {
zonestats_translation_table,
zonestats_translation_table_length,
/* plugin_instance = */ "global-zone_maint_stats"
/* user_data = */ &table_ptr,
doc, xpathCtx, current_time, DS_TYPE_COUNTER);
}
- else if (version == 2)
+ else
{
bind_parse_generic_name_value ("server/zonestat",
/* callback = */ bind_xml_table_callback,
/* user_data = */ &table_ptr,
doc, xpathCtx, current_time, DS_TYPE_COUNTER);
}
- else // version == 3
- {
- bind_parse_generic_name_attr_value_list ("server/counters[@type='zonestat']",
- /* callback = */ bind_xml_table_callback,
- /* user_data = */ &table_ptr,
- doc, xpathCtx, current_time, DS_TYPE_COUNTER);
- }
}
/* XPath: server/resstats, server/counters[@type='resstat']
* <counter>0</counter>
* </resstat>
* :
- * Layout v3:
- * <counters type="resstat"
- * <counter name="Queryv4">0</counter>
- * <counter name="Queryv6">0</counter>
- * :
- * </counter>
*/
if (global_resolver_stats != 0)
{
translation_table_ptr_t table_ptr =
- {
+ {
resstats_translation_table,
resstats_translation_table_length,
/* plugin_instance = */ "global-resolver_stats"
/* user_data = */ &table_ptr,
doc, xpathCtx, current_time, DS_TYPE_COUNTER);
}
- else if (version == 2)
- {
- bind_parse_generic_name_value ("server/resstat",
- /* callback = */ bind_xml_table_callback,
- /* user_data = */ &table_ptr,
- doc, xpathCtx, current_time, DS_TYPE_COUNTER);
- }
else
{
- bind_parse_generic_name_attr_value_list ("server/counters[@type='resstat']",
+ bind_parse_generic_name_value ("server/resstat",
/* callback = */ bind_xml_table_callback,
/* user_data = */ &table_ptr,
doc, xpathCtx, current_time, DS_TYPE_COUNTER);
}
}
+} /* }}} bind_xml_stats_v1_v2 */
+
+static int bind_xml_stats (int version, xmlDoc *doc, /* {{{ */
+ xmlXPathContext *xpathCtx, xmlNode *statsnode)
+{
+ time_t current_time = 0;
+ int status;
+
+ xpathCtx->node = statsnode;
+
+ /* TODO: Check `server/boot-time' to recognize server restarts. */
+
+ status = bind_xml_read_timestamp ("server/current-time",
+ doc, xpathCtx, ¤t_time);
+ if (status != 0)
+ {
+ ERROR ("bind plugin: Reading `server/current-time' failed.");
+ return (-1);
+ }
+ DEBUG ("bind plugin: Current server time is %i.", (int) current_time);
+
+ if (version == 3)
+ {
+ bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time);
+ }
+ else
+ {
+ bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time);
+ }
/* XPath: memory/summary
* Variables: TotalUse, InUse, BlockSize, ContextSize, Lost
bind_config_add_view (child);
else if (strcasecmp ("ParseTime", child->key) == 0)
cf_util_get_boolean (child, &config_parse_time);
+ else if (strcasecmp ("Timeout", child->key) == 0)
+ cf_util_get_int (child, &timeout);
else
{
WARNING ("bind plugin: Unknown configuration option "
curl_easy_setopt (curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 50L);
+#ifdef HAVE_CURLOPT_TIMEOUT_MS
+ curl_easy_setopt (curl, CURLOPT_TIMEOUT_MS, (timeout >= 0) ?
+ (long) timeout : CDTIME_T_TO_MS(plugin_get_interval()));
+#endif
+
return (0);
} /* }}} int bind_init */