summaryrefslogtreecommitdiffstats
path: root/plugins/urlize.c
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
committerEthan Galstad <egalstad@users.sourceforge.net>2002-02-28 06:42:51 (GMT)
commit44a321cb8a42d6c0ea2d96a1086a17f2134c89cc (patch)
treea1a4d9f7b92412a17ab08f34f04eec45433048b7 /plugins/urlize.c
parent54fd5d7022ff2d6a59bc52b8869182f3fc77a058 (diff)
downloadmonitoring-plugins-44a321cb8a42d6c0ea2d96a1086a17f2134c89cc.tar.gz
Initial revision
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/urlize.c')
-rw-r--r--plugins/urlize.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/plugins/urlize.c b/plugins/urlize.c
new file mode 100644
index 0000000..83c37da
--- /dev/null
+++ b/plugins/urlize.c
@@ -0,0 +1,141 @@
1/******************************************************************************
2 *
3 * urlize.c
4 *
5 * Program: plugin wrapper for Nagios
6 * License: GPL
7 * Copyright (c) 2000 Karl DeBisschop (kdebiss@alum.mit.edu)
8 *
9 * Last Modified: $Date$
10 * 2000-06-01 Karl DeBisschop <karl@debisschop.net>
11 * Written based of concept in urlize.pl
12 *
13 * Usage: urlize <url> <plugin> <arg1> ... <argN>
14 *
15 * Description:
16 *
17 * This plugin wraps the text output of another command (plugin) in HTML
18 * <A> tags, thus displaying the plugin output in as a clickable link in
19 * the Nagios status screen. The return status is the same as the plugin
20 * invoked by urlize
21 *
22 * License Information:
23 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 *
38 *****************************************************************************/
39
40#include "common.h"
41#include "utils.h"
42#include "popen.h"
43
44void print_usage (char *);
45void print_help (char *);
46
47int
48main (int argc, char **argv)
49{
50 int i = 0, found = 0, result = STATE_UNKNOWN;
51 char command_line[MAX_INPUT_BUFFER] = "";
52 char input_buffer[MAX_INPUT_BUFFER];
53
54 if (argc < 2) {
55 print_usage (my_basename (argv[0]));
56 exit (STATE_UNKNOWN);
57 }
58
59 if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) {
60 print_help (argv[0]);
61 exit (STATE_OK);
62 }
63
64 if (!strcmp (argv[1], "-V") || !strcmp (argv[1], "--version")) {
65 print_revision (my_basename (argv[0]), "$Revision$");
66 exit (STATE_OK);
67 }
68
69 if (argc < 2) {
70 print_usage (my_basename (argv[0]));
71 exit (STATE_UNKNOWN);
72 }
73
74 sprintf (command_line, "%s", argv[2]);
75 for (i = 3; i < argc; i++) {
76 sprintf (command_line, "%s %s", command_line, argv[i]);
77 }
78
79 child_process = spopen (command_line);
80 if (child_process == NULL) {
81 printf ("Could not open pipe: %s\n", command_line);
82 exit (STATE_UNKNOWN);
83 }
84
85 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
86 if (child_stderr == NULL) {
87 printf ("Could not open stderr for %s\n", command_line);
88 }
89
90 printf ("<A href=\"%s\">", argv[1]);
91 while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
92 found++;
93 if (index (input_buffer, '\n')) {
94 input_buffer[strcspn (input_buffer, "\n")] = 0;
95 printf ("%s", input_buffer);
96 }
97 else {
98 printf ("%s", input_buffer);
99 }
100 }
101
102 if (!found) {
103 printf ("%s problem - No data recieved from host\nCMD: %s\n", argv[0],
104 command_line);
105 exit (STATE_UNKNOWN);
106 }
107
108 /* close the pipe */
109 result = spclose (child_process);
110
111 /* WARNING if output found on stderr */
112 if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
113 result = max (result, STATE_WARNING);
114
115 /* close stderr */
116 (void) fclose (child_stderr);
117
118 printf ("</A>\n");
119 return result;
120}
121
122void
123print_usage (char *cmd)
124{
125 printf ("Usage:\n %s <url> <plugin> <arg1> ... <argN>\n",
126 my_basename (cmd));
127}
128
129void
130print_help (char *cmd)
131{
132 print_revision ("urlize", "$Revision$");
133 printf
134 ("Copyright (c) 2000 Karl DeBisschop (kdebiss@alum.mit.edu)\n\n"
135 "\nThis plugin wraps the text output of another command (plugin) in HTML\n"
136 "<A> tags, thus displaying the plugin output in as a clickable link in\n"
137 "the Nagios status screen. The return status is the same as the invoked\n"
138 "plugin.\n\n");
139 print_usage (cmd);
140 exit (STATE_OK);
141}