77 |
#define MYPIDDIR PIDDIR |
#define MYPIDDIR PIDDIR |
78 |
#define MYPIDFILE "monit.pid" |
#define MYPIDFILE "monit.pid" |
79 |
#define MYSTATEFILE "monit.state" |
#define MYSTATEFILE "monit.state" |
80 |
|
#define MYEVENTLISTBASE "/var/monit" |
81 |
|
|
82 |
#define LOCALHOST "localhost" |
#define LOCALHOST "localhost" |
83 |
|
|
129 |
#define TYPE_FILE 2 |
#define TYPE_FILE 2 |
130 |
#define TYPE_PROCESS 3 |
#define TYPE_PROCESS 3 |
131 |
#define TYPE_HOST 4 |
#define TYPE_HOST 4 |
132 |
|
#define TYPE_SYSTEM 5 |
133 |
|
|
134 |
#define RESOURCE_ID_CPU_PERCENT 1 |
#define RESOURCE_ID_CPU_PERCENT 1 |
135 |
#define RESOURCE_ID_MEM_PERCENT 2 |
#define RESOURCE_ID_MEM_PERCENT 2 |
194 |
#define MIN(x,y) ((x) < (y) ? (x) : (y)) |
#define MIN(x,y) ((x) < (y) ? (x) : (y)) |
195 |
#define IS(a,b) ((a&&b)?!strcasecmp(a, b):0) |
#define IS(a,b) ((a&&b)?!strcasecmp(a, b):0) |
196 |
#define DEBUG if(Run.debug) log |
#define DEBUG if(Run.debug) log |
197 |
|
#define FLAG(x, y) (x & y) == y |
198 |
|
|
199 |
|
|
200 |
/** ------------------------------------------------- Synchronization macros */ |
/** ------------------------------------------------- Synchronization macros */ |
363 |
} SystemInfo_T; |
} SystemInfo_T; |
364 |
|
|
365 |
|
|
|
/** Defines data for application runtime */ |
|
|
struct myrun { |
|
|
int stopped; /**< TRUE if monit was stopped. Flag used by threads */ |
|
|
char *controlfile; /**< The file to read configuration from */ |
|
|
char *logfile; /**< The file to write logdata into */ |
|
|
char *localhostname; /**< The host name for localhost */ |
|
|
char *pidfile; /**< This programs pidfile */ |
|
|
char *statefile; /**< The file with the saved runtime state */ |
|
|
char *mygroup; /**< Group Name of the Service */ |
|
|
int debug; /**< Write debug information - TRUE or FALSE */ |
|
|
int use_syslog; /**< If TRUE write log to syslog */ |
|
|
int dolog; /**< TRUE if program should log actions, otherwise FALSE */ |
|
|
int isdaemon; /**< TRUE if program should run as a daemon */ |
|
|
int polltime; /**< In deamon mode, the sleeptime (sec) between run */ |
|
|
int dohttpd; /**< TRUE if monit HTTP server should run */ |
|
|
int httpdssl; /**< TRUE if monit HTTP server uses ssl */ |
|
|
char *httpsslpem; /**< PEM file for the HTTPS server */ |
|
|
int clientssl; /**< TRUE if monit HTTP server uses ssl with client auth */ |
|
|
char *httpsslclientpem; /**< PEM file/dir to check against at connect */ |
|
|
int allowselfcert; /**< TRUE if self certified client certs are allowed */ |
|
|
int httpdsig; /**< TRUE if monit HTTP server presents version signature */ |
|
|
int httpdport; /**< The monit http server's portnumber */ |
|
|
int once; /**< TRUE - run only once */ |
|
|
int init; /**< TRUE - don't background to run from init */ |
|
|
int facility; /** The facility to use when running openlog() */ |
|
|
int doprocess; /**< TRUE if process status engine is used */ |
|
|
char *bind_addr; /**< The address monit http will bind to */ |
|
|
int doreload; /**< TRUE if a monit daemon should reinitialize */ |
|
|
mode_t umask; /**< The initial umask monit was started with */ |
|
|
int testing; /**< Running in configuration testing mode - TRUE or FALSE */ |
|
|
int wait_start; /**< Number of threads waiting for process' start */ |
|
|
time_t incarnation; /**< Unique ID for running monit instance */ |
|
|
|
|
|
/** An object holding program relevant "environment" data, see; env.c */ |
|
|
struct myenvironment { |
|
|
char *user; /**< The the effective user running this program */ |
|
|
char *home; /**< Users home directory */ |
|
|
char *cwd; /**< Current working directory */ |
|
|
} Env; |
|
|
|
|
|
int mailserver_timeout; /**< Connect and read timeout for a SMTP server */ |
|
|
Mail_T maillist; /**< Global alert notification mailinglist */ |
|
|
MailServer_T mailservers; /**< List of MTAs used for alert notification */ |
|
|
Collector_T collectors; /**< Event notification and status receivers list */ |
|
|
Auth_T credentials; /** A list holding Basic Authentication information */ |
|
|
/** User selected standard mail format */ |
|
|
struct myformat { |
|
|
char *from; /**< The standard mail from address */ |
|
|
char *subject; /**< The standard mail subject */ |
|
|
char *message; /**< The standard mail message */ |
|
|
} MailFormat; |
|
|
|
|
|
pthread_mutex_t mutex; /**< Mutex used for service data synchronization */ |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
366 |
/** Defines a protocol object with protocol functions */ |
/** Defines a protocol object with protocol functions */ |
367 |
typedef struct myprotocol { |
typedef struct myprotocol { |
368 |
const char *name; /**< Protocol name */ |
const char *name; /**< Protocol name */ |
645 |
EventAction_T action_NONEXIST; /**< Description of the action upon event */ |
EventAction_T action_NONEXIST; /**< Description of the action upon event */ |
646 |
EventAction_T action_TIMEOUT; /**< Description of the action upon event */ |
EventAction_T action_TIMEOUT; /**< Description of the action upon event */ |
647 |
|
|
648 |
|
/** Internal monit events */ |
649 |
|
EventAction_T action_MONIT_START; /**< Monit instance start action */ |
650 |
|
EventAction_T action_MONIT_STOP; /**< Monit instance stop action */ |
651 |
|
EventAction_T action_MONIT_RELOAD; /**< Monit instance reload action */ |
652 |
|
|
653 |
/** Runtime parameters */ |
/** Runtime parameters */ |
654 |
unsigned long long error; /**< Error flags bitmap */ |
unsigned long long error; /**< Error flags bitmap */ |
655 |
Info_T inf; /**< Service check result */ |
Info_T inf; /**< Service check result */ |
656 |
time_t collected; /**< When were data collected */ |
time_t collected; /**< When were data collected */ |
657 |
|
|
|
|
|
658 |
/** Events */ |
/** Events */ |
659 |
struct myevent { |
struct myevent { |
660 |
|
#define EVENT_VERSION 1 /**< The event structure version */ |
661 |
int id; /**< The event identification */ |
int id; /**< The event identification */ |
662 |
time_t collected; /**< When the event occured */ |
time_t collected; /**< When the event occured */ |
663 |
struct myservice *source; /**< Event source */ |
char *source; /**< Event source service name */ |
664 |
|
char *group; /**< Service group name */ |
665 |
|
int mode; /**< Monitoring mode for the service */ |
666 |
|
int type; /**< Monitored service type */ |
667 |
short state; /**< TRUE if failed, FALSE if passed */ |
short state; /**< TRUE if failed, FALSE if passed */ |
668 |
short state_changed; /**< TRUE if state changed */ |
short state_changed; /**< TRUE if state changed */ |
669 |
long long state_map; /**< Event bitmap for last cycles */ |
long long state_map; /**< Event bitmap for last cycles */ |
670 |
unsigned int count; /**< The event rate */ |
unsigned int count; /**< The event rate */ |
671 |
|
unsigned int flag; /**< The handlers state flag */ |
672 |
char *message; /**< Optional message describing the event */ |
char *message; /**< Optional message describing the event */ |
673 |
EventAction_T action; /**< Description of the event action */ |
EventAction_T action; /**< Description of the event action */ |
674 |
/** For internal use */ |
/** For internal use */ |
675 |
pthread_mutex_t mutex; /**< Mutex used for action synchronization */ |
pthread_mutex_t mutex; /**< Mutex used for action synchronization */ |
676 |
struct myevent *next; /**< next event in chain */ |
struct myevent *next; /**< next event in chain */ |
677 |
|
struct myevent *previous; /**< previous event in chain */ |
678 |
} *eventlist; /**< Pending events list */ |
} *eventlist; /**< Pending events list */ |
679 |
|
|
680 |
/** Context specific parameters */ |
/** Context specific parameters */ |
691 |
typedef struct myevent *Event_T; |
typedef struct myevent *Event_T; |
692 |
|
|
693 |
|
|
694 |
|
/** Defines data for application runtime */ |
695 |
|
struct myrun { |
696 |
|
int stopped; /**< TRUE if monit was stopped. Flag used by threads */ |
697 |
|
char *controlfile; /**< The file to read configuration from */ |
698 |
|
char *logfile; /**< The file to write logdata into */ |
699 |
|
char *localhostname; /**< The host name for localhost */ |
700 |
|
char *pidfile; /**< This programs pidfile */ |
701 |
|
char *statefile; /**< The file with the saved runtime state */ |
702 |
|
char *mygroup; /**< Group Name of the Service */ |
703 |
|
int debug; /**< Write debug information - TRUE or FALSE */ |
704 |
|
int use_syslog; /**< If TRUE write log to syslog */ |
705 |
|
int dolog; /**< TRUE if program should log actions, otherwise FALSE */ |
706 |
|
int isdaemon; /**< TRUE if program should run as a daemon */ |
707 |
|
int polltime; /**< In deamon mode, the sleeptime (sec) between run */ |
708 |
|
int dohttpd; /**< TRUE if monit HTTP server should run */ |
709 |
|
int httpdssl; /**< TRUE if monit HTTP server uses ssl */ |
710 |
|
char *httpsslpem; /**< PEM file for the HTTPS server */ |
711 |
|
int clientssl; /**< TRUE if monit HTTP server uses ssl with client auth */ |
712 |
|
char *httpsslclientpem; /**< PEM file/dir to check against at connect */ |
713 |
|
int allowselfcert; /**< TRUE if self certified client certs are allowed */ |
714 |
|
int httpdsig; /**< TRUE if monit HTTP server presents version signature */ |
715 |
|
int httpdport; /**< The monit http server's portnumber */ |
716 |
|
int once; /**< TRUE - run only once */ |
717 |
|
int init; /**< TRUE - don't background to run from init */ |
718 |
|
int facility; /** The facility to use when running openlog() */ |
719 |
|
int doprocess; /**< TRUE if process status engine is used */ |
720 |
|
char *bind_addr; /**< The address monit http will bind to */ |
721 |
|
int doreload; /**< TRUE if a monit daemon should reinitialize */ |
722 |
|
mode_t umask; /**< The initial umask monit was started with */ |
723 |
|
int testing; /**< Running in configuration testing mode - TRUE or FALSE */ |
724 |
|
int wait_start; /**< Number of threads waiting for process' start */ |
725 |
|
time_t incarnation; /**< Unique ID for running monit instance */ |
726 |
|
int handler_flag; /**< The handlers state flag */ |
727 |
|
Service_T system; /**< The general system service */ |
728 |
|
char *eventlist_dir; /**< The event queue base directory */ |
729 |
|
int eventlist_slots; /**< The event queue size - number of slots */ |
730 |
|
|
731 |
|
/** An object holding program relevant "environment" data, see; env.c */ |
732 |
|
struct myenvironment { |
733 |
|
char *user; /**< The the effective user running this program */ |
734 |
|
char *home; /**< Users home directory */ |
735 |
|
char *cwd; /**< Current working directory */ |
736 |
|
} Env; |
737 |
|
|
738 |
|
int mailserver_timeout; /**< Connect and read timeout for a SMTP server */ |
739 |
|
Mail_T maillist; /**< Global alert notification mailinglist */ |
740 |
|
MailServer_T mailservers; /**< List of MTAs used for alert notification */ |
741 |
|
Collector_T collectors; /**< Event notification and status receivers list */ |
742 |
|
Auth_T credentials; /** A list holding Basic Authentication information */ |
743 |
|
Event_T eventlist; /** A list holding partialy handled events */ |
744 |
|
/** User selected standard mail format */ |
745 |
|
struct myformat { |
746 |
|
char *from; /**< The standard mail from address */ |
747 |
|
char *subject; /**< The standard mail subject */ |
748 |
|
char *message; /**< The standard mail message */ |
749 |
|
} MailFormat; |
750 |
|
|
751 |
|
pthread_mutex_t mutex; /**< Mutex used for service data synchronization */ |
752 |
|
|
753 |
|
}; |
754 |
|
|
755 |
|
|
756 |
/* -------------------------------------------------------- Global variables */ |
/* -------------------------------------------------------- Global variables */ |
757 |
|
|
758 |
char *prog; /**< The Name of this Program */ |
char *prog; /**< The Name of this Program */ |
789 |
void gc_mail_list(Mail_T *); |
void gc_mail_list(Mail_T *); |
790 |
int kill_daemon(int); |
int kill_daemon(int); |
791 |
int exist_daemon(); |
int exist_daemon(); |
792 |
void sendmail(Mail_T); |
int sendmail(Mail_T); |
793 |
int sock_msg(int, char *, ...); |
int sock_msg(int, char *, ...); |
794 |
void init_env(); |
void init_env(); |
795 |
void *xmalloc (int); |
void *xmalloc (int); |
813 |
int check_file(Service_T); |
int check_file(Service_T); |
814 |
int check_directory(Service_T); |
int check_directory(Service_T); |
815 |
int check_remote_host(Service_T); |
int check_remote_host(Service_T); |
816 |
|
int check_system(Service_T); |
817 |
int check_URL(Service_T s); |
int check_URL(Service_T s); |
818 |
int sha_md5_stream (FILE *, void *, void *); |
int sha_md5_stream (FILE *, void *, void *); |
819 |
void reset_procinfo(Service_T); |
void reset_procinfo(Service_T); |
820 |
int check_service_status(Service_T); |
int check_service_status(Service_T); |
821 |
void printhash(char *); |
void printhash(char *); |
822 |
char *status_xml(Event_T, short); |
char *status_xml(Event_T, short); |
823 |
void handle_collector(Event_T); |
int handle_collector(Event_T); |
824 |
int do_wakeupcall(); |
int do_wakeupcall(); |
825 |
|
|
826 |
#endif |
#endif |