diff options
Diffstat (limited to 'web/attachments/456909-nagios-plugins-metadata.patch')
| -rw-r--r-- | web/attachments/456909-nagios-plugins-metadata.patch | 315 |
1 files changed, 315 insertions, 0 deletions
diff --git a/web/attachments/456909-nagios-plugins-metadata.patch b/web/attachments/456909-nagios-plugins-metadata.patch new file mode 100644 index 0000000..421a1fa --- /dev/null +++ b/web/attachments/456909-nagios-plugins-metadata.patch | |||
| @@ -0,0 +1,315 @@ | |||
| 1 | commit ba0449fe8534bdcc03d3a15e36c8af711a2a72d2 | ||
| 2 | Author: Dejan Muhamedagic <dejan@suse.de> | ||
| 3 | Date: Thu Nov 22 15:47:27 2012 +0100 | ||
| 4 | |||
| 5 | Support for meta-data (XML) | ||
| 6 | |||
| 7 | Enables nagios plugins to be deployed as resource agents with | ||
| 8 | pacemaker clusters. The meta-data is defined here: | ||
| 9 | |||
| 10 | https://github.com/ClusterLabs/resource-agents/blob/master/heartbeat/ra-api-1.dtd | ||
| 11 | |||
| 12 | This commit does not change behaviour of any plugins. | ||
| 13 | |||
| 14 | diff --git a/plugins/Makefile.am b/plugins/Makefile.am | ||
| 15 | index 0eb0255..0ef8d50 100644 | ||
| 16 | --- a/plugins/Makefile.am | ||
| 17 | +++ b/plugins/Makefile.am | ||
| 18 | @@ -39,12 +39,12 @@ EXTRA_PROGRAMS = check_mysql check_radius check_pgsql check_snmp check_hpjd \ | ||
| 19 | check_nagios check_by_ssh check_dns check_nt check_ide_smart \ | ||
| 20 | check_procs check_mysql_query check_apt check_dbi | ||
| 21 | |||
| 22 | -EXTRA_DIST = t tests utils.c netutils.c sslutils.c popen.c utils.h netutils.h \ | ||
| 23 | - popen.h common.h runcmd.c runcmd.h | ||
| 24 | +EXTRA_DIST = t tests utils.c netutils.c sslutils.c popen.c help.c \ | ||
| 25 | + utils.h netutils.h popen.h common.h runcmd.c runcmd.h help.h | ||
| 26 | |||
| 27 | PLUGINHDRS = common.h | ||
| 28 | |||
| 29 | -BASEOBJS = utils.o ../lib/libnagiosplug.a ../gl/libgnu.a | ||
| 30 | +BASEOBJS = utils.o help.o ../lib/libnagiosplug.a ../gl/libgnu.a | ||
| 31 | NETOBJS = netutils.o $(BASEOBJS) $(EXTRA_NETOBJS) | ||
| 32 | SSLOBJS = sslutils.o | ||
| 33 | NETLIBS = $(NETOBJS) $(SOCKETLIBS) | ||
| 34 | @@ -159,6 +159,8 @@ runcmd.o: runcmd.c runcmd.h $(PLUGINHDRS) | ||
| 35 | |||
| 36 | utils.o: utils.c utils.h $(PLUGINHDRS) | ||
| 37 | |||
| 38 | +help.o: help.c help.h | ||
| 39 | + | ||
| 40 | netutils.o: netutils.c netutils.h $(PLUGINHDRS) | ||
| 41 | sslutils.o: sslutils.c netutils.h $(PLUGINHDRS) | ||
| 42 | |||
| 43 | diff --git a/plugins/help.c b/plugins/help.c | ||
| 44 | new file mode 100644 | ||
| 45 | index 0000000..214707e | ||
| 46 | --- /dev/null | ||
| 47 | +++ b/plugins/help.c | ||
| 48 | @@ -0,0 +1,140 @@ | ||
| 49 | +/* | ||
| 50 | + * help.c: custom help functions to print help text and XML | ||
| 51 | + * meta-data | ||
| 52 | + * | ||
| 53 | + * Copyright (C) 2012 Dejan Muhamedagic <dejan@hello-penguin.com> | ||
| 54 | + * | ||
| 55 | + * | ||
| 56 | + * This library is free software; you can redistribute it and/or | ||
| 57 | + * modify it under the terms of the GNU Lesser General Public | ||
| 58 | + * License as published by the Free Software Foundation; either | ||
| 59 | + * version 2.1 of the License, or (at your option) any later version. | ||
| 60 | + * | ||
| 61 | + * This library is distributed in the hope that it will be useful, | ||
| 62 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 63 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 64 | + * Lesser General Public License for more details. | ||
| 65 | + * | ||
| 66 | + * You should have received a copy of the GNU Lesser General Public | ||
| 67 | + * License along with this library; if not, write to the Free Software | ||
| 68 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 69 | + * | ||
| 70 | + */ | ||
| 71 | + | ||
| 72 | +#include "common.h" | ||
| 73 | +#include "help.h" | ||
| 74 | + | ||
| 75 | +static void meta_long_desc_from_short(const char *, const char *); | ||
| 76 | +static void meta_long_desc(const char *, const char *); | ||
| 77 | +static void meta_short_desc(const char *, const char *); | ||
| 78 | +static void meta_param(const char *, struct parameter_help *); | ||
| 79 | +static void indent(const char *, const char *); | ||
| 80 | + | ||
| 81 | +static void | ||
| 82 | +meta_long_desc_from_short(const char *lang, const char *s) | ||
| 83 | +{ | ||
| 84 | + printf(XML_LONGDESC_BEGIN, lang); | ||
| 85 | + printf("%s\n", _(s)); | ||
| 86 | + printf(XML_LONGDESC_END); | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +static void | ||
| 90 | +meta_long_desc(const char *lang, const char *s) | ||
| 91 | +{ | ||
| 92 | + printf(XML_LONGDESC_BEGIN, lang); | ||
| 93 | + printf("%s", _(s)); | ||
| 94 | + printf(XML_LONGDESC_END); | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +static void | ||
| 98 | +meta_short_desc(const char *lang, const char *s) | ||
| 99 | +{ | ||
| 100 | + printf(XML_SHORTDESC_BEGIN, lang); | ||
| 101 | + printf("%s", _(s)); | ||
| 102 | + printf(XML_SHORTDESC_END); | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +static void | ||
| 106 | +meta_param(const char *lang, struct parameter_help *ph) | ||
| 107 | +{ | ||
| 108 | + printf(XML_PARAMETER_BEGIN, ph->name, ph->unique, ph->required); | ||
| 109 | + if (ph->long_desc) { | ||
| 110 | + meta_long_desc(lang, ph->long_desc); | ||
| 111 | + } else { | ||
| 112 | + meta_long_desc_from_short(lang, ph->short_desc); | ||
| 113 | + } | ||
| 114 | + meta_short_desc(lang, ph->short_desc); | ||
| 115 | + printf(XML_PARAMETER_CONTENT, ph->type, ph->dflt_value); | ||
| 116 | + printf(XML_PARAMETER_END); | ||
| 117 | +} | ||
| 118 | + | ||
| 119 | +void | ||
| 120 | +print_meta_data(struct help_head *hh, struct parameter_help *ph) | ||
| 121 | +{ | ||
| 122 | + struct parameter_help *p; | ||
| 123 | + | ||
| 124 | + printf(XML_START, hh->name); | ||
| 125 | + if (hh->long_desc) { | ||
| 126 | + meta_long_desc(LANG, hh->long_desc); | ||
| 127 | + } else { | ||
| 128 | + meta_long_desc_from_short(LANG, hh->short_desc); | ||
| 129 | + } | ||
| 130 | + meta_short_desc(LANG, hh->short_desc); | ||
| 131 | + printf("\n"); | ||
| 132 | + printf(XML_PARAMETERS_BEGIN); | ||
| 133 | + printf("\n"); | ||
| 134 | + for (p = ph; p->short_desc; p++) { | ||
| 135 | + meta_param(LANG, p); | ||
| 136 | + printf("\n"); | ||
| 137 | + } | ||
| 138 | + printf(XML_PARAMETERS_END); | ||
| 139 | + printf("\n"); | ||
| 140 | + printf(XML_ACTIONS); | ||
| 141 | + printf("\n"); | ||
| 142 | + printf(XML_END); | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +static void | ||
| 146 | +indent(const char *s, const char *tab) | ||
| 147 | +{ | ||
| 148 | + const char *p, *q; | ||
| 149 | + int len; | ||
| 150 | + | ||
| 151 | + if (!s ) | ||
| 152 | + return; | ||
| 153 | + for (p = s; p < s+strlen(s) && *p; p = q+1) { | ||
| 154 | + q = strchr(p, '\n'); | ||
| 155 | + if( q ) { | ||
| 156 | + printf("%s%.*s", tab, q-p+1, p); | ||
| 157 | + } else { | ||
| 158 | + printf("%s%s\n", tab, p); | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | +} | ||
| 162 | + | ||
| 163 | +void | ||
| 164 | +print_help_head(struct help_head *hh) | ||
| 165 | +{ | ||
| 166 | + if (hh->long_desc) { | ||
| 167 | + printf(_(hh->long_desc)); | ||
| 168 | + } else { | ||
| 169 | + printf("%s\n", _(hh->short_desc)); | ||
| 170 | + } | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +void | ||
| 174 | +print_parameters_help(struct parameter_help *ph) | ||
| 175 | +{ | ||
| 176 | + struct parameter_help *p; | ||
| 177 | + | ||
| 178 | + for (p = ph; p->short_desc; p++) { | ||
| 179 | + if (p->short_opt) { | ||
| 180 | + printf(" -%c, --%s=%s\n", (unsigned char)(p->short_opt), | ||
| 181 | + p->name, p->value_desc); | ||
| 182 | + } else { | ||
| 183 | + printf(" --%s=%s\n", p->name, p->value_desc); | ||
| 184 | + } | ||
| 185 | + indent(_(p->long_desc), " "); | ||
| 186 | + printf(UT_METADATA); | ||
| 187 | + } | ||
| 188 | +} | ||
| 189 | diff --git a/plugins/help.h b/plugins/help.h | ||
| 190 | new file mode 100644 | ||
| 191 | index 0000000..4486424 | ||
| 192 | --- /dev/null | ||
| 193 | +++ b/plugins/help.h | ||
| 194 | @@ -0,0 +1,108 @@ | ||
| 195 | +/* | ||
| 196 | + * help.h: custom help functions to print help text and XML | ||
| 197 | + * meta-data | ||
| 198 | + * | ||
| 199 | + * Copyright (C) 2012 Dejan Muhamedagic <dejan@hello-penguin.com> | ||
| 200 | + * | ||
| 201 | + * | ||
| 202 | + * This library is free software; you can redistribute it and/or | ||
| 203 | + * modify it under the terms of the GNU Lesser General Public | ||
| 204 | + * License as published by the Free Software Foundation; either | ||
| 205 | + * version 2.1 of the License, or (at your option) any later version. | ||
| 206 | + * | ||
| 207 | + * This library is distributed in the hope that it will be useful, | ||
| 208 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 209 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 210 | + * Lesser General Public License for more details. | ||
| 211 | + * | ||
| 212 | + * You should have received a copy of the GNU Lesser General Public | ||
| 213 | + * License along with this library; if not, write to the Free Software | ||
| 214 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 215 | + * | ||
| 216 | + */ | ||
| 217 | + | ||
| 218 | +#ifndef NP_HELP_H | ||
| 219 | +#define NP_HELP_H | ||
| 220 | +/* Header file for nagios plugins help.c */ | ||
| 221 | + | ||
| 222 | +/* This file should be included in all plugins */ | ||
| 223 | + | ||
| 224 | +#include <stdio.h> | ||
| 225 | +#include <stdlib.h> | ||
| 226 | +#include <string.h> | ||
| 227 | +#include <getopt.h> | ||
| 228 | + | ||
| 229 | +/* | ||
| 230 | + * The generic constants for XML | ||
| 231 | + */ | ||
| 232 | + | ||
| 233 | +#define XML_START \ | ||
| 234 | + "<?xml version=\"1.0\"?>\n" \ | ||
| 235 | + "<!DOCTYPE resource-agent SYSTEM \"ra-api-1.dtd\">\n" \ | ||
| 236 | + "<resource-agent name=\"%s\">\n" \ | ||
| 237 | + "<version>1.0</version>\n\n" | ||
| 238 | +#define XML_ACTIONS \ | ||
| 239 | + "<actions>\n" \ | ||
| 240 | + "<action name=\"start\" timeout=\"20\" />\n" \ | ||
| 241 | + "<action name=\"stop\" timeout=\"15\" />\n" \ | ||
| 242 | + "<action name=\"status\" timeout=\"20\" />\n" \ | ||
| 243 | + "<action name=\"monitor\" timeout=\"20\" interval=\"60\" />\n" \ | ||
| 244 | + "<action name=\"meta-data\" timeout=\"15\" />\n" \ | ||
| 245 | + "</actions>\n" | ||
| 246 | +#define XML_END \ | ||
| 247 | + "</resource-agent>\n" | ||
| 248 | + | ||
| 249 | +/* <parameters>?</parameters> */ | ||
| 250 | +#define XML_PARAMETERS_BEGIN "<parameters>\n" | ||
| 251 | +#define XML_PARAMETERS_END "</parameters>\n" | ||
| 252 | + | ||
| 253 | +/* <parameter name="ipaddr" required="1" unique="1"> | ||
| 254 | + <content type="string" default="value"/> | ||
| 255 | + ? | ||
| 256 | + </parameter> | ||
| 257 | + */ | ||
| 258 | +#define XML_PARAMETER_BEGIN \ | ||
| 259 | + "<parameter name=\"%s\" unique=\"%d\" required=\"%d\">\n" | ||
| 260 | +#define XML_PARAMETER_CONTENT \ | ||
| 261 | + "<content type=\"%s\" default=\"%s\" />\n" | ||
| 262 | +#define XML_PARAMETER_END "</parameter>\n" | ||
| 263 | + | ||
| 264 | +/* <shortdesc lang="en">?</shortdesc> */ | ||
| 265 | +#define XML_SHORTDESC_BEGIN \ | ||
| 266 | + "<shortdesc lang=\"%s\">" | ||
| 267 | +#define XML_SHORTDESC_END "</shortdesc>\n" | ||
| 268 | + | ||
| 269 | +/* <longdesc lang="en">?</longdesc> */ | ||
| 270 | +#define XML_LONGDESC_BEGIN \ | ||
| 271 | + "<longdesc lang=\"%s\">\n" | ||
| 272 | +#define XML_LONGDESC_END "</longdesc>\n" | ||
| 273 | + | ||
| 274 | +#define LANG "en" | ||
| 275 | + | ||
| 276 | +#define UT_METADATA _("\ | ||
| 277 | + --metadata\n\ | ||
| 278 | + Print resource agent meta-data.\n") | ||
| 279 | + | ||
| 280 | +struct parameter_help { | ||
| 281 | + const char *name; | ||
| 282 | + int short_opt; | ||
| 283 | + const char *short_desc; | ||
| 284 | + int unique; | ||
| 285 | + int required; | ||
| 286 | + const char *type; | ||
| 287 | + const char *dflt_value; | ||
| 288 | + const char *value_desc; | ||
| 289 | + const char *long_desc; | ||
| 290 | +}; | ||
| 291 | + | ||
| 292 | +struct help_head { | ||
| 293 | + const char *name; | ||
| 294 | + const char *short_desc; | ||
| 295 | + const char *long_desc; | ||
| 296 | +}; | ||
| 297 | + | ||
| 298 | +void print_meta_data(struct help_head *, struct parameter_help *); | ||
| 299 | +void print_parameters_help(struct parameter_help *); | ||
| 300 | +void print_help_head(struct help_head *); | ||
| 301 | + | ||
| 302 | +#endif /* NP_HELP_H */ | ||
| 303 | diff --git a/plugins/utils.h b/plugins/utils.h | ||
| 304 | index 822be94..f0d0e50 100644 | ||
| 305 | --- a/plugins/utils.h | ||
| 306 | +++ b/plugins/utils.h | ||
| 307 | @@ -24,6 +24,8 @@ suite of plugins. */ | ||
| 308 | #define np_extra_opts(acptr,av,pr) av | ||
| 309 | #endif | ||
| 310 | |||
| 311 | +#include "help.h" | ||
| 312 | + | ||
| 313 | /* Standardize version information, termination */ | ||
| 314 | |||
| 315 | void support (void); | ||
