@cryptotaxi247 / netdata-1 / commits / d5cd94eed

cups.plugin: Support older versions (#5350)

The usage of cupsGetIntegerOption did block users using older cups versions than 2.2.4. After redistribution this method all cups versions since 1.7 can be used. httpConnect2 is now the most recently added method in cups.h.

Simon Nagl committed Feb 11, 2019 at 10:40 UTC d5cd94eed3c838a0f997c8a289c0f729e9da1eb7
3 files changed +35 -4
collectors/cups.plugin/README.md
+1 -1
@@ -4,7 +4,7 @@
4
5 ## Prerequisites
6
7 -This plugin needs a running local CUPS daemon (`cupsd`). This plugin does not need any configuration.
7 +This plugin needs a running local CUPS daemon (`cupsd`). This plugin does not need any configuration. Supports cups since version 1.7.
8
9 ## Charts
10
collectors/cups.plugin/cups_plugin.c
+32 -2
@@ -136,6 +136,37 @@ void parse_command_line(int argc, char **argv) {
136 }
137 }
138
139 +/*
140 + * 'cupsGetIntegerOption()' - Get an integer option value.
141 + *
142 + * INT_MIN is returned when the option does not exist, is not an integer, or
143 + * exceeds the range of values for the "int" type.
144 + *
145 + * @since CUPS 2.2.4/macOS 10.13@
146 + */
147 +
148 +int /* O - Option value or @code INT_MIN@ */
149 +getIntegerOption(
150 + const char *name, /* I - Name of option */
151 + int num_options, /* I - Number of options */
152 + cups_option_t *options) /* I - Options */
153 +{
154 + const char *value = cupsGetOption(name, num_options, options);
155 + /* String value of option */
156 + char *ptr; /* Pointer into string value */
157 + long intvalue; /* Integer value */
158 +
159 +
160 + if (!value || !*value)
161 + return (INT_MIN);
162 +
163 + intvalue = strtol(value, &ptr, 10);
164 + if (intvalue < INT_MIN || intvalue > INT_MAX || *ptr)
165 + return (INT_MIN);
166 +
167 + return ((int)intvalue);
168 +}
169 +
170 int reset_job_metrics(void *entry, void *data) {
171 (void)data;
172
@@ -303,8 +334,7 @@ int main(int argc, char **argv) {
334 num_dest_shared++;
335 }
336
306 - // TODO use cupsGetIntegerOption
307 - int printer_state = cupsGetIntegerOption("printer-state", curr_dest->num_options, curr_dest->options);
337 + int printer_state = getIntegerOption("printer-state", curr_dest->num_options, curr_dest->options);
338 switch (printer_state) {
339 case 3:
340 num_dest_idle++;
configure.ac
+2 -1
@@ -409,7 +409,8 @@ AM_CONDITIONAL([ENABLE_PLUGIN_FREEIPMI], [test "${enable_plugin_freeipmi}" = "ye
409 # -----------------------------------------------------------------------------
410 # cups.plugin - libmnl, libnetfilter_acct
411
412 - AC_CHECK_LIB([cups], [cupsGetIntegerOption],
412 +# Only check most recently added method of cups
413 + AC_CHECK_LIB([cups], [httpConnect2],
414 [AC_CHECK_HEADER(
415 [cups/cups.h],
416 [have_cups=yes],