Re: zbxpcp.so: update module.h from upstream 3.2.1
"Nathan Scott" <[email protected]>
| Newsgroups | gmane.comp.sysutils.pcp |
|---|---|
| Message-ID | <[email protected]> |
Attached patch includes those two changes - Mark, up to you if ya want to pull this in, its fairly localized though - else we can just pick it up next time if too late. cheers. ----- Original Message ----- > Hi, > > On 2016-11-09 08:18, Nathan Scott wrote: > > ----- Original Message ----- > >> [...] > >> Zabbix Agent module API has been changed, every existing binary is > >> broken and we need to adjust our local module.h copy. > > > > Ouch. We may be able to workaround this the same way we did last time > > - if we can find a symbol newly added in zabbix 3.2 we could use dlsym > > heuristics again. > > > >> Zabbix 3.2 is available from their repos for RHEL 5 and newer, I don't > >> think we need to preserve source level compatibility with API version 1. > > > > *nod* - its more the existing zbxpcp.so installed base we need to worry > > about, which would break for all pre-3.2 zabbix versions (i.e. if we go > > with that patch, next PCP upgrade will break pretty much everyone using > > zbxpcp.so). > > > > Attached patch is an initial tweak on the PCP code, which should do all > > the right things once its "zbx_xxxxxx" is replaced with an appropriate > > function name, and hopefully will then work for all Zabbix versions. Any > > ideas on a symbol we could use? (perhaps something related to this new > > "history" functionality) > > Good idea (again) - your patch with two additional changes works with > both 3.0.5 and 3.2.1: > > - use history_log_cbs as the symbol to check > - call zbx_get_version() in zbx_module_api_version(), not in > zbx_module_init() > > Thanks, > > -- > Marko Myllynen > -=-=-=-=-=-=-=-=-=-=-=- pcp mailing list [email protected] https://groups.io/g/pcp/messages -=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#14674): https://groups.io/g/pcp/message/14674 View All Messages In Topic (4): https://groups.io/g/pcp/topic/2992464 Mute This Topic: https://groups.io/mt/2992464?uid=174580 New Topic: https://groups.io/g/pcp/post Change Your Subscription: https://groups.io/g/pcp/editsub?uid=174580 Group Home: https://groups.io/g/pcp Contact Group Owner: [email protected] Terms of Service: https://groups.io/static/tos Unsubscribe: https://groups.io/g/pcp/leave/354243/563757577/xyzzy -=-=-=-=-=-=-=-=-=-=-=-
zbxpcp-versions.patch
(text/x-patch, 3.2 KB)
diff --git a/src/zabbix-agent/src/module.h b/src/zabbix-agent/src/module.h
index c8ba990..8886e22 100644
--- a/src/zabbix-agent/src/module.h
+++ b/src/zabbix-agent/src/module.h
@@ -22,6 +22,7 @@ typedef __uint64_t zbx_uint64_t;
#define ZBX_MODULE_FAIL -1
#define ZBX_MODULE_API_VERSION_ONE 1
+#define ZBX_MODULE_API_VERSION_TWO 2
#define get_rkey(request) (request)->key
#define get_rparams_num(request) (request)->nparam
diff --git a/src/zabbix-agent/src/zbxpcp.c b/src/zabbix-agent/src/zbxpcp.c
index 141daf8..541e434 100644
--- a/src/zabbix-agent/src/zbxpcp.c
+++ b/src/zabbix-agent/src/zbxpcp.c
@@ -44,8 +44,9 @@
* We attempt to auto-detect the Zabbix agent version to deal
* with ABI/ABI breakage at the Zabbix v2/v3 boundary.
*/
-#define ZBX_COMPAT_VERSION 2
-#define ZBX_RECENT_VERSION 3
+#define ZBX_VERSION2 2.0
+#define ZBX_VERSION3 3.0
+#define ZBX_VERSION3_2 3.2
/* PCP includes. */
#include "pmapi.h"
@@ -57,7 +58,7 @@
/* Zabbix includes. */
#include "module.h"
-static int zbx_version;
+static float zbx_version = ZBX_VERSION2;
/*
* PCP connection
@@ -79,26 +80,26 @@ static int zbx_module_pcp_disconnect()
return pmDestroyContext(ctx);
}
-static int zbx_get_version()
+static void zbx_get_version()
{
- int version = ZBX_COMPAT_VERSION;
#if defined(HAVE_DLOPEN)
void *handle = dlopen(NULL, RTLD_NOW);
if (!handle) {
- fprintf(stderr, "dlopen failed, assuming zabbix-agent version=%d\n",
- version);
- return version;
+ fprintf(stderr, "dlopen failed, assuming zabbix-agent version=%.1f\n",
+ zbx_version);
+ return;
}
- /* lookup a symbol that should exist in all new versions, but not old */
- if (dlsym(handle, "zbx_user_macro_parse") != NULL)
- version = ZBX_RECENT_VERSION;
+ /* lookup symbol that should exist in new versions, but not old versions */
+ if (dlsym(handle, "history_log_cbs") != NULL)
+ zbx_version = ZBX_VERSION3_2;
+ else if (dlsym(handle, "zbx_user_macro_parse") != NULL)
+ zbx_version = ZBX_VERSION3;
dlclose(handle);
#else
- fprintf(stderr, "dlopen unsupported, assuming zabbix-agent version=%d\n",
- version);
+ fprintf(stderr, "dlopen unsupported, assuming zabbix-agent version=%.1f\n",
+ zbx_version);
#endif
- return version;
}
/*
@@ -106,7 +107,6 @@ static int zbx_get_version()
*/
int zbx_module_init()
{
- zbx_version = zbx_get_version();
if (zbx_module_pcp_connect() < 0)
return ZBX_MODULE_FAIL;
return ZBX_MODULE_OK;
@@ -114,6 +114,9 @@ int zbx_module_init()
int zbx_module_api_version()
{
+ zbx_get_version();
+ if (zbx_version >= ZBX_VERSION3_2)
+ return ZBX_MODULE_API_VERSION_TWO;
return ZBX_MODULE_API_VERSION_ONE;
}
@@ -199,7 +202,7 @@ static void zbx_module_pcp_add_metric(const char *name)
if (metrics == NULL) { metrics = mptr; free(metric); free(param); return; }
metrics[metric_count].key = metric;
metrics[metric_count].flags = flags;
- if (zbx_version == ZBX_RECENT_VERSION)
+ if (zbx_version >= ZBX_VERSION3)
metrics[metric_count].function = zbx_module3_pcp_fetch_metric;
else
metrics[metric_count].function = zbx_module2_pcp_fetch_metric;