1 Index: smallapp/unbound-host.c
2 ===================================================================
3 --- smallapp/unbound-host.c (revision 2115)
4 +++ smallapp/unbound-host.c (working copy)
6 #include "libunbound/unbound.h"
9 +/** status variable ala nagios */
10 +#define FINAL_STATUS_OK 0
11 +#define FINAL_STATUS_WARNING 1
12 +#define FINAL_STATUS_CRITICAL 2
13 +#define FINAL_STATUS_UNKNOWN 3
15 /** verbosity for unbound-host app */
18 +/** variable to determine final output */
19 +static int final_status = FINAL_STATUS_UNKNOWN;
21 /** Give unbound-host usage, and exit (1). */
25 printf("Version %s\n", PACKAGE_VERSION);
26 printf("BSD licensed, see LICENSE in source package for details.\n");
27 printf("Report bugs to %s\n", PACKAGE_BUGREPORT);
29 + exit(FINAL_STATUS_UNKNOWN);
32 /** determine if str is ip4 and put into reverse lookup format */
36 fprintf(stderr, "error: out of memory\n");
38 + exit(FINAL_STATUS_UNKNOWN);
45 fprintf(stderr, "error: out of memory\n");
47 + exit(FINAL_STATUS_UNKNOWN);
52 if(r == 0 && strcasecmp(t, "TYPE0") != 0 &&
54 fprintf(stderr, "error unknown type %s\n", t);
56 + exit(FINAL_STATUS_UNKNOWN);
61 if(r == 0 && strcasecmp(c, "CLASS0") != 0 &&
63 fprintf(stderr, "error unknown class %s\n", c);
65 + exit(FINAL_STATUS_UNKNOWN);
73 +/** update the final status for the exit code */
75 +update_final_status(struct ub_result* result)
77 + if (final_status == FINAL_STATUS_UNKNOWN || final_status == FINAL_STATUS_OK) {
78 + if (result->secure) final_status = FINAL_STATUS_OK;
79 + else if (result->bogus) final_status = FINAL_STATUS_CRITICAL;
80 + else final_status = FINAL_STATUS_WARNING;
82 + else if (final_status == FINAL_STATUS_WARNING && result->bogus)
83 + final_status = FINAL_STATUS_CRITICAL;
86 /** nice string for type */
88 pretty_type(char* s, size_t len, int t)
91 fprintf(stderr, "could not parse "
92 "reply packet to ANY query\n");
94 + exit(FINAL_STATUS_UNKNOWN);
99 ret = ub_resolve(ctx, q, t, c, &result);
101 fprintf(stderr, "resolve error: %s\n", ub_strerror(ret));
103 + exit(FINAL_STATUS_UNKNOWN);
105 pretty_output(q, t, c, result, docname);
106 + update_final_status(result);
107 ret = result->nxdomain;
108 ub_resolve_free(result);
113 fprintf(stderr, "error: %s\n", ub_strerror(r));
115 + exit(FINAL_STATUS_UNKNOWN);
120 ctx = ub_ctx_create();
122 fprintf(stderr, "error: out of memory\n");
124 + exit(FINAL_STATUS_UNKNOWN);
127 /* parse the options */
131 lookup(ctx, argv[0], qtype, qclass);
133 + return final_status;