summaryrefslogtreecommitdiffstats
path: root/plugins/urlize.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/urlize.c')
-rw-r--r--plugins/urlize.c219
1 files changed, 107 insertions, 112 deletions
diff --git a/plugins/urlize.c b/plugins/urlize.c
index 6fda72d1..a8590fae 100644
--- a/plugins/urlize.c
+++ b/plugins/urlize.c
@@ -1,51 +1,49 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring urlize plugin 3 * Monitoring urlize plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 2000-2007 Monitoring Plugins Development Team 6 * Copyright (c) 2000-2024 Monitoring Plugins Development Team
7* 7 *
8* Description: 8 * Description:
9* 9 *
10* This file contains the urlize plugin 10 * This file contains the urlize plugin
11* 11 *
12* This plugin wraps the text output of another command (plugin) in HTML <A> 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. 13 * tags. This plugin returns the status of the invoked plugin.
14* 14 *
15* 15 *
16* This program is free software: you can redistribute it and/or modify 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 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 18 * the Free Software Foundation, either version 3 of the License, or
19* (at your option) any later version. 19 * (at your option) any later version.
20* 20 *
21* This program is distributed in the hope that it will be useful, 21 * This program is distributed in the hope that it will be useful,
22* but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24* GNU General Public License for more details. 24 * GNU General Public License for more details.
25* 25 *
26* You should have received a copy of the GNU General Public License 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/>. 27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28* 28 *
29* 29 *
30*****************************************************************************/ 30 *****************************************************************************/
31 31
32const char *progname = "urlize"; 32const char *progname = "urlize";
33const char *copyright = "2000-2006"; 33const char *copyright = "2000-2024";
34const char *email = "devel@monitoring-plugins.org"; 34const char *email = "devel@monitoring-plugins.org";
35 35
36#include "common.h" 36#include "common.h"
37#include "utils.h" 37#include "utils.h"
38#include "popen.h" 38#include "popen.h"
39 39
40#define PERF_CHARACTER "|" 40#define PERF_CHARACTER "|"
41#define NEWLINE_CHARACTER '\n' 41#define NEWLINE_CHARACTER '\n'
42 42
43void print_help (void); 43void print_help(void);
44void print_usage (void); 44void print_usage(void);
45 45
46int 46int main(int argc, char **argv) {
47main (int argc, char **argv)
48{
49 int found = 0, result = STATE_UNKNOWN; 47 int found = 0, result = STATE_UNKNOWN;
50 char *url = NULL; 48 char *url = NULL;
51 char *cmd; 49 char *cmd;
@@ -55,144 +53,141 @@ main (int argc, char **argv)
55 53
56 int c; 54 int c;
57 int option = 0; 55 int option = 0;
58 static struct option longopts[] = { 56 static struct option longopts[] = {{"help", no_argument, 0, 'h'},
59 {"help", no_argument, 0, 'h'}, 57 {"version", no_argument, 0, 'V'},
60 {"version", no_argument, 0, 'V'}, 58 {"url", required_argument, 0, 'u'},
61 {"url", required_argument, 0, 'u'}, 59 {0, 0, 0, 0}};
62 {0, 0, 0, 0}
63 };
64 60
65 setlocale (LC_ALL, ""); 61 setlocale(LC_ALL, "");
66 bindtextdomain (PACKAGE, LOCALEDIR); 62 bindtextdomain(PACKAGE, LOCALEDIR);
67 textdomain (PACKAGE); 63 textdomain(PACKAGE);
68 64
69 /* Need at least 2 args */ 65 /* Need at least 2 args */
70 if (argc < 3) { 66 if (argc < 3) {
71 print_help(); 67 print_help();
72 exit (STATE_UNKNOWN); 68 exit(STATE_UNKNOWN);
73 } 69 }
74 70
75 while (1) { 71 while (1) {
76 c = getopt_long (argc, argv, "+hVu:", longopts, &option); 72 c = getopt_long(argc, argv, "+hVu:", longopts, &option);
77 73
78 if (c == -1 || c == EOF) 74 if (c == -1 || c == EOF) {
79 break; 75 break;
76 }
80 77
81 switch (c) { 78 switch (c) {
82 case 'h': /* help */ 79 case 'h': /* help */
83 print_help (); 80 print_help();
84 exit (EXIT_SUCCESS); 81 exit(EXIT_SUCCESS);
85 break; 82 break;
86 case 'V': /* version */ 83 case 'V': /* version */
87 print_revision (progname, NP_VERSION); 84 print_revision(progname, NP_VERSION);
88 exit (EXIT_SUCCESS); 85 exit(EXIT_SUCCESS);
89 break; 86 break;
90 case 'u': 87 case 'u':
91 url = strdup (argv[optind]); 88 url = strdup(argv[optind]);
92 break; 89 break;
93 case '?': 90 case '?':
94 default: 91 default:
95 usage5 (); 92 usage5();
96 } 93 }
97 } 94 }
98 95
99 if (url == NULL) 96 if (url == NULL) {
100 url = strdup (argv[optind++]); 97 url = strdup(argv[optind++]);
98 }
101 99
102 cmd = strdup (argv[optind++]); 100 cmd = strdup(argv[optind++]);
103 for (c = optind; c < argc; c++) { 101 for (c = optind; c < argc; c++) {
104 xasprintf (&cmd, "%s %s", cmd, argv[c]); 102 xasprintf(&cmd, "%s %s", cmd, argv[c]);
105 } 103 }
106 104
107 child_process = spopen (cmd); 105 child_process = spopen(cmd);
108 if (child_process == NULL) { 106 if (child_process == NULL) {
109 printf (_("Could not open pipe: %s\n"), cmd); 107 printf(_("Could not open pipe: %s\n"), cmd);
110 exit (STATE_UNKNOWN); 108 exit(STATE_UNKNOWN);
111 } 109 }
112 110
113 child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); 111 child_stderr = fdopen(child_stderr_array[fileno(child_process)], "r");
114 if (child_stderr == NULL) { 112 if (child_stderr == NULL) {
115 printf (_("Could not open stderr for %s\n"), cmd); 113 printf(_("Could not open stderr for %s\n"), cmd);
116 } 114 }
117 115
118 bzero(tstr, sizeof(tstr)); 116 bzero(tstr, sizeof(tstr));
119 buf = malloc(MAX_INPUT_BUFFER); 117 buf = malloc(MAX_INPUT_BUFFER);
120 printf ("<A href=\"%s\">", argv[1]); 118 printf("<A href=\"%s\">", argv[1]);
121 while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) { 119 while (fgets(buf, MAX_INPUT_BUFFER - 1, child_process)) {
122 found++; 120 found++;
123 /* Collect the string in temp str so we can tokenize */ 121 /* Collect the string in temp str so we can tokenize */
124 strcat(tstr, buf); 122 strcat(tstr, buf);
125 } 123 }
126 124
127 if (!found) 125 if (!found) {
128 die (STATE_UNKNOWN, 126 die(STATE_UNKNOWN, _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"), argv[0],
129 _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"), 127 cmd);
130 argv[0], cmd); 128 }
131
132 129
133 /* chop the newline character */ 130 /* chop the newline character */
134 if ((nstr = strchr(tstr, NEWLINE_CHARACTER)) != NULL) 131 if ((nstr = strchr(tstr, NEWLINE_CHARACTER)) != NULL) {
135 *nstr = '\0'; 132 *nstr = '\0';
133 }
136 134
137 /* tokenize the string for Perfdata if there is some */ 135 /* tokenize the string for Perfdata if there is some */
138 nstr = strtok(tstr, PERF_CHARACTER); 136 nstr = strtok(tstr, PERF_CHARACTER);
139 printf ("%s", nstr); 137 printf("%s", nstr);
140 printf ("</A>"); 138 printf("</A>");
141 nstr = strtok(NULL, PERF_CHARACTER); 139 nstr = strtok(NULL, PERF_CHARACTER);
142 if (nstr != NULL) 140 if (nstr != NULL) {
143 printf (" | %s", nstr); 141 printf(" | %s", nstr);
142 }
144 143
145 /* close the pipe */ 144 /* close the pipe */
146 result = spclose (child_process); 145 result = spclose(child_process);
147 146
148 /* WARNING if output found on stderr */ 147 /* WARNING if output found on stderr */
149 if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) 148 if (fgets(buf, MAX_INPUT_BUFFER - 1, child_stderr)) {
150 result = max_state (result, STATE_WARNING); 149 result = max_state(result, STATE_WARNING);
150 }
151 151
152 /* close stderr */ 152 /* close stderr */
153 (void) fclose (child_stderr); 153 (void)fclose(child_stderr);
154 154
155 return result; 155 return result;
156} 156}
157 157
158void print_help(void) {
159 print_revision(progname, NP_VERSION);
158 160
161 printf("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
162 printf(COPYRIGHT, copyright, email);
159 163
160void 164 printf("%s\n", _("This plugin wraps the text output of another command (plugin) in HTML <A>"));
161print_help (void) 165 printf("%s\n",
162{ 166 _("tags, thus displaying the child plugin's output as a clickable link in compatible"));
163 print_revision (progname, NP_VERSION); 167 printf("%s\n",
164 168 _("monitoring status screen. This plugin returns the status of the invoked plugin."));
165 printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
166 printf (COPYRIGHT, copyright, email);
167
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."));
171 169
172 printf ("\n\n"); 170 printf("\n\n");
173 171
174 print_usage (); 172 print_usage();
175 173
176 printf (UT_HELP_VRSN); 174 printf(UT_HELP_VRSN);
177 175
178 printf ("\n"); 176 printf("\n");
179 printf ("%s\n", _("Examples:")); 177 printf("%s\n", _("Examples:"));
180 printf ("%s\n", _("Pay close attention to quoting to ensure that the shell passes the expected")); 178 printf("%s\n",
181 printf ("%s\n\n", _("data to the plugin. For example, in:")); 179 _("Pay close attention to quoting to ensure that the shell passes the expected"));
182 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r 'two words'")); 180 printf("%s\n\n", _("data to the plugin. For example, in:"));
183 printf (" %s\n", _("the shell will remove the single quotes and urlize will see:")); 181 printf(" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r 'two words'"));
184 printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r two words")); 182 printf(" %s\n", _("the shell will remove the single quotes and urlize will see:"));
185 printf (" %s\n\n", _("You probably want:")); 183 printf(" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r two words"));
186 printf (" %s\n", _("urlize http://example.com/ \"check_http -H example.com -r 'two words'\"")); 184 printf(" %s\n\n", _("You probably want:"));
185 printf(" %s\n", _("urlize http://example.com/ \"check_http -H example.com -r 'two words'\""));
187 186
188 printf (UT_SUPPORT); 187 printf(UT_SUPPORT);
189} 188}
190 189
191 190void print_usage(void) {
192 191 printf("%s\n", _("Usage:"));
193void 192 printf("%s <url> <plugin> <arg1> ... <argN>\n", progname);
194print_usage (void)
195{
196 printf ("%s\n", _("Usage:"));
197 printf ("%s <url> <plugin> <arg1> ... <argN>\n", progname);
198} 193}