dhcpd-pools  3.0
ISC dhcpd lease usage analyser
Enumerations | Functions | Variables
output.c File Reference

All about output formats. More...

#include <config.h>
#include <arpa/inet.h>
#include <errno.h>
#include <inttypes.h>
#include <langinfo.h>
#include <locale.h>
#include <math.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include "close-stream.h"
#include "error.h"
#include "progname.h"
#include "strftime.h"
#include "dhcpd-pools.h"
Include dependency graph for output.c:

Enumerations

enum  colored_formats { OUT_FORM_TEXT, OUT_FORM_HTML, NUM_OF_OUT_FORMS }
 Enumeration of output formats. More...
 
enum  count_status_t {
  STATUS_OK, STATUS_WARN, STATUS_CRIT, STATUS_IGNORED,
  STATUS_SUPPRESSED, COLOR_RESET
}
 Enumeration of possible range and shared net statuses. More...
 

Functions

int range_output_helper (struct conf_t *state, struct output_helper_t *oh, struct range_t *range_p)
 Calculate range percentages and such. More...
 
int shnet_output_helper (struct conf_t *state, struct output_helper_t *oh, struct shared_network_t *shared_p)
 Calculate shared network percentages and such. More...
 
static int start_color (struct conf_t *state, struct output_helper_t *oh, FILE *outfile)
 Output a color based on output_helper_t status. More...
 
static FILE * open_outfile (struct conf_t *state)
 Helper function to open a output file. More...
 
static void close_outfile (FILE *outfile)
 Helper function to close outfile. More...
 
static int output_txt (struct conf_t *state)
 Text output format, which is the default. More...
 
static int output_xml (struct conf_t *state, const int print_mac_addreses)
 The xml output formats. More...
 
static int output_json (struct conf_t *state, const int print_mac_addreses)
 The json output formats. More...
 
static void html_header (struct conf_t *state, FILE *restrict f)
 Header for full html output format. More...
 
static void html_footer (FILE *restrict f)
 Footer for full html output format. More...
 
static void start_tag (FILE *restrict f, char const *restrict tag)
 Start a html tag. More...
 
static void end_tag (FILE *restrict f, char const *restrict tag)
 End a html tag. More...
 
static void output_line (FILE *restrict f, char const *restrict type, char const *restrict text)
 Line with text in html output format. More...
 
static void output_double (FILE *restrict f, char const *restrict type, double d)
 Line with digit in html output format. More...
 
static void output_double_color (struct conf_t *state, struct output_helper_t *oh, FILE *restrict f, char const *restrict type)
 Line with a potentially colored digit in html output format. More...
 
static void output_float (FILE *restrict f, char const *restrict type, float fl)
 Line with float in html output format. More...
 
static void table_start (FILE *restrict f, char const *restrict id, char const *restrict summary)
 Begin table in html output format. More...
 
static void table_end (FILE *restrict f)
 End table in html output format. More...
 
static void newsection (FILE *restrict f, char const *restrict title)
 New section in html output format. More...
 
static int output_html (struct conf_t *state)
 Output html format. More...
 
static int output_csv (struct conf_t *state)
 Output cvs format. More...
 
static int output_alarming (struct conf_t *state)
 Output alarm text, and return program exit value. More...
 
int output_analysis (struct conf_t *state, const char output_format)
 Return output_format_names enum based on single char input. More...
 

Variables

static const char * color_tags [][NUM_OF_OUT_FORMS]
 Array of stings that make colors to start and end in different schemas per array column. More...
 

Detailed Description

All about output formats.

Enumeration Type Documentation

◆ colored_formats

Enumeration of output formats.

Keep the text and html first, they are used color array selector.

Enumerator
OUT_FORM_TEXT 
OUT_FORM_HTML 
NUM_OF_OUT_FORMS 

◆ count_status_t

Enumeration of possible range and shared net statuses.

Enumerator
STATUS_OK 
STATUS_WARN 
STATUS_CRIT 
STATUS_IGNORED 
STATUS_SUPPRESSED 
COLOR_RESET 

Function Documentation

◆ close_outfile()

static void close_outfile ( FILE *  outfile)
static

Helper function to close outfile.

Referenced by output_alarming(), output_csv(), output_html(), output_json(), output_txt(), and output_xml().

Here is the call graph for this function:

◆ end_tag()

static void end_tag ( FILE *restrict  f,
char const *restrict  tag 
)
static

End a html tag.

Parameters
fOutput file descriptor.
tagThe html tag.

Referenced by output_html().

◆ html_footer()

static void html_footer ( FILE *restrict  f)
static

Footer for full html output format.

Parameters
fOutput file descriptor.

Referenced by output_html().

◆ html_header()

static void html_header ( struct conf_t state,
FILE *restrict  f 
)
static

Header for full html output format.

Parameters
fOutput file descriptor.

Referenced by output_html().

Here is the call graph for this function:

◆ newsection()

static void newsection ( FILE *restrict  f,
char const *restrict  title 
)
static

New section in html output format.

Parameters
fOutput file descriptor.
titleTable title.

Referenced by output_html().

Here is the call graph for this function:

◆ open_outfile()

static FILE* open_outfile ( struct conf_t state)
static

Helper function to open a output file.

Returns
The outfile in all of the output functions.

Referenced by output_alarming(), output_csv(), output_html(), output_json(), output_txt(), and output_xml().

Here is the call graph for this function:

◆ output_alarming()

static int output_alarming ( struct conf_t state)
static

Output alarm text, and return program exit value.

Referenced by output_analysis().

Here is the call graph for this function:

◆ output_analysis()

int output_analysis ( struct conf_t state,
const char  output_format 
)

Return output_format_names enum based on single char input.

Referenced by main().

Here is the call graph for this function:

◆ output_csv()

static int output_csv ( struct conf_t state)
static

Output cvs format.

Referenced by output_analysis().

Here is the call graph for this function:

◆ output_double()

static void output_double ( FILE *restrict  f,
char const *restrict  type,
double  d 
)
static

Line with digit in html output format.

Parameters
fOutput file descriptor.
typeHMTL tag name.
dActual payload of the printout.

Referenced by output_html().

◆ output_double_color()

static void output_double_color ( struct conf_t state,
struct output_helper_t oh,
FILE *restrict  f,
char const *restrict  type 
)
static

Line with a potentially colored digit in html output format.

Parameters
stateRuntime configuration state.
fOutput file descriptor.
typeHMTL tag name.
dActual payload of the printout.

Referenced by output_html().

Here is the call graph for this function:

◆ output_float()

static void output_float ( FILE *restrict  f,
char const *restrict  type,
float  fl 
)
static

Line with float in html output format.

Parameters
fOutput file descriptor.
typeHTML tag name.
flActual payload of the printout.

Referenced by output_html().

◆ output_html()

static int output_html ( struct conf_t state)
static

Output html format.

Referenced by output_analysis().

Here is the call graph for this function:

◆ output_json()

static int output_json ( struct conf_t state,
const int  print_mac_addreses 
)
static

The json output formats.

Referenced by output_analysis().

Here is the call graph for this function:

◆ output_line()

static void output_line ( FILE *restrict  f,
char const *restrict  type,
char const *restrict  text 
)
static

Line with text in html output format.

Parameters
fOutput file descriptor.
typeHTML tag name.
classHow the data is aligned.
textActual payload of the printout.

Referenced by newsection(), and output_html().

◆ output_txt()

static int output_txt ( struct conf_t state)
static

Text output format, which is the default.

Referenced by output_analysis().

Here is the call graph for this function:

◆ output_xml()

static int output_xml ( struct conf_t state,
const int  print_mac_addreses 
)
static

The xml output formats.

Referenced by output_analysis().

Here is the call graph for this function:

◆ range_output_helper()

int range_output_helper ( struct conf_t state,
struct output_helper_t oh,
struct range_t range_p 
)

Calculate range percentages and such.

Returns
Indicator if the entry should be skipped from output.

Referenced by must_next_range(), output_alarming(), output_csv(), output_html(), output_json(), output_txt(), and output_xml().

◆ shnet_output_helper()

int shnet_output_helper ( struct conf_t state,
struct output_helper_t oh,
struct shared_network_t shared_p 
)

Calculate shared network percentages and such.

Returns
Indicator if the entry should be skipped from output.

Referenced by must_enter(), must_next_shnet(), output_alarming(), output_csv(), output_html(), output_json(), output_txt(), and output_xml().

◆ start_color()

static int start_color ( struct conf_t state,
struct output_helper_t oh,
FILE *  outfile 
)
static

Output a color based on output_helper_t status.

Returns
Indicator whether coloring was started or not.

Referenced by output_double_color(), and output_txt().

◆ start_tag()

static void start_tag ( FILE *restrict  f,
char const *restrict  tag 
)
static

Start a html tag.

Parameters
fOutput file descriptor.
tagThe html tag.

Referenced by output_html().

◆ table_end()

static void table_end ( FILE *restrict  f)
static

End table in html output format.

Parameters
fOutput file descriptor.

Referenced by output_html().

◆ table_start()

static void table_start ( FILE *restrict  f,
char const *restrict  id,
char const *restrict  summary 
)
static

Begin table in html output format.

Parameters
fOutput file descriptor.

Referenced by output_html().

Variable Documentation

◆ color_tags

color_tags
static
Initial value:
= {
[STATUS_OK] = { "", "" },
[STATUS_WARN] = { "\033[1;33m", " style=\"color:magenta;font-style:italic\"" },
[STATUS_CRIT] = { "\033[1;31m", " style=\"color:red;font-weight:bold\"" },
[STATUS_IGNORED] = { "\033[1;32m", " style=\"color:green\"" },
[STATUS_SUPPRESSED] = { "\033[1;34m", " style=\"color:blue\"" },
[COLOR_RESET] = { "\033[0m", "" }
}
Definition: output.c:81
Definition: output.c:76
Definition: output.c:78
Definition: output.c:80
Definition: output.c:77
Definition: output.c:79

Array of stings that make colors to start and end in different schemas per array column.

Referenced by output_txt(), and start_color().