[prev in list] [next in list] [prev in thread] [next in thread]
List: netsaintplug-devel
Subject: Re: [Netsaintplug-devel] Request for change on some utils.
From: "David Allan" <dave () airflash ! com>
Date: 2001-04-27 17:01:39
[Download RAW message or body]
Ok, after way too long, I've patched check_disk to create an --output-flags option. \
The patch file is attached. I'm a sysadmin, not a C programmer, so I'd like someone \
who really is a programmer to give me feedback on it. In particular, there is a \
switch block that I don't understand the purpose of--I've inserted a comment into the \
code at that point. It builds on Linux and Solaris, however, and seems to work ok on \
those platforms as well.
Dave
Karl DeBisschop wrote:
> David Allan wrote:
> >
> > Thinking about features for the check_disk plugin, it would be great to be able \
> > to limit the information it outputs to have the option for nothing but DISK OK
> > or just some middle ground like
> > DISK OK 100%, 67%, 36%, 100%, 21%, 15%, 52% ... free
> > or everything below.
> >
> > I'll try to look at this myself this week, but it's shaping up to be a crowded \
> > week.
>
> If you get a chance to look, that would be great. I was thinking of an option like
>
> --output-format=lufp
>
> would show the label, the used and free space, and the percentage free. Then you \
> could omit any of the flags that you wished to.
> But I'm sure there are other more elegant ways to specify the behaviour, all the \
> way up to a printf style formatted output. All depends on who has the time to write \
> it.
> BTW, this would count as a new feature, not a bug fix. So for anyone following the \
> thread, your chances of getting contributed code added to the plugins are high if \
> you submit patches against the head of the CVS tree. Your chances are much lower \
> you if you patch against 1.2.9 releases or the r129 CVS branch.
> --
> Karl
>
> _______________________________________________
> Netsaintplug-devel mailing list
> Netsaintplug-devel@lists.sourceforge.net
> http://lists.sourceforge.net/lists/listinfo/netsaintplug-devel
["pat.file" (text/plain)]
--- check_disk.c.vanilla Thu Apr 26 18:57:29 2001
+++ check_disk.c Thu Apr 26 21:46:27 2001
@@ -53,2 +53,8 @@
int verbose = FALSE;
+int output_flags = FALSE;
+int output_flag_n = FALSE;
+int output_flag_l = FALSE;
+int output_flag_u = FALSE;
+int output_flag_f = FALSE;
+int output_flag_p = FALSE;
@@ -99,8 +105,44 @@
result = max (result, check_disk (usp, free_disk));
- len =
- snprintf (outbuf, MAX_INPUT_BUFFER - 1,
- " [%d kB (%d%%) free on %s]", free_disk, 100 - usp,
- file_system);
- outbuf[len] = 0;
- output = strscat (output, outbuf);
+
+ if (output_flags && !output_flag_n) {
+ len = snprintf (outbuf, MAX_INPUT_BUFFER - 1, " [");
+ outbuf[len] = 0;
+ output = strscat (output, outbuf);
+ if (output_flag_l) {
+ len = snprintf (outbuf, MAX_INPUT_BUFFER - 1, " %s", file_system);
+ outbuf[len] = 0;
+ output = strscat (output, outbuf);
+ }
+ if (output_flag_u) {
+ len = (len + snprintf (outbuf, MAX_INPUT_BUFFER - 1, " %d KB used", used_disk));
+ outbuf[len] = 0;
+ output = strscat (output, outbuf);
+ }
+ if (output_flag_f) {
+ len = (len + snprintf (outbuf, MAX_INPUT_BUFFER - 1, " %d KB free", free_disk));
+ outbuf[len] = 0;
+ output = strscat (output, outbuf);
+ }
+ if (output_flag_p) {
+ len = (len + snprintf (outbuf, MAX_INPUT_BUFFER - 1, " %d%% free", 100 - usp));
+ outbuf[len] = 0;
+ output = strscat (output, outbuf);
+ }
+ len = (len + snprintf (outbuf, MAX_INPUT_BUFFER - 1, " ]"));
+ outbuf[len] = 0;
+ output = strscat (output, outbuf);
+ }
+
+ if (output_flag_n) {
+ len = snprintf (outbuf, MAX_INPUT_BUFFER - 1, " ");
+ outbuf[len] = 0;
+ output = strscat (output, outbuf);
+ }
+
+ if (!output_flags) {
+ len = snprintf (outbuf, MAX_INPUT_BUFFER - 1, " [%d kB (%d%%) free on %s]",
+ free_disk, 100 - usp, file_system);
+ outbuf[len] = 0;
+ output = strscat (output, outbuf);
+ }
}
@@ -128,3 +170,3 @@
else
- printf ("DISK %s -%s\n", state_text (result), output);
+ printf ("DISK(S) %s %s\n", state_text (result), output);
@@ -182,2 +224,3 @@
{"partition", required_argument, 0, 'p'},
+ {"output-flags", required_argument, 0, 'o'},
{"verbose", no_argument, 0, 'v'},
@@ -192,5 +235,5 @@
c =
- getopt_long (argc, argv, "+?Vhvt:c:w:p:", long_options, &option_index);
+ getopt_long (argc, argv, "+?Vhvt:c:w:p:o:", long_options, &option_index);
#else
- c = getopt (argc, argv, "+?Vhvt:c:w:p:");
+ c = getopt (argc, argv, "+?Vhvt:c:w:p:o:");
#endif
@@ -207,2 +250,3 @@
case 'p':
+/* Should 'o' be included here? What does this switch block do? */
i++;
@@ -260,2 +304,25 @@
exit (STATE_OK);
+ case 'o': /* flags */
+ if (strpbrk (optarg, "nlufp")) {
+ output_flags = TRUE;
+ if (strchr (optarg, 'l')) {
+ output_flag_l = TRUE;
+ }
+ if (strchr (optarg, 'u')) {
+ output_flag_u = TRUE;
+ }
+ if (strchr (optarg, 'f')) {
+ output_flag_f = TRUE;
+ }
+ if (strchr (optarg, 'p')) {
+ output_flag_p = TRUE;
+ }
+ if (strchr (optarg, 'n')) {
+ output_flag_n = TRUE;
+ }
+ }
+ else {
+ usage ("Output flags must be one of: nlufp\n");
+ }
+ break;
case 'h': /* help */
@@ -339,2 +406,5 @@
" Show details for command-line debugging (do not use with netsaint server)\n"
+ " -o, --output-flags=[nlufp]\n"
+ " Show one or more of none, label, used space, free space and percent free\n"
+ " Shows all information if unspecified. n shows no info beyond disk status\n"
" -h, --help\n"
@@ -349,3 +419,3 @@
printf
- ("Usage: %s -w limit -c limit [-p path] [-t timeout] [--verbose]\n"
+ ("Usage: %s -w limit -c limit [-p path] [-t timeout] [-o args] [--verbose]\n"
" %s (-h|--help)\n"
_______________________________________________
Netsaintplug-devel mailing list
Netsaintplug-devel@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/netsaintplug-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic