1 /*****************************************************************************
3 * Monitoring urlize plugin
6 * Copyright (c) 2000-2007 Monitoring Plugins Development Team
10 * This file contains the urlize plugin
12 * This plugin wraps the text output of another command (plugin) in HTML <A>
13 * tags. This plugin returns the status of the invoked plugin.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 *****************************************************************************/
32 const char *progname
= "urlize";
33 const char *copyright
= "2000-2006";
34 const char *email
= "devel@monitoring-plugins.org";
40 #define PERF_CHARACTER "|"
41 #define NEWLINE_CHARACTER '\n'
43 void print_help (void);
44 void print_usage (void);
47 main (int argc
, char **argv
)
49 int found
= 0, result
= STATE_UNKNOWN
;
54 char tstr
[MAX_INPUT_BUFFER
];
58 static struct option longopts
[] = {
59 {"help", no_argument
, 0, 'h'},
60 {"version", no_argument
, 0, 'V'},
61 {"url", required_argument
, 0, 'u'},
65 setlocale (LC_ALL
, "");
66 bindtextdomain (PACKAGE
, LOCALEDIR
);
69 /* Need at least 2 args */
76 c
= getopt_long (argc
, argv
, "+hVu:", longopts
, &option
);
78 if (c
== -1 || c
== EOF
)
86 case 'V': /* version */
87 print_revision (progname
, NP_VERSION
);
91 url
= strdup (argv
[optind
]);
100 url
= strdup (argv
[optind
++]);
102 cmd
= strdup (argv
[optind
++]);
103 for (c
= optind
; c
< argc
; c
++) {
104 xasprintf (&cmd
, "%s %s", cmd
, argv
[c
]);
107 child_process
= spopen (cmd
);
108 if (child_process
== NULL
) {
109 printf (_("Could not open pipe: %s\n"), cmd
);
110 exit (STATE_UNKNOWN
);
113 child_stderr
= fdopen (child_stderr_array
[fileno (child_process
)], "r");
114 if (child_stderr
== NULL
) {
115 printf (_("Could not open stderr for %s\n"), cmd
);
118 bzero(tstr
, sizeof(tstr
));
119 buf
= malloc(MAX_INPUT_BUFFER
);
120 printf ("<A href=\"%s\">", argv
[1]);
121 while (fgets (buf
, MAX_INPUT_BUFFER
- 1, child_process
)) {
123 /* Collect the string in temp str so we can tokenize */
129 _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"),
133 /* chop the newline character */
134 if ((nstr
= strchr(tstr
, NEWLINE_CHARACTER
)) != NULL
)
137 /* tokenize the string for Perfdata if there is some */
138 nstr
= strtok(tstr
, PERF_CHARACTER
);
141 nstr
= strtok(NULL
, PERF_CHARACTER
);
143 printf (" | %s", nstr
);
146 result
= spclose (child_process
);
148 /* WARNING if output found on stderr */
149 if (fgets (buf
, MAX_INPUT_BUFFER
- 1, child_stderr
))
150 result
= max_state (result
, STATE_WARNING
);
153 (void) fclose (child_stderr
);
163 print_revision (progname
, NP_VERSION
);
165 printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
166 printf (COPYRIGHT
, copyright
, email
);
168 printf ("%s\n", _("This plugin wraps the text output of another command (plugin) in HTML <A>"));
169 printf ("%s\n", _("tags, thus displaying the child plugin's output as a clickable link in compatible"));
170 printf ("%s\n", _("monitoring status screen. This plugin returns the status of the invoked plugin."));
176 printf (UT_HELP_VRSN
);
179 printf ("%s\n", _("Examples:"));
180 printf ("%s\n", _("Pay close attention to quoting to ensure that the shell passes the expected"));
181 printf ("%s\n\n", _("data to the plugin. For example, in:"));
182 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r 'two words'"));
183 printf (" %s\n", _("the shell will remove the single quotes and urlize will see:"));
184 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r two words"));
185 printf (" %s\n\n", _("You probably want:"));
186 printf (" %s\n", _("urlize http://example.com/ \"check_http -H example.com -r 'two words'\""));
196 printf ("%s\n", _("Usage:"));
197 printf ("%s <url> <plugin> <arg1> ... <argN>\n", progname
);