1 /******************************************************************************
6 * Copyright (c) 2000-2006 nagios-plugins team
8 * Last Modified: $Date$
12 * This file contains the urlize plugin
14 * This plugin wraps the text output of another command (plugin)
15 * in HTML <A> tags, thus displaying the plugin output in as a clickable link in
16 * the Nagios status screen. The return status is the same as the invoked plugin.
18 * License Information:
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 ******************************************************************************/
39 const char *progname
= "urlize";
40 const char *revision
= "$Revision$";
41 const char *copyright
= "2000-2006";
42 const char *email
= "nagiosplug-devel@lists.sourceforge.net";
48 #define PERF_CHARACTER "|"
49 #define NEWLINE_CHARACTER '\n'
51 void print_help (void);
52 void print_usage (void);
55 main (int argc
, char **argv
)
57 int found
= 0, result
= STATE_UNKNOWN
;
62 char tstr
[MAX_INPUT_BUFFER
];
66 static struct option longopts
[] = {
67 {"help", no_argument
, 0, 'h'},
68 {"version", no_argument
, 0, 'V'},
69 {"url", required_argument
, 0, 'u'},
73 setlocale (LC_ALL
, "");
74 bindtextdomain (PACKAGE
, LOCALEDIR
);
77 /* Need at least 2 args */
84 c
= getopt_long (argc
, argv
, "+hVu:", longopts
, &option
);
86 if (c
== -1 || c
== EOF
)
94 case 'V': /* version */
95 print_revision (progname
, revision
);
99 url
= strdup (argv
[optind
]);
108 url
= strdup (argv
[optind
++]);
110 cmd
= strdup (argv
[optind
++]);
111 for (c
= optind
; c
< argc
; c
++) {
112 asprintf (&cmd
, "%s %s", cmd
, argv
[c
]);
115 child_process
= spopen (cmd
);
116 if (child_process
== NULL
) {
117 printf (_("Could not open pipe: %s\n"), cmd
);
118 exit (STATE_UNKNOWN
);
121 child_stderr
= fdopen (child_stderr_array
[fileno (child_process
)], "r");
122 if (child_stderr
== NULL
) {
123 printf (_("Could not open stderr for %s\n"), cmd
);
126 bzero(tstr
, sizeof(tstr
));
127 buf
= malloc(MAX_INPUT_BUFFER
);
128 printf ("<A href=\"%s\">", argv
[1]);
129 while (fgets (buf
, MAX_INPUT_BUFFER
- 1, child_process
)) {
131 /* Collect the string in temp str so we can tokenize */
137 _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"),
141 /* chop the newline character */
142 if ((nstr
= strchr(tstr
, NEWLINE_CHARACTER
)) != NULL
)
145 /* tokenize the string for Perfdata if there is some */
146 nstr
= strtok(tstr
, PERF_CHARACTER
);
149 nstr
= strtok(NULL
, PERF_CHARACTER
);
151 printf (" | %s", nstr
);
154 result
= spclose (child_process
);
156 /* WARNING if output found on stderr */
157 if (fgets (buf
, MAX_INPUT_BUFFER
- 1, child_stderr
))
158 result
= max_state (result
, STATE_WARNING
);
161 (void) fclose (child_stderr
);
171 print_revision (progname
, revision
);
173 printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
174 printf (COPYRIGHT
, copyright
, email
);
176 printf ("%s\n", _("This plugin wraps the text output of another command (plugin)"));
177 printf ("%s\n", _("in HTML <A> tags, thus displaying the plugin output in as a clickable link in"));
178 printf ("%s\n", _("the Nagios status screen. The return status is the same as the invoked plugin."));
184 printf (_(UT_HELP_VRSN
));
187 printf ("%s\n", _("Examples:"));
188 printf ("%s\n", _("Pay close attention to quoting to ensure that the shell passes the expected"));
189 printf ("%s\n\n", _("data to the plugin. For example, in:"));
190 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r 'two words'"));
191 printf (" %s\n", _("the shell will remove the single quotes and urlize will see:"));
192 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r two words"));
193 printf (" %s\n\n", _("You probably want:"));
194 printf (" %s\n", _("urlize http://example.com/ \"check_http -H example.com -r 'two words'\""));
196 printf (_(UT_SUPPORT
));
204 printf (_("Usage:"));
205 printf ("%s <url> <plugin> <arg1> ... <argN>\n", progname
);