mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-17 00:06:59 +00:00
output: make output_analysis() to be regular function
This commit makes it possible to define alarming thresholds at the same time with other output formats. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
9deeae8c36
commit
abf5d04736
4 changed files with 73 additions and 74 deletions
|
|
@ -73,7 +73,6 @@ double (*get_range_size) (const struct range_t *r);
|
|||
int (*xstrstr) (const char *restrict str);
|
||||
int (*ipcomp) (const union ipaddr_t *restrict a, const union ipaddr_t *restrict b);
|
||||
int (*leasecomp) (const struct leases_t *restrict a, const struct leases_t *restrict b);
|
||||
int (*output_analysis) (void);
|
||||
void (*add_lease) (union ipaddr_t *ip, enum ltype type);
|
||||
struct leases_t *(*find_lease) (union ipaddr_t *ip);
|
||||
|
||||
|
|
@ -99,8 +98,9 @@ static int return_limit(const char c)
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
int option_index = 0;
|
||||
char output_format = '\0';
|
||||
int alarming = 0;
|
||||
char const *tmp;
|
||||
const char *print_mac_addreses_tmp;
|
||||
struct range_t *tmp_ranges;
|
||||
enum {
|
||||
OPT_SNET_ALARMS = CHAR_MAX + 1,
|
||||
|
|
@ -159,8 +159,6 @@ int main(int argc, char **argv)
|
|||
config.header_limit = (*tmp - '0');
|
||||
tmp++;
|
||||
config.number_limit = (*tmp - '0');
|
||||
/* Make sure some output format is selected by default */
|
||||
print_mac_addreses_tmp = OUTPUT_FORMAT;
|
||||
/* Default sort order is by IPs small to big */
|
||||
config.reverse_order = 0;
|
||||
config.backups_found = 0;
|
||||
|
|
@ -186,7 +184,7 @@ int main(int argc, char **argv)
|
|||
break;
|
||||
case 'f':
|
||||
/* Output format */
|
||||
print_mac_addreses_tmp = optarg;
|
||||
output_format = optarg[0];
|
||||
break;
|
||||
case 's':
|
||||
{
|
||||
|
|
@ -225,19 +223,19 @@ int main(int argc, char **argv)
|
|||
config.snet_alarms = 1;
|
||||
break;
|
||||
case OPT_WARN:
|
||||
print_mac_addreses_tmp = "a";
|
||||
alarming = 1;
|
||||
config.warning = strtod_or_err(optarg, "illegal argument");
|
||||
break;
|
||||
case OPT_CRIT:
|
||||
print_mac_addreses_tmp = "a";
|
||||
alarming = 1;
|
||||
config.critical = strtod_or_err(optarg, "illegal argument");
|
||||
break;
|
||||
case OPT_WARN_COUNT:
|
||||
print_mac_addreses_tmp = "a";
|
||||
alarming = 1;
|
||||
config.warn_count = strtod_or_err(optarg, "illegal argument");
|
||||
break;
|
||||
case OPT_CRIT_COUNT:
|
||||
print_mac_addreses_tmp = "a";
|
||||
alarming = 1;
|
||||
config.crit_count = strtod_or_err(optarg, "illegal argument");
|
||||
break;
|
||||
case OPT_MINSIZE:
|
||||
|
|
@ -274,50 +272,22 @@ int main(int argc, char **argv)
|
|||
program_name);
|
||||
}
|
||||
}
|
||||
/* Output function selection */
|
||||
switch (print_mac_addreses_tmp[0]) {
|
||||
case 't':
|
||||
output_analysis = output_txt;
|
||||
config.print_mac_addreses = 0;
|
||||
break;
|
||||
case 'a':
|
||||
output_analysis = output_alarming;
|
||||
config.print_mac_addreses = 0;
|
||||
break;
|
||||
case 'h':
|
||||
error(EXIT_FAILURE, 0, "html table only output format is deprecated");
|
||||
break;
|
||||
case 'H':
|
||||
output_analysis = output_html;
|
||||
config.print_mac_addreses = 0;
|
||||
break;
|
||||
case 'x':
|
||||
output_analysis = output_xml;
|
||||
config.print_mac_addreses = 0;
|
||||
break;
|
||||
case 'X':
|
||||
output_analysis = output_xml;
|
||||
config.print_mac_addreses = 1;
|
||||
break;
|
||||
case 'j':
|
||||
output_analysis = output_json;
|
||||
config.print_mac_addreses = 0;
|
||||
break;
|
||||
case 'J':
|
||||
output_analysis = output_json;
|
||||
config.print_mac_addreses = 1;
|
||||
break;
|
||||
case 'c':
|
||||
output_analysis = output_csv;
|
||||
config.print_mac_addreses = 0;
|
||||
break;
|
||||
default:
|
||||
clean_up();
|
||||
error(EXIT_FAILURE, 0, "unknown output format: %s", quote(print_mac_addreses_tmp));
|
||||
/* Output format is not defined, if alarm thresholds are then it's
|
||||
* alarming, else use the default. */
|
||||
if (output_format == '\0') {
|
||||
if (alarming == 1)
|
||||
output_format = 'a';
|
||||
else {
|
||||
const char *const def = OUTPUT_FORMAT;
|
||||
output_format = def[0];
|
||||
}
|
||||
}
|
||||
/* Do the job */
|
||||
parse_config(1, config.dhcpdconf_file, shared_networks);
|
||||
parse_leases();
|
||||
if (output_format == 'X' || output_format == 'J')
|
||||
parse_leases(1);
|
||||
else
|
||||
parse_leases(0);
|
||||
prepare_data();
|
||||
do_counting();
|
||||
tmp_ranges = xmalloc(sizeof(struct range_t) * num_ranges);
|
||||
|
|
@ -326,7 +296,7 @@ int main(int argc, char **argv)
|
|||
if (config.reverse_order == 1)
|
||||
flip_ranges(ranges, tmp_ranges);
|
||||
free(tmp_ranges);
|
||||
ret_val = output_analysis();
|
||||
ret_val = output_analysis(output_format);
|
||||
clean_up();
|
||||
return (ret_val);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue