1 /*****************************************************************************
6 * Copyright (c) 2000-2007 Nagios Plugins Development Team
8 * Last Modified: $Date$
12 * This file contains the urlize plugin
14 * This plugin wraps the text output of another command (plugin) in HTML <A>
15 * tags, thus displaying the plugin output in as a clickable link in the
16 * Nagios status screen. The return status is the same as the invoked plugin.
19 * This program is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 *****************************************************************************/
36 const char *progname
= "urlize";
37 const char *revision
= "$Revision$";
38 const char *copyright
= "2000-2006";
39 const char *email
= "nagiosplug-devel@lists.sourceforge.net";
45 #define PERF_CHARACTER "|"
46 #define NEWLINE_CHARACTER '\n'
48 void print_help (void);
49 void print_usage (void);
52 main (int argc
, char **argv
)
54 int found
= 0, result
= STATE_UNKNOWN
;
59 char tstr
[MAX_INPUT_BUFFER
];
63 static struct option longopts
[] = {
64 {"help", no_argument
, 0, 'h'},
65 {"version", no_argument
, 0, 'V'},
66 {"url", required_argument
, 0, 'u'},
70 setlocale (LC_ALL
, "");
71 bindtextdomain (PACKAGE
, LOCALEDIR
);
74 /* Need at least 2 args */
81 c
= getopt_long (argc
, argv
, "+hVu:", longopts
, &option
);
83 if (c
== -1 || c
== EOF
)
91 case 'V': /* version */
92 print_revision (progname
, revision
);
96 url
= strdup (argv
[optind
]);
105 url
= strdup (argv
[optind
++]);
107 cmd
= strdup (argv
[optind
++]);
108 for (c
= optind
; c
< argc
; c
++) {
109 asprintf (&cmd
, "%s %s", cmd
, argv
[c
]);
112 child_process
= spopen (cmd
);
113 if (child_process
== NULL
) {
114 printf (_("Could not open pipe: %s\n"), cmd
);
115 exit (STATE_UNKNOWN
);
118 child_stderr
= fdopen (child_stderr_array
[fileno (child_process
)], "r");
119 if (child_stderr
== NULL
) {
120 printf (_("Could not open stderr for %s\n"), cmd
);
123 bzero(tstr
, sizeof(tstr
));
124 buf
= malloc(MAX_INPUT_BUFFER
);
125 printf ("<A href=\"%s\">", argv
[1]);
126 while (fgets (buf
, MAX_INPUT_BUFFER
- 1, child_process
)) {
128 /* Collect the string in temp str so we can tokenize */
134 _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"),
138 /* chop the newline character */
139 if ((nstr
= strchr(tstr
, NEWLINE_CHARACTER
)) != NULL
)
142 /* tokenize the string for Perfdata if there is some */
143 nstr
= strtok(tstr
, PERF_CHARACTER
);
146 nstr
= strtok(NULL
, PERF_CHARACTER
);
148 printf (" | %s", nstr
);
151 result
= spclose (child_process
);
153 /* WARNING if output found on stderr */
154 if (fgets (buf
, MAX_INPUT_BUFFER
- 1, child_stderr
))
155 result
= max_state (result
, STATE_WARNING
);
158 (void) fclose (child_stderr
);
168 print_revision (progname
, revision
);
170 printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
171 printf (COPYRIGHT
, copyright
, email
);
173 printf ("%s\n", _("This plugin wraps the text output of another command (plugin)"));
174 printf ("%s\n", _("in HTML <A> tags, thus displaying the plugin output in as a clickable link in"));
175 printf ("%s\n", _("the Nagios status screen. The return status is the same as the invoked plugin."));
181 printf (_(UT_HELP_VRSN
));
184 printf ("%s\n", _("Examples:"));
185 printf ("%s\n", _("Pay close attention to quoting to ensure that the shell passes the expected"));
186 printf ("%s\n\n", _("data to the plugin. For example, in:"));
187 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r 'two words'"));
188 printf (" %s\n", _("the shell will remove the single quotes and urlize will see:"));
189 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r two words"));
190 printf (" %s\n\n", _("You probably want:"));
191 printf (" %s\n", _("urlize http://example.com/ \"check_http -H example.com -r 'two words'\""));
193 printf (_(UT_SUPPORT
));
201 printf (_("Usage:"));
202 printf ("%s <url> <plugin> <arg1> ... <argN>\n", progname
);