1 /*****************************************************************************
6 * Copyright (c) 2000-2007 Nagios 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, thus displaying the child plugin's output as a clickable link in the
14 * Nagios status screen. This plugin returns the status of the invoked plugin.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 *****************************************************************************/
33 const char *progname
= "urlize";
34 const char *copyright
= "2000-2006";
35 const char *email
= "nagiosplug-devel@lists.sourceforge.net";
41 #define PERF_CHARACTER "|"
42 #define NEWLINE_CHARACTER '\n'
44 void print_help (void);
45 void print_usage (void);
48 main (int argc
, char **argv
)
50 int found
= 0, result
= STATE_UNKNOWN
;
55 char tstr
[MAX_INPUT_BUFFER
];
59 static struct option longopts
[] = {
60 {"help", no_argument
, 0, 'h'},
61 {"version", no_argument
, 0, 'V'},
62 {"url", required_argument
, 0, 'u'},
66 setlocale (LC_ALL
, "");
67 bindtextdomain (PACKAGE
, LOCALEDIR
);
70 /* Need at least 2 args */
77 c
= getopt_long (argc
, argv
, "+hVu:", longopts
, &option
);
79 if (c
== -1 || c
== EOF
)
87 case 'V': /* version */
88 print_revision (progname
, NP_VERSION
);
92 url
= strdup (argv
[optind
]);
101 url
= strdup (argv
[optind
++]);
103 cmd
= strdup (argv
[optind
++]);
104 for (c
= optind
; c
< argc
; c
++) {
105 xasprintf (&cmd
, "%s %s", cmd
, argv
[c
]);
108 child_process
= spopen (cmd
);
109 if (child_process
== NULL
) {
110 printf (_("Could not open pipe: %s\n"), cmd
);
111 exit (STATE_UNKNOWN
);
114 child_stderr
= fdopen (child_stderr_array
[fileno (child_process
)], "r");
115 if (child_stderr
== NULL
) {
116 printf (_("Could not open stderr for %s\n"), cmd
);
119 bzero(tstr
, sizeof(tstr
));
120 buf
= malloc(MAX_INPUT_BUFFER
);
121 printf ("<A href=\"%s\">", argv
[1]);
122 while (fgets (buf
, MAX_INPUT_BUFFER
- 1, child_process
)) {
124 /* Collect the string in temp str so we can tokenize */
130 _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"),
134 /* chop the newline character */
135 if ((nstr
= strchr(tstr
, NEWLINE_CHARACTER
)) != NULL
)
138 /* tokenize the string for Perfdata if there is some */
139 nstr
= strtok(tstr
, PERF_CHARACTER
);
142 nstr
= strtok(NULL
, PERF_CHARACTER
);
144 printf (" | %s", nstr
);
147 result
= spclose (child_process
);
149 /* WARNING if output found on stderr */
150 if (fgets (buf
, MAX_INPUT_BUFFER
- 1, child_stderr
))
151 result
= max_state (result
, STATE_WARNING
);
154 (void) fclose (child_stderr
);
164 print_revision (progname
, NP_VERSION
);
166 printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
167 printf (COPYRIGHT
, copyright
, email
);
169 printf ("%s\n", _("This plugin wraps the text output of another command (plugin)"));
170 printf ("%s\n", _("in HTML <A> tags, thus displaying the child plugin's output as a clickable link in"));
171 printf ("%s\n", _("the Nagios status screen. This plugin returns the status of the invoked plugin."));
177 printf (UT_HELP_VRSN
);
180 printf ("%s\n", _("Examples:"));
181 printf ("%s\n", _("Pay close attention to quoting to ensure that the shell passes the expected"));
182 printf ("%s\n\n", _("data to the plugin. For example, in:"));
183 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r 'two words'"));
184 printf (" %s\n", _("the shell will remove the single quotes and urlize will see:"));
185 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r two words"));
186 printf (" %s\n\n", _("You probably want:"));
187 printf (" %s\n", _("urlize http://example.com/ \"check_http -H example.com -r 'two words'\""));
197 printf ("%s\n", _("Usage:"));
198 printf ("%s <url> <plugin> <arg1> ... <argN>\n", progname
);