Icinga-core 1.4.0
next gen monitoring
cgi/cmd.c File Reference

submits commands to Icinga command pipe More...

#include "../include/config.h"
#include "../include/common.h"
#include "../include/objects.h"
#include "../include/comments.h"
#include "../include/downtime.h"
#include "../include/cgiutils.h"
#include "../include/cgiauth.h"
#include "../include/getcgi.h"

Go to the source code of this file.

Data Structures

struct  hostlist
 host/service list structure More...
struct  errorlist
 error list structure More...

Defines

LIMITS
#define MAX_AUTHOR_LENGTH   64
#define MAX_COMMENT_LENGTH   1024
#define NUMBER_OF_STRUCTS   500
ELEMET TEMPLATE TYPES
#define PRINT_COMMON_HEADER   1
#define PRINT_AUTHOR   2
#define PRINT_STICKY_ACK   3
#define PRINT_PERSISTENT   4
#define PRINT_SEND_NOTFICATION   5
#define PRINT_COMMENT_BOX   6
#define PRINT_NOTIFICATION_DELAY   7
#define PRINT_START_TIME   8
#define PRINT_END_TIME   9
#define PRINT_CHECK_TIME   10
#define PRINT_FORCE_CHECK   11
#define PRINT_CHECK_OUTPUT_BOX   12
#define PRINT_PERFORMANCE_DATA_BOX   13
#define PRINT_FIXED_FLEXIBLE_TYPE   14
#define PRINT_BROADCAST_NOTIFICATION   15
#define PRINT_FORCE_NOTIFICATION   16
OBJECT LIST TYPES
#define PRINT_HOST_LIST   17
#define PRINT_SERVICE_LIST   18
#define PRINT_COMMENT_LIST   19
#define PRINT_DOWNTIME_LIST   20

Functions

void request_command_data (int)
 Print form for all details to submit command.
void commit_command_data (int)
 submits the command data and checks for sanity
int commit_command (int)
 checks the authorization and passes the data to cmd_submitf
int write_command_to_file (char *)
 write the command to Icinga command pipe
void clean_comment_data (char *)
 strips out semicolons and newlines from comment data
void print_form_element (int, int)
 strips out semicolons and newlines from comment data
void print_object_list (int)
 print the list of affected objects
void print_help_box (char *)
 print the mouseover box with help text
void check_comment_sanity (int *)
 checks start and end time and if start_time is before end_time
void check_time_sanity (int *)
 checks if comment and author are not empty strings
int process_cgivars (void)
 Parses the requested GET/POST variables.
int main (void)
 Yes we need a main function.
 __attribute__ ((format(printf, 2, 3)))
 doe's some checks before passing data to write_command_to_file

Variables

Vars which are imported for cgiutils
Warning:
these wars should be all extern,
then they could get deleted, because they aren't used here.
cgiutils.c , needs them
int show_all_hosts = TRUE
int show_all_hostgroups = TRUE
int show_all_servicegroups = TRUE
int display_type = DISPLAY_HOSTS
Internal vars
char * host_name = ""
char * hostgroup_name = ""
char * servicegroup_name = ""
char * service_desc = ""
char * comment_author = ""
char * comment_data = ""
char * start_time_string = ""
char * end_time_string = ""
char help_text [MAX_INPUT_BUFFER] = ""
char plugin_output [MAX_INPUT_BUFFER] = ""
char performance_data [MAX_INPUT_BUFFER] = ""
int notification_delay = 0
int schedule_delay = 0
int persistent_comment = FALSE
int sticky_ack = FALSE
int send_notification = FALSE
int force_check = FALSE
int plugin_state = STATE_OK
int affect_host_and_services = FALSE
int propagate_to_children = FALSE
int fixed = FALSE
unsigned long duration = 0L
unsigned long triggered_by = 0L
int child_options = 0
int force_notification = 0
int broadcast_notification = 0
int command_type = CMD_NONE
int command_mode = CMDMODE_REQUEST
time_t start_time = 0L
time_t end_time = 0L
int CGI_ID = CMD_CGI_ID
authdata current_authdata
struct hostlist commands [NUMBER_OF_STRUCTS]
struct errorlist error [NUMBER_OF_STRUCTS]
unsigned long multi_ids [NUMBER_OF_STRUCTS]
short is_authorized [NUMBER_OF_STRUCTS]
short submit_result [NUMBER_OF_STRUCTS]

External vars

char main_config_file [MAX_FILENAME_LENGTH]
char url_html_path [MAX_FILENAME_LENGTH]
char url_images_path [MAX_FILENAME_LENGTH]
char command_file [MAX_FILENAME_LENGTH]
char comment_file [MAX_FILENAME_LENGTH]
int check_external_commands
int use_authentication
int lock_author_names
int persistent_ack_comments
int log_external_commands_user
int content_type
int display_header
int daemon_check
int enforce_comments_on_actions
int date_format
scheduled_downtimescheduled_downtime_list
commentcomment_list
const char * extcmd_get_name (int id)

Detailed Description

submits commands to Icinga command pipe

Definition in file cmd.c.


Define Documentation

#define MAX_AUTHOR_LENGTH   64

Definition at line 70 of file cmd.c.

#define MAX_COMMENT_LENGTH   1024

Definition at line 71 of file cmd.c.

#define NUMBER_OF_STRUCTS   500

Set a limit of 500 structs, which is around 125 checks total

Definition at line 72 of file cmd.c.

#define PRINT_AUTHOR   2

Definition at line 78 of file cmd.c.

#define PRINT_BROADCAST_NOTIFICATION   15

Definition at line 91 of file cmd.c.

#define PRINT_CHECK_OUTPUT_BOX   12

Definition at line 88 of file cmd.c.

#define PRINT_CHECK_TIME   10

Definition at line 86 of file cmd.c.

#define PRINT_COMMENT_BOX   6

Definition at line 82 of file cmd.c.

#define PRINT_COMMENT_LIST   19

Definition at line 99 of file cmd.c.

#define PRINT_COMMON_HEADER   1

Definition at line 77 of file cmd.c.

#define PRINT_DOWNTIME_LIST   20

Definition at line 100 of file cmd.c.

#define PRINT_END_TIME   9

Definition at line 85 of file cmd.c.

#define PRINT_FIXED_FLEXIBLE_TYPE   14

Definition at line 90 of file cmd.c.

#define PRINT_FORCE_CHECK   11

Definition at line 87 of file cmd.c.

#define PRINT_FORCE_NOTIFICATION   16

Definition at line 92 of file cmd.c.

#define PRINT_HOST_LIST   17

Definition at line 97 of file cmd.c.

#define PRINT_NOTIFICATION_DELAY   7

Definition at line 83 of file cmd.c.

#define PRINT_PERFORMANCE_DATA_BOX   13

Definition at line 89 of file cmd.c.

#define PRINT_PERSISTENT   4

Definition at line 80 of file cmd.c.

#define PRINT_SEND_NOTFICATION   5

Definition at line 81 of file cmd.c.

#define PRINT_SERVICE_LIST   18

Definition at line 98 of file cmd.c.

#define PRINT_START_TIME   8

Definition at line 84 of file cmd.c.

#define PRINT_STICKY_ACK   3

Definition at line 79 of file cmd.c.


Function Documentation

__attribute__ ( (format(printf, 2, 3))  )

doe's some checks before passing data to write_command_to_file

Actually defines the command cmd_submitf.

Definition at line 2362 of file cmd.c.

void check_comment_sanity ( int *  e)

checks start and end time and if start_time is before end_time

Parameters:
[in]ethe error element list

Checks if author or comment is empty. If so it adds an error to error list.

Definition at line 2892 of file cmd.c.

void check_time_sanity ( int *  e)

checks if comment and author are not empty strings

Parameters:
[in]ethe error element list

Checks the sanity of given start and end time. Checks if time is wrong or start_time is past end_time then if found an error it adds an error to error list.

Definition at line 2901 of file cmd.c.

void clean_comment_data ( char *  buffer)

strips out semicolons and newlines from comment data

Parameters:
[in,out]bufferthe stringt which should be cleaned

Converts semicolons, newline and carriage return to space.

Definition at line 2878 of file cmd.c.

int commit_command ( int  cmd)

checks the authorization and passes the data to cmd_submitf

Parameters:
[in]cmdID of requested command
Return values:
OK
ERROR
Returns:
success / fail

Here the command get formatted properly to be readable by icinga core. It passes the data to cmd_submitf .

Definition at line 2399 of file cmd.c.

void commit_command_data ( int  cmd)

submits the command data and checks for sanity

Parameters:
[in]cmdID of requested command

This function checks the submitted data (request_command_data) for sanity. If everything is alright it passes the data to commit_command.

Definition at line 1808 of file cmd.c.

const char* extcmd_get_name ( int  id)

Definition at line 219 of file extcmd_list.c.

int main ( void  )

Yes we need a main function.

Definition at line 288 of file cmd.c.

void print_form_element ( int  element,
int  cmd 
)

strips out semicolons and newlines from comment data

Parameters:
[in]elementID of the element which should be printed
[in]cmdID of requested command

These are templates for the different form elements. Specify the element you want to print with element id.

Definition at line 823 of file cmd.c.

void print_help_box ( char *  content)

print the mouseover box with help text

Parameters:
[in]contentstring which should be printed as help box

This writes the mousover help box.

Definition at line 814 of file cmd.c.

void print_object_list ( int  list_type)

print the list of affected objects

Parameters:
[in]list_typeID of the item list which should be printed

Used to print the list of requested objects. Depending on the command you can specify the list (HOST/SERVICE/COMMENT/DOWNTIME).

Definition at line 762 of file cmd.c.

int process_cgivars ( void  )

Parses the requested GET/POST variables.

Return values:
TRUE
FALSE
Returns:
wether parsing was successful or not


This function parses the request and set's the necessary variables

void request_command_data ( int  cmd)

Print form for all details to submit command.

Parameters:
[in]cmdID of requested command

This function generates the form for the command with all requested host/services/downtimes/comments items. This is the first page you get when you submit a command.

Definition at line 1021 of file cmd.c.

int write_command_to_file ( char *  cmd)

write the command to Icinga command pipe

Parameters:
[in]cmdthe formatted command string
Return values:
OK
ERROR
Returns:
success / fail

This function actually writes the formatted string into Icinga command pipe. And if configured also to Icinga CGI log.

Definition at line 2811 of file cmd.c.


Variable Documentation

bool if notifiactions or else affect all host and services

Definition at line 155 of file cmd.c.

this options determines if notification should be broadcasted

Definition at line 162 of file cmd.c.

int CGI_ID = CMD_CGI_ID

ID to identify the cgi for functions in cgiutils.c

Definition at line 170 of file cmd.c.

Definition at line 132 of file icinga.c.

int child_options = 0

if downtime should trigger child host downtimes

Definition at line 160 of file cmd.c.

char command_file[MAX_FILENAME_LENGTH]

Definition at line 64 of file icinga.c.

int command_mode = CMDMODE_REQUEST

if command mode is request or commit

Definition at line 165 of file cmd.c.

int command_type = CMD_NONE

the requested command ID

Definition at line 164 of file cmd.c.

struct hostlist commands[NUMBER_OF_STRUCTS]

Initialize the struct

Definition at line 175 of file cmd.c.

char* comment_author = ""

submitted comment author

Definition at line 138 of file cmd.c.

char* comment_data = ""

submitted comment data

Definition at line 139 of file cmd.c.

char comment_file[MAX_FILENAME_LENGTH]

Definition at line 47 of file comments.c.

Definition at line 165 of file cgiutils.c.

struct to hold current authentication data

Definition at line 172 of file cmd.c.

Definition at line 169 of file cgiutils.c.

Definition at line 243 of file icinga.c.

Definition at line 167 of file cgiutils.c.

int display_type = DISPLAY_HOSTS

Definition at line 129 of file cmd.c.

unsigned long duration = 0L

downtime duration

Definition at line 158 of file cmd.c.

time_t end_time = 0L

end time as unix timestamp

Definition at line 168 of file cmd.c.

char* end_time_string = ""

the requested end time

Definition at line 141 of file cmd.c.

Definition at line 140 of file cgiutils.c.

struct errorlist error[NUMBER_OF_STRUCTS]

initialze the error list

Definition at line 178 of file cmd.c.

int fixed = FALSE

bool if downtime is fixed or flexible

Definition at line 157 of file cmd.c.

int force_check = FALSE

bool if check should be forced

Definition at line 153 of file cmd.c.

force a notification to be send out through event handler

Definition at line 161 of file cmd.c.

char help_text[MAX_INPUT_BUFFER] = ""

help string

Definition at line 143 of file cmd.c.

char* host_name = ""

requested host name

Definition at line 134 of file cmd.c.

char* hostgroup_name = ""

requested hostgroup name

Definition at line 135 of file cmd.c.

short is_authorized[NUMBER_OF_STRUCTS]

store the authentication status when data gets checked to submited

Definition at line 184 of file cmd.c.

Definition at line 74 of file cgiutils.c.

Definition at line 102 of file icinga.c.

char main_config_file[MAX_FILENAME_LENGTH]

Definition at line 50 of file icingastats.c.

unsigned long multi_ids[NUMBER_OF_STRUCTS]

Hold IDs of comments and downtimes

Definition at line 181 of file cmd.c.

delay for submitted notification in minutes

Definition at line 147 of file cmd.c.

char performance_data[MAX_INPUT_BUFFER] = ""

plugin performance data for passive submitted check

Definition at line 145 of file cmd.c.

Definition at line 121 of file cgiutils.c.

int persistent_comment = FALSE

bool if omment should survive Icinga restart

Definition at line 150 of file cmd.c.

char plugin_output[MAX_INPUT_BUFFER] = ""

plugin output text for passive submitted check

Definition at line 144 of file cmd.c.

int plugin_state = STATE_OK

plugin state for passive submitted check

Definition at line 154 of file cmd.c.

int propagate_to_children = FALSE

bool if en/disable host notifications should propagated to children

Definition at line 156 of file cmd.c.

int schedule_delay = 0

delay for sheduled actions in minutes (Icinga restart, Notfications enable/disable) !not implemented in GUI!

Definition at line 148 of file cmd.c.

int send_notification = FALSE

bool sends a notification if service gets acknowledged

Definition at line 152 of file cmd.c.

char* service_desc = ""

requested service name

Definition at line 137 of file cmd.c.

char* servicegroup_name = ""

requested servicegroup name

Definition at line 136 of file cmd.c.

int show_all_hostgroups = TRUE

Definition at line 127 of file cmd.c.

int show_all_hosts = TRUE

Definition at line 126 of file cmd.c.

Definition at line 128 of file cmd.c.

time_t start_time = 0L

start time as unix timestamp

Definition at line 167 of file cmd.c.

char* start_time_string = ""

the requested start time

Definition at line 140 of file cmd.c.

int sticky_ack = FALSE

bool to disable notifications until recover

Definition at line 151 of file cmd.c.

short submit_result[NUMBER_OF_STRUCTS]

store the result of each object which get submited

Definition at line 187 of file cmd.c.

unsigned long triggered_by = 0L

downtime id which triggers submited downtime

Definition at line 159 of file cmd.c.

char url_html_path[MAX_FILENAME_LENGTH]

Definition at line 38 of file cgiutils.c.

char url_images_path[MAX_FILENAME_LENGTH]

Definition at line 41 of file cgiutils.c.

Definition at line 104 of file cgiutils.c.

 All Data Structures Files Functions Variables Typedefs Defines