git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/nagios-plugins-contrib-24.20190301~bpo9+1/debian/patches/check_varnish/fix_for_v56
blob: 91c93fbf4782322553ba7bdfe67a3e9bbf6dc63a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
From d53252d965aaa1889a8b56a681c464c6ca04f632 Mon Sep 17 00:00:00 2001
From: Jean-Louis Dupond <mail_redacted_for_web>
Date: Sat, 23 Dec 2017 13:06:01 +0100
Subject: [PATCH] Switch to new functions for Varnish 5.2

---
 check_varnish.c | 54 +++++++++++++++++++++++++++++++++++++++++--------
 configure.ac    | 18 ++++++++++-------
 2 files changed, 57 insertions(+), 15 deletions(-)

diff --git a/check_varnish/src/check_varnish.c b/check_varnish/src/check_varnish.c
index 809657c..83aacdc 100644
--- a/check_varnish/src/check_varnish.c
+++ b/check_varnish/src/check_varnish.c
@@ -43,7 +43,7 @@
 #include <locale.h>
 #include <assert.h>
 
-#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
+#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1) || defined(HAVE_VARNISHAPI_5)
 #include <vapi/vsc.h>
 #include <vapi/vsm.h>
 #elif defined(HAVE_VARNISHAPI_3)
@@ -185,7 +185,11 @@ check_stats_cb(void *priv, const struct VSC_point * const pt)
 	if (pt == NULL)
 		return(0);
 
-#if defined(HAVE_VARNISHAPI_4_1) || defined(HAVE_VARNISHAPI_4)
+#if defined(HAVE_VARNISHAPI_5)
+	assert(sizeof(tmp) > (strlen(pt->name) + 1));
+	snprintf(tmp, sizeof(tmp), "%s", pt->name);
+	p = priv;
+#elif defined(HAVE_VARNISHAPI_4_1) || defined(HAVE_VARNISHAPI_4)
 	assert(sizeof(tmp) > (strlen(pt->section->fantom->type) + 1 +
 			      strlen(pt->section->fantom->ident) + 1 +
 			      strlen(pt->desc->name) + 1));
@@ -197,7 +201,9 @@ check_stats_cb(void *priv, const struct VSC_point * const pt)
 		 pt->desc->name);
 	p = priv;
 #endif
-#if defined(HAVE_VARNISHAPI_4_1)
+#if defined(HAVE_VARNISHAPI_5)
+	assert(!strcmp(pt->ctype, "uint64_t"));
+#elif defined(HAVE_VARNISHAPI_4_1)
 	assert(!strcmp(pt->desc->ctype, "uint64_t"));
 #elif defined(HAVE_VARNISHAPI_4)
 	assert(!strcmp(pt->desc->fmt, "uint64_t"));
@@ -216,7 +222,9 @@ check_stats_cb(void *priv, const struct VSC_point * const pt)
 #endif
 	if (strcmp(tmp, p->param) == 0) {
 		p->found = 1;
-#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
+#if defined(HAVE_VARNISHAPI_5)
+		p->info = pt->sdesc;
+#elif defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
 		p->info = pt->desc->sdesc;
 #elif defined(HAVE_VARNISHAPI_3)
 		p->info = pt->desc;
@@ -237,7 +245,11 @@ check_stats_cb(void *priv, const struct VSC_point * const pt)
  * Check the statistics for the requested parameter.
  */
 static void
+#if defined(HAVE_VARNISHAPI_5)
+check_stats(struct vsc *vsc, struct vsm *vsm, char *param)
+#else
 check_stats(struct VSM_data *vd, char *param)
+#endif
 {
 	int status;
 	struct stat_priv priv;
@@ -245,7 +257,9 @@ check_stats(struct VSM_data *vd, char *param)
 	priv.found = 0;
 	priv.param = param;
 
-#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
+#if defined(HAVE_VARNISHAPI_5)
+	(void)VSC_Iter(vsc, vsm, check_stats_cb, &priv);
+#elif defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
 	(void)VSC_Iter(vd, NULL, check_stats_cb, &priv);
 #elif defined(HAVE_VARNISHAPI_3)
 	(void)VSC_Iter(vd, check_stats_cb, &priv);
@@ -315,18 +329,25 @@ usage(void)
 int
 main(int argc, char **argv)
 {
+#if defined(HAVE_VARNISHAPI_5)
+	struct vsm *vd;
+	struct vsc *vsc;
+#else
 	struct VSM_data *vd;
+#endif
 	char *param = NULL;
 	int opt;
 
 	setlocale(LC_ALL, "");
 
 	vd = VSM_New();
-#if defined(HAVE_VARNISHAPI_3)
+#if defined(HAVE_VARNISHAPI_5)
+	vsc = VSC_New();
+#elif defined(HAVE_VARNISHAPI_3)
 	VSC_Setup(vd);
 #endif
 
-	while ((opt = getopt(argc, argv, VSC_ARGS "c:hn:p:vw:")) != -1) {
+	while ((opt = getopt(argc, argv, "c:hn:p:vw:")) != -1) {
 		switch (opt) {
 		case 'c':
 			if (parse_range(optarg, &critical) != 0)
@@ -336,7 +357,11 @@ main(int argc, char **argv)
 			help();
 			break;
 		case 'n':
+#if defined(HAVE_VARNISHAPI_5)
+			VSC_Arg(vsc, opt, optarg);
+#else
 			VSC_Arg(vd, opt, optarg);
+#endif
 			break;
 		case 'p':
 			param = strdup(optarg);
@@ -349,13 +374,22 @@ main(int argc, char **argv)
 				usage();
 			break;
 		default:
+#if defined(HAVE_VARNISHAPI_5)
+			if (VSC_Arg(vsc, opt, optarg) > 0)
+#else
 			if (VSC_Arg(vd, opt, optarg) > 0)
+#endif
 				break;
 			usage();
 		}
 	}
 
-#if defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
+#if defined(HAVE_VARNISHAPI_5)
+	if (VSM_Attach(vd, -1) < 0) {
+		printf("varnish plugin: Cannot attach to varnish. %s", VSM_Error(vd));
+		exit(1);
+	}
+#elif defined(HAVE_VARNISHAPI_4) || defined(HAVE_VARNISHAPI_4_1)
 	if (VSM_Open(vd))
 		exit(1);
 #elif defined(HAVE_VARNISHAPI_3)
@@ -377,7 +411,11 @@ main(int argc, char **argv)
 	if (!param)
 		usage();
 
+#if defined(HAVE_VARNISHAPI_5)
+	check_stats(vsc, vd, param);
+#else
 	check_stats(vd, param);
+#endif
 
 	exit(0);
 }
diff --git a/check_varnish/src/configure.ac b/check_varnish/src/configure.ac
index c7946c2..8b0b2ec 100644
--- a/check_varnish/src/configure.ac
+++ b/check_varnish/src/configure.ac
@@ -21,13 +21,17 @@ AC_PROG_LIBTOOL
 AC_PROG_MAKE_SET
 
 # Checks for libraries.
-PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4.1],
-  [AC_DEFINE([HAVE_VARNISHAPI_4_1], [1], [Use VARNISHAPI v4.1])],
-  [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4],
-    [AC_DEFINE([HAVE_VARNISHAPI_4], [1], [Use VARNISHAPI v4])],
-    [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 3],
-      [AC_DEFINE([HAVE_VARNISHAPI_3], [1], [Use VARNISHAPI v3])],
-      [AC_MSG_ERROR([Could not find neither varnishapi v4 nor v3.])])
+PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 5.2],
+  [AC_DEFINE([HAVE_VARNISHAPI_5], [1], [Use VARNISHAPI v5])],
+  [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4.1],
+    [AC_DEFINE([HAVE_VARNISHAPI_4_1], [1], [Use VARNISHAPI v4.1])],
+    [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 4],
+      [AC_DEFINE([HAVE_VARNISHAPI_4], [1], [Use VARNISHAPI v4])],
+      [PKG_CHECK_MODULES([VARNISHAPI], [varnishapi >= 3],
+        [AC_DEFINE([HAVE_VARNISHAPI_3], [1], [Use VARNISHAPI v3])],
+        [AC_MSG_ERROR([Could not find neither varnishapi v4 nor v3.])])
+      ]
+    )
     ]
   )
   ]