"Fossies" - the Fresh Open Source Software Archive

Member "monit-5.28.0/src/monit.h" (28 Mar 2021, 63352 Bytes) of package /linux/privat/monit-5.28.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "monit.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.27.2_vs_5.28.0.

    1 /*
    2  * Copyright (C) Tildeslash Ltd. All rights reserved.
    3  *
    4  * This program is free software: you can redistribute it and/or modify
    5  * it under the terms of the GNU Affero General Public License version 3.
    6  *
    7  * This program is distributed in the hope that it will be useful,
    8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  * GNU General Public License for more details.
   11  *
   12  * You should have received a copy of the GNU Affero General Public License
   13  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   14  *
   15  * In addition, as a special exception, the copyright holders give
   16  * permission to link the code of portions of this program with the
   17  * OpenSSL library under certain conditions as described in each
   18  * individual source file, and distribute linked combinations
   19  * including the two.
   20  *
   21  * You must obey the GNU Affero General Public License in all respects
   22  * for all of the code used other than OpenSSL.
   23  */
   24 
   25 
   26 #ifndef MONIT_H
   27 #define MONIT_H
   28 
   29 #include "config.h"
   30 #include <assert.h>
   31 
   32 #ifdef HAVE_KINFO_H
   33 #include <kinfo.h>
   34 #endif
   35 
   36 #ifdef HAVE_SYS_TYPES_H
   37 #include <sys/types.h>
   38 #endif
   39 
   40 #ifdef HAVE_SYS_STAT_H
   41 #include <sys/stat.h>
   42 #endif
   43 
   44 #ifdef HAVE_SIGNAL_H
   45 #include <signal.h>
   46 #endif
   47 
   48 #ifdef HAVE_PTHREAD_H
   49 #include <pthread.h>
   50 #endif
   51 
   52 #ifdef HAVE_STDARG_H
   53 #include <stdarg.h>
   54 #endif
   55 
   56 #ifdef HAVE_STDIO_H
   57 #include <stdio.h>
   58 #endif
   59 
   60 #ifdef HAVE_STDLIB_H
   61 #include <stdlib.h>
   62 #endif
   63 
   64 #ifdef HAVE_REGEX_H
   65 #include <regex.h>
   66 #endif
   67 
   68 #ifdef HAVE_SYSLOG_H
   69 #include <syslog.h>
   70 #endif
   71 
   72 #ifdef HAVE_LIMITS_H
   73 #include <limits.h>
   74 #endif
   75 
   76 #ifdef HAVE_SYS_UTSNAME_H
   77 #include <sys/utsname.h>
   78 #endif
   79 
   80 #ifdef HAVE_ERRNO_H
   81 #include <errno.h>
   82 #endif
   83 
   84 #ifdef HAVE_NETDB_H
   85 #include <netdb.h>
   86 #endif
   87 
   88 #ifdef HAVE_SYS_SOCKET_H
   89 #include <sys/socket.h>
   90 #endif
   91 
   92 #ifdef HAVE_UVM_UVM_PARAM_H
   93 #include <uvm/uvm_param.h>
   94 #endif
   95 #ifdef HAVE_VM_VM_H
   96 #include <vm/vm.h>
   97 #endif
   98 
   99 #include <stdbool.h>
  100 
  101 
  102 #include "Ssl.h"
  103 #include "Address.h"
  104 #include "statistics/Statistics.h"
  105 #include "net/socket.h"
  106 #include "net/Link.h"
  107 
  108 // libmonit
  109 #include "system/Command.h"
  110 #include "system/Process.h"
  111 #include "util/Str.h"
  112 #include "util/StringBuffer.h"
  113 #include "thread/Thread.h"
  114 
  115 
  116 #define MONITRC            "monitrc"
  117 #define TIMEFORMAT         "%FT%T%z"
  118 #define STRERROR            strerror(errno)
  119 #define STRLEN             256
  120 #ifndef USEC_PER_SEC
  121 #define USEC_PER_SEC       1000000L
  122 #endif
  123 #define USEC_PER_MSEC      1000L
  124 
  125 #define ARGMAX             64
  126 #define MYPIDDIR           PIDDIR
  127 #define MYPIDFILE          "monit.pid"
  128 #define MYSTATEFILE        "monit.state"
  129 #define MYIDFILE           "monit.id"
  130 #define MYEVENTLISTBASE    "/var/monit"
  131 
  132 #define LOCALHOST          "localhost"
  133 
  134 #define PORT_SMTP          25
  135 #define PORT_SMTPS         465
  136 #define PORT_HTTP          80
  137 #define PORT_HTTPS         443
  138 
  139 #define SSL_TIMEOUT        15000
  140 #define SMTP_TIMEOUT       30000
  141 
  142 
  143 //FIXME: refactor Run_Flags to bit field
  144 typedef enum {
  145         Run_Once                 = 0x1,                   /**< Run Monit only once */
  146         Run_Foreground           = 0x2,                 /**< Don't daemonize Monit */ //FIXME: cleanup: Run_Foreground and Run_Daemon are mutually exclusive => no need for 2 flags
  147         Run_Daemon               = 0x4,                       /**< Daemonize Monit */ //FIXME: cleanup: Run_Foreground and Run_Daemon are mutually exclusive => no need for 2 flags
  148         Run_Log                  = 0x8,                           /**< Log enabled */
  149         Run_UseSyslog            = 0x10,                           /**< Use syslog */ //FIXME: cleanup: no need for standalone flag ... if syslog is enabled, don't set Run.files.log, then (Run.flags&Run_Log && ! Run.files.log => syslog)
  150         Run_FipsEnabled          = 0x20,                 /** FIPS-140 mode enabled */
  151         Run_HandlerInit          = 0x40,    /**< The handlers queue initialization */
  152         Run_ProcessEngineEnabled = 0x80,    /**< Process monitoring engine enabled */
  153         Run_ActionPending        = 0x100,              /**< Service action pending */
  154         Run_MmonitCredentials    = 0x200,      /**< Should set M/Monit credentials */
  155         Run_Stopped              = 0x400,                          /**< Stop Monit */
  156         Run_DoReload             = 0x800,                        /**< Reload Monit */
  157         Run_DoWakeup             = 0x1000,                       /**< Wakeup Monit */
  158         Run_Batch                = 0x2000                      /**< CLI batch mode */
  159 } __attribute__((__packed__)) Run_Flags;
  160 
  161 
  162 typedef enum {
  163         ProcessEngine_None               = 0x0,
  164         ProcessEngine_CollectCommandLine = 0x1
  165 } __attribute__((__packed__)) ProcessEngine_Flags;
  166 
  167 
  168 typedef enum {
  169         Httpd_Start = 1,
  170         Httpd_Stop
  171 } __attribute__((__packed__)) Httpd_Action;
  172 
  173 
  174 typedef enum {
  175         Every_Cycle = 0,
  176         Every_SkipCycles,
  177         Every_Cron,
  178         Every_NotInCron
  179 } __attribute__((__packed__)) Every_Type;
  180 
  181 
  182 typedef enum {
  183         State_Succeeded  = 0x0,
  184         State_Failed     = 0x1,
  185         State_Changed    = 0x2,
  186         State_ChangedNot = 0x4,
  187         State_Init       = 0x8,
  188         State_None       = State_Init // Alias
  189 } __attribute__((__packed__)) State_Type;
  190 
  191 
  192 typedef enum {
  193         Operator_Less = 0,
  194         Operator_LessOrEqual,
  195         Operator_Greater,
  196         Operator_GreaterOrEqual,
  197         Operator_Equal,
  198         Operator_NotEqual,
  199         Operator_Changed
  200 } __attribute__((__packed__)) Operator_Type;
  201 
  202 
  203 typedef enum {
  204         Timestamp_Default = 0,
  205         Timestamp_Access,
  206         Timestamp_Change,
  207         Timestamp_Modification
  208 } __attribute__((__packed__)) Timestamp_Type;
  209 
  210 
  211 typedef enum {
  212         Httpd_Disabled                    = 0x0,
  213         Httpd_Net                         = 0x1,  // IP
  214         Httpd_Unix                        = 0x2,  // Unix socket
  215         Httpd_UnixUid                     = 0x4,  // Unix socket: override UID
  216         Httpd_UnixGid                     = 0x8,  // Unix socket: override GID
  217         Httpd_UnixPermission              = 0x10, // Unix socket: override permissions
  218         Httpd_Signature                   = 0x20  // Server Signature enabled
  219 } __attribute__((__packed__)) Httpd_Flags;
  220 
  221 
  222 typedef enum {
  223         Http_Head = 1,
  224         Http_Get
  225 } __attribute__((__packed__)) Http_Method;
  226 
  227 
  228 typedef enum {
  229         Time_Second = 1,
  230         Time_Minute = 60,
  231         Time_Hour   = 3600,
  232         Time_Day    = 86400,
  233         Time_Month  = 2678400
  234 } __attribute__((__packed__)) Time_Type;
  235 
  236 
  237 typedef enum {
  238         Action_Ignored = 0,
  239         Action_Alert,
  240         Action_Restart,
  241         Action_Stop,
  242         Action_Exec,
  243         Action_Unmonitor,
  244         Action_Start,
  245         Action_Monitor
  246 } __attribute__((__packed__)) Action_Type;
  247 
  248 
  249 typedef enum {
  250         Monitor_Active = 0,
  251         Monitor_Passive
  252 } __attribute__((__packed__)) Monitor_Mode;
  253 
  254 
  255 typedef enum {
  256         Onreboot_Start = 0,
  257         Onreboot_Nostart,
  258         Onreboot_Laststate
  259 } __attribute__((__packed__)) Onreboot_Type;
  260 
  261 
  262 typedef enum {
  263         Monitor_Not     = 0x0,
  264         Monitor_Yes     = 0x1,
  265         Monitor_Init    = 0x2,
  266         Monitor_Waiting = 0x4
  267 } __attribute__((__packed__)) Monitor_State;
  268 
  269 
  270 typedef enum {
  271         Connection_Failed = 0,
  272         Connection_Ok,
  273         Connection_Init
  274 } __attribute__((__packed__)) Connection_State;
  275 
  276 
  277 typedef enum {
  278         Service_Filesystem = 0,
  279         Service_Directory,
  280         Service_File,
  281         Service_Process,
  282         Service_Host,
  283         Service_System,
  284         Service_Fifo,
  285         Service_Program,
  286         Service_Net,
  287         Service_Last = Service_Net
  288 } __attribute__((__packed__)) Service_Type;
  289 
  290 
  291 typedef enum {
  292         Resource_CpuPercent = 1,
  293         Resource_MemoryPercent,
  294         Resource_MemoryKbyte,
  295         Resource_LoadAverage1m,
  296         Resource_LoadAverage5m,
  297         Resource_LoadAverage15m,
  298         Resource_Children,
  299         Resource_MemoryKbyteTotal,
  300         Resource_MemoryPercentTotal,
  301         Resource_Inode,
  302         Resource_InodeFree,
  303         Resource_Space,
  304         Resource_SpaceFree,
  305         Resource_CpuUser,
  306         Resource_CpuSystem,
  307         Resource_CpuWait,
  308         Resource_CpuNice,
  309         Resource_CpuHardIRQ,
  310         Resource_CpuSoftIRQ,
  311         Resource_CpuSteal,
  312         Resource_CpuGuest,
  313         Resource_CpuGuestNice,
  314         Resource_CpuPercentTotal,
  315         Resource_SwapPercent,
  316         Resource_SwapKbyte,
  317         Resource_Threads,
  318         Resource_ReadBytes,
  319         Resource_ReadBytesPhysical,
  320         Resource_ReadOperations,
  321         Resource_WriteBytes,
  322         Resource_WriteBytesPhysical,
  323         Resource_WriteOperations,
  324         Resource_ServiceTime,
  325         Resource_LoadAveragePerCore1m,
  326         Resource_LoadAveragePerCore5m,
  327         Resource_LoadAveragePerCore15m
  328 } __attribute__((__packed__)) Resource_Type;
  329 
  330 
  331 
  332 typedef enum {
  333         Digest_Cleartext = 1,
  334         Digest_Crypt,
  335         Digest_Md5,
  336         Digest_Pam
  337 } __attribute__((__packed__)) Digest_Type;
  338 
  339 
  340 typedef enum {
  341         Unit_Byte     = 1,
  342         Unit_Kilobyte = 1024,
  343         Unit_Megabyte = 1048576,
  344         Unit_Gigabyte = 1073741824
  345 } __attribute__((__packed__)) Unit_Type;
  346 
  347 
  348 typedef enum {
  349         Hash_Unknown = 0,
  350         Hash_Md5,
  351         Hash_Sha1,
  352         Hash_Default = Hash_Md5
  353 } __attribute__((__packed__)) Hash_Type;
  354 
  355 
  356 typedef enum {
  357         Handler_Succeeded = 0x0,
  358         Handler_Alert     = 0x1,
  359         Handler_Mmonit    = 0x2,
  360         Handler_Max       = Handler_Mmonit
  361 } __attribute__((__packed__)) Handler_Type;
  362 
  363 
  364 typedef enum {
  365         MmonitCompress_Init = 0,
  366         MmonitCompress_No,
  367         MmonitCompress_Yes
  368 } __attribute__((__packed__)) MmonitCompress_Type;
  369 
  370 
  371 typedef enum {
  372         Statistics_CpuUser                      = 0x1,
  373         Statistics_CpuNice                      = 0x2,
  374         Statistics_CpuSystem                    = 0x4,
  375         Statistics_CpuIOWait                    = 0x8,
  376         Statistics_CpuHardIRQ                   = 0x10,
  377         Statistics_CpuSoftIRQ                   = 0x20,
  378         Statistics_CpuSteal                     = 0x40,
  379         Statistics_CpuGuest                     = 0x80,
  380         Statistics_CpuGuestNice                 = 0x100,
  381         Statistics_FiledescriptorsPerSystem     = 0x200,
  382         Statistics_FiledescriptorsPerProcess    = 0x400,
  383         Statistics_FiledescriptorsPerProcessMax = 0x800
  384 } __attribute__((__packed__)) Statistics_Flags;
  385 
  386 
  387 /* Length of the longest message digest in bytes */
  388 #define MD_SIZE 65
  389 
  390 
  391 #define ICMP_SIZE 64
  392 #define ICMP_MAXSIZE 1500
  393 #define ICMP_ATTEMPT_COUNT 3
  394 
  395 
  396 /* Default limits */
  397 #define LIMIT_SENDEXPECTBUFFER  256
  398 #define LIMIT_FILECONTENTBUFFER 512
  399 #define LIMIT_PROGRAMOUTPUT     512
  400 #define LIMIT_HTTPCONTENTBUFFER 1048576
  401 #define LIMIT_NETWORKTIMEOUT    5000
  402 #define LIMIT_PROGRAMTIMEOUT    300000
  403 #define LIMIT_STOPTIMEOUT       30000
  404 #define LIMIT_STARTTIMEOUT      30000
  405 #define LIMIT_RESTARTTIMEOUT    30000
  406 
  407 
  408 
  409 /** ------------------------------------------------- Special purpose macros */
  410 
  411 
  412 /* Replace the standard signal function with a more reliable using
  413  * sigaction. Taken from Stevens APUE book. */
  414 typedef void Sigfunc(int);
  415 Sigfunc *signal(int signo, Sigfunc * func);
  416 #if defined(SIG_IGN) && !defined(SIG_ERR)
  417 #define SIG_ERR ((Sigfunc *)-1)
  418 #endif
  419 
  420 
  421 /** ------------------------------------------------- General purpose macros */
  422 
  423 
  424 #undef MAX
  425 #define MAX(x,y) ((x) > (y) ? (x) : (y))
  426 #undef MIN
  427 #define MIN(x,y) ((x) < (y) ? (x) : (y))
  428 #define IS(a,b)  ((a && b) ? Str_isEqual(a, b) : false)
  429 #define DEBUG Log_debug
  430 #define FLAG(x, y) (x & y) == y
  431 #define NVLSTR(x) (x ? x : "")
  432 
  433 
  434 /** ------------------------------------------ Simple Assert Exception macro */
  435 
  436 
  437 #define ASSERT(e) do { if (!(e)) { Log_critical("AssertException: " #e \
  438 " at %s:%d\naborting..\n", __FILE__, __LINE__); abort(); } } while (0)
  439 
  440 
  441 /* --------------------------------------------------------- Data structures */
  442 
  443 
  444 /** Message Digest type with size for the longest digest we will compute */
  445 typedef char MD_T[MD_SIZE];
  446 
  447 
  448 /** Defines monit limits object */
  449 typedef struct Limits_T {
  450         int      programOutput;           /**< Program output truncate limit [B] */
  451         size_t   fileContentBuffer;  /**< Maximum tested file content length [B] */
  452         uint32_t sendExpectBuffer;  /**< Maximum send/expect response length [B] */
  453         uint32_t httpContentBuffer;  /**< Maximum tested HTTP content length [B] */
  454         uint32_t networkTimeout;               /**< Default network timeout [ms] */
  455         uint32_t programTimeout;               /**< Default program timeout [ms] */
  456         uint32_t stopTimeout;                     /**< Default stop timeout [ms] */
  457         uint32_t startTimeout;                   /**< Default start timeout [ms] */
  458         uint32_t restartTimeout;               /**< Default restart timeout [ms] */
  459 } Limits_T;
  460 
  461 
  462 /**
  463  * Defines a Command with ARGMAX optional arguments. The arguments
  464  * array must be NULL terminated and the first entry is the program
  465  * itself. In addition, a user and group may be set for the Command
  466  * which means that the Command should run as a certain user and with
  467  * certain group. To avoid name collision with Command_T in libmonit
  468  * this structure uses lower case.
  469  */
  470 typedef struct command_t {
  471         char *arg[ARGMAX];                             /**< Program with arguments */
  472         short length;                       /**< The length of the arguments array */
  473         bool has_uid;      /**< true if a new uid is defined for this Command */
  474         bool has_gid;      /**< true if a new gid is defined for this Command */
  475         uid_t uid;         /**< The user id to switch to when running this Command */
  476         gid_t gid;        /**< The group id to switch to when running this Command */
  477         unsigned int timeout;     /**< Max seconds which we wait for method to execute */
  478 } *command_t;
  479 
  480 
  481 /** Defines an event action object */
  482 typedef struct Action_T {
  483         Action_Type id;                                   /**< Action to be done */
  484         int count;                 /**< Event count needed to trigger the action */
  485         int cycles;          /**< Cycles during which count limit can be reached */
  486         int repeat;                             /*< Repeat action each Xth cycle */
  487         command_t exec;                     /**< Optional command to be executed */
  488 } *Action_T;
  489 
  490 
  491 /** Defines event's up and down actions */
  492 typedef struct EventAction_T {
  493         Action_T  failed;                  /**< Action in the case of failure down */
  494         Action_T  succeeded;                    /**< Action in the case of failure up */
  495 } *EventAction_T;
  496 
  497 
  498 /** Defines an url object */
  499 typedef struct URL_T {
  500         char *url;                                                  /**< Full URL */
  501         char *protocol;                                    /**< URL protocol type */
  502         char *user;                                        /**< URL user     part */
  503         char *password;                                    /**< URL password part */
  504         char *hostname;                                    /**< URL hostname part */
  505         char *path;                                        /**< URL path     part */
  506         char *query;                                       /**< URL query    part */
  507         int   port;                                        /**< URL port     part */
  508         bool ipv6;
  509 } *URL_T;
  510 
  511 
  512 /** Defines a HTTP client request object */
  513 typedef struct Request_T {
  514         URL_T url;                                               /**< URL request */
  515         Operator_Type operator;         /**< Response content comparison operator */
  516         regex_t *regex;                   /* regex used to test the response body */
  517 } *Request_T;
  518 
  519 
  520 /** Defines an event notification and status receiver object */
  521 typedef struct Mmonit_T {
  522         URL_T url;                                             /**< URL definition */
  523         struct SslOptions_T ssl;                               /**< SSL definition */
  524         int timeout;                /**< The timeout to wait for connection or i/o */
  525         MmonitCompress_Type compress;                        /**< Compression flag */
  526 
  527         /** For internal use */
  528         struct Mmonit_T *next;                         /**< next receiver in chain */
  529 } *Mmonit_T;
  530 
  531 
  532 /** Defines a mailinglist object */
  533 typedef struct Mail_T {
  534         char *to;                         /**< Mail address for alert notification */
  535         Address_T from;                                 /**< The mail from address */
  536         Address_T replyto;                          /**< Optional reply-to address */
  537         char *subject;                                       /**< The mail subject */
  538         char *message;                                       /**< The mail message */
  539         char *host;                                             /**< FQDN hostname */
  540         unsigned int events;  /*< Events for which this mail object should be sent */
  541         unsigned int reminder;              /*< Send error reminder each Xth cycle */
  542 
  543         /** For internal use */
  544         struct Mail_T *next;                          /**< next recipient in chain */
  545 } *Mail_T;
  546 
  547 
  548 /** Defines a mail server address */
  549 typedef struct MailServer_T {
  550         char *host;     /**< Server host address, may be a IP or a hostname string */
  551         int   port;                                               /**< Server port */
  552         char *username;                               /** < Username for SMTP_AUTH */
  553         char *password;                               /** < Password for SMTP_AUTH */
  554         struct SslOptions_T ssl;                               /**< SSL definition */
  555         Socket_T socket;                                     /**< Connected socket */
  556 
  557         /** For internal use */
  558         struct MailServer_T *next;        /**< Next server to try on connect error */
  559 } *MailServer_T;
  560 
  561 
  562 typedef struct Auth_T {
  563         char *uname;                  /**< User allowed to connect to monit httpd */
  564         char *passwd;                                /**< The users password data */
  565         char *groupname;                                      /**< PAM group name */
  566         Digest_Type digesttype;                /**< How did we store the password */
  567         bool is_readonly; /**< true if this is a read-only authenticated user*/
  568         struct Auth_T *next;                 /**< Next credential or NULL if last */
  569 } *Auth_T;
  570 
  571 
  572 /** Defines data for systemwide statistic */
  573 typedef struct SystemInfo_T {
  574         Statistics_Flags statisticsAvailable; /**< List of statistics that are available on this system */
  575         struct {
  576                 int count;                                      /**< Number of CPUs */
  577                 struct {
  578                         float user;       /**< Time in user space [%] */
  579                         float nice;       /**< Time in user space with low priority [%] */
  580                         float system;     /**< Time in kernel space [%] */
  581                         float iowait;     /**< Idle time while waiting for I/O [%] */
  582                         float hardirq;    /**< Time servicing hardware interrupts [%] */
  583                         float softirq;    /**< Time servicing software interrupts [%] */
  584                         float steal;      /**< Stolen time, which is the time spent in other operating systems when running in a virtualized environment [%] */
  585                         float guest;      /**< Time spent running a virtual CPU for guest operating systems under the control of the kernel [%] */
  586                         float guest_nice; /**< Time spent running a niced guest (virtual CPU for guest operating systems under the control of the kernel) [%] */
  587                         float idle;       /**< Idle time [%] */
  588                 } usage;
  589         } cpu;
  590         struct {
  591                 unsigned long long size;                      /**< Maximal system real memory */
  592                 struct {
  593                         float percent;  /**< Total real memory in use in the system */
  594                         unsigned long long bytes; /**< Total real memory in use in the system */
  595                 } usage;
  596         } memory;
  597         struct {
  598                 unsigned long long size;                                       /**< Swap size */
  599                 struct {
  600                         float percent;         /**< Total swap in use in the system */
  601                         unsigned long long bytes;        /**< Total swap in use in the system */
  602                 } usage;
  603         } swap;
  604         struct {
  605                 long long allocated;        /**< Number of allocated filedescriptors */
  606                 long long unused;              /**< Number of unused filedescriptors */
  607                 long long maximum;                        /**< Filedescriptors limit */
  608         } filedescriptors;
  609         size_t argmax;                                                   /**< Program arguments maximum [B] */
  610         double loadavg[3];                                                         /**< Load average triple */
  611         struct utsname uname;                                 /**< Platform information provided by uname() */
  612         struct timeval collected;                                             /**< When were data collected */
  613         unsigned long long booted; /**< System boot time (seconds since UNIX epoch, using platform-agnostic unsigned long long) */
  614         double time;                                                                      /**< 1/10 seconds */
  615         double time_prev;                                                                 /**< 1/10 seconds */
  616 } SystemInfo_T;
  617 
  618 
  619 /** Defines a protocol object with protocol functions */
  620 typedef struct Protocol_T {
  621         const char *name;                                       /**< Protocol name */
  622         void (*check)(Socket_T);          /**< Protocol verification function */
  623 } *Protocol_T;
  624 
  625 
  626 /** Defines a send/expect object used for generic protocol tests */
  627 typedef struct Generic_T {
  628         char *send;                           /* string to send, or NULL if expect */
  629         regex_t *expect;                  /* regex code to expect, or NULL if send */
  630         /** For internal use */
  631         struct Generic_T *next;
  632 } *Generic_T;
  633 
  634 
  635 typedef struct Outgoing_T {
  636         char *ip;                                         /**< Outgoing IP address */
  637         struct sockaddr_storage addr;
  638         socklen_t addrlen;
  639 } Outgoing_T;
  640 
  641 
  642 typedef struct ResponseTime_T {
  643         Operator_Type operator;
  644         double current;                            /**< Current response time [ms] */
  645         double limit;                                /**< Response time limit [ms] */
  646 } ResponseTime_T;
  647 
  648 
  649 /** Defines a port object */
  650 typedef struct Port_T {
  651         char *hostname;                                     /**< Hostname to check */
  652         union {
  653                 struct {
  654                         char *pathname;                  /**< Unix socket pathname */
  655                 } unix;
  656                 struct {
  657                         int port;                                 /**< Port number */
  658                         struct {
  659                                 struct SslOptions_T options;
  660                                 struct {
  661                                         int validDays;
  662                                         int minimumDays;
  663                                 } certificate;
  664                         } ssl;
  665                 } net;
  666         } target;
  667         Outgoing_T outgoing;                                 /**< Outgoing address */
  668         bool check_invers;           /**< Whether to alert on a connection success */
  669         int timeout;      /**< The timeout in [ms] to wait for connect or read i/o */
  670         int retry;       /**< Number of connection retry before reporting an error */
  671         volatile int socket;                       /**< Socket used for connection */
  672         struct ResponseTime_T responsetime;               /**< Response time limit */
  673         Socket_Type type;           /**< Socket type used for connection (UDP/TCP) */
  674         Socket_Family family;    /**< Socket family used for connection (NET/UNIX) */
  675         Connection_State is_available;               /**< Server/port availability */
  676         EventAction_T action; /**< Description of the action upon event occurrence */
  677         /** Protocol specific parameters */
  678         union {
  679                 struct {
  680                         char *username;
  681                         char *password;
  682                         char *path;                                              /**< status path */
  683                         short loglimit;                  /**< Max percentage of logging processes */
  684                         short closelimit;             /**< Max percentage of closinging processes */
  685                         short dnslimit;         /**< Max percentage of processes doing DNS lookup */
  686                         short keepalivelimit;          /**< Max percentage of keepalive processes */
  687                         short replylimit;               /**< Max percentage of replying processes */
  688                         short requestlimit;     /**< Max percentage of processes reading requests */
  689                         short startlimit;            /**< Max percentage of processes starting up */
  690                         short waitlimit;  /**< Min percentage of processes waiting for connection */
  691                         short gracefullimit;/**< Max percentage of processes gracefully finishing */
  692                         short cleanuplimit;      /**< Max percentage of processes in idle cleanup */
  693                         Operator_Type loglimitOP;                          /**< loglimit operator */
  694                         Operator_Type closelimitOP;                      /**< closelimit operator */
  695                         Operator_Type dnslimitOP;                          /**< dnslimit operator */
  696                         Operator_Type keepalivelimitOP;              /**< keepalivelimit operator */
  697                         Operator_Type replylimitOP;                      /**< replylimit operator */
  698                         Operator_Type requestlimitOP;                  /**< requestlimit operator */
  699                         Operator_Type startlimitOP;                      /**< startlimit operator */
  700                         Operator_Type waitlimitOP;                        /**< waitlimit operator */
  701                         Operator_Type gracefullimitOP;                /**< gracefullimit operator */
  702                         Operator_Type cleanuplimitOP;                  /**< cleanuplimit operator */
  703                 } apachestatus;
  704                 struct {
  705                         Generic_T sendexpect;
  706                 } generic;
  707                 struct {
  708                         Hash_Type hashtype;           /**< Type of hash for a checksum (optional) */
  709                         bool hasStatus;                    /**< Is explicit HTTP status set? */
  710                         Operator_Type operator;                         /**< HTTP status operator */
  711                         Http_Method method;
  712                         int status;                                              /**< HTTP status */
  713                         char *username;
  714                         char *password;
  715                         char *request;                                          /**< HTTP request */
  716                         char *checksum;                         /**< Document checksum (optional) */
  717                         List_T headers;      /**< List of headers to send with request (optional) */
  718                 } http;
  719                 struct {
  720                         char *username;
  721                         char *password;
  722                 } mqtt;
  723                 struct {
  724                         char *username;
  725                         char *password;
  726                         char *rsaChecksum;
  727                         Hash_Type rsaChecksumType;
  728                 } mysql;
  729                 struct {
  730                         char *secret;
  731                 } radius;
  732                 struct {
  733                         int maxforward;
  734                         char *target;
  735                 } sip;
  736                 struct {
  737                         char *username;
  738                         char *password;
  739                 } smtp;
  740                 struct {
  741                         int version;
  742                         char *host;
  743                         char *origin;
  744                         char *request;
  745                 } websocket;
  746         } parameters;
  747         Protocol_T protocol;     /**< Protocol object for testing a port's service */
  748         Request_T url_request;             /**< Optional url client request object */
  749 
  750         /** For internal use */
  751         struct Port_T *next;                               /**< next port in chain */
  752 } *Port_T;
  753 
  754 
  755 /** Defines a ICMP/Ping object */
  756 typedef struct Icmp_T {
  757         int type;                                              /**< ICMP type used */
  758         int size;                                     /**< ICMP echo requests size */
  759         int count;                                   /**< ICMP echo requests count */
  760         int timeout;         /**< The timeout in milliseconds to wait for response */
  761         bool check_invers;           /**< Whether to alert on a connection success */
  762         Connection_State is_available;    /**< Flag for the server is availability */
  763         Socket_Family family;                 /**< ICMP family used for connection */
  764         struct ResponseTime_T responsetime;               /**< Response time limit */
  765         Outgoing_T outgoing;                                 /**< Outgoing address */
  766         EventAction_T action; /**< Description of the action upon event occurrence */
  767 
  768         /** For internal use */
  769         struct Icmp_T *next;                               /**< next icmp in chain */
  770 } *Icmp_T;
  771 
  772 
  773 typedef struct Dependant_T {
  774         char *dependant;                            /**< name of dependant service */
  775         char *dependant_urlescaped;     /**< URL escaped name of dependant service */
  776         StringBuffer_T dependant_htmlescaped; /**< HTML escaped name of dependant service */
  777 
  778         /** For internal use */
  779         struct Dependant_T *next;             /**< next dependant service in chain */
  780 } *Dependant_T;
  781 
  782 
  783 /** Defines resource data */
  784 typedef struct Resource_T {
  785         Resource_Type resource_id;                     /**< Which value is checked */
  786         Operator_Type operator;                           /**< Comparison operator */
  787         double limit;                                   /**< Limit of the resource */
  788         EventAction_T action; /**< Description of the action upon event occurrence */
  789 
  790         /** For internal use */
  791         struct Resource_T *next;                       /**< next resource in chain */
  792 } *Resource_T;
  793 
  794 
  795 /** Defines timestamp object */
  796 typedef struct Timestamp_T {
  797         bool initialized;              /**< true if timestamp was initialized */
  798         bool test_changes;       /**< true if we only should test for changes */
  799         Timestamp_Type type;
  800         Operator_Type operator;                           /**< Comparison operator */
  801         unsigned long long time;                                    /**< Timestamp watermark */
  802         time_t lastTimestamp;        /**< Last timestamp (context depends on type) */
  803         EventAction_T action; /**< Description of the action upon event occurrence */
  804 
  805         /** For internal use */
  806         struct Timestamp_T *next;                     /**< next timestamp in chain */
  807 } *Timestamp_T;
  808 
  809 
  810 /** Defines action rate object */
  811 typedef struct ActionRate_T {
  812         int  count;                                            /**< Action counter */
  813         int  cycle;                                             /**< Cycle counter */
  814         EventAction_T action;    /**< Description of the action upon matching rate */
  815 
  816         /** For internal use */
  817         struct ActionRate_T *next;                   /**< next actionrate in chain */
  818 } *ActionRate_T;
  819 
  820 
  821 /** Defines when to run a check for a service. This type supports both the old
  822  cycle based every statement and the new cron-format version */
  823 typedef struct Every_T {
  824         Every_Type type; /**< 0 = not set, 1 = cycle, 2 = cron, 3 = negated cron */
  825         time_t last_run;
  826         union {
  827                 struct {
  828                         int number; /**< Check this program at a given cycles */
  829                         int counter; /**< Counter for number. When counter == number, check */
  830                 } cycle; /**< Old cycle based every check */
  831                 char *cron; /* A crontab format string */
  832         } spec;
  833 } Every_T;
  834 
  835 
  836 typedef struct Status_T {
  837         bool initialized;                 /**< true if status was initialized */
  838         Operator_Type operator;                           /**< Comparison operator */
  839         int return_value;                /**< Return value of the program to check */
  840         EventAction_T action; /**< Description of the action upon event occurrence */
  841 
  842         /** For internal use */
  843         struct Status_T *next;                       /**< next exit value in chain */
  844 } *Status_T;
  845 
  846 
  847 typedef struct Program_T {
  848         Process_T P;          /**< A Process_T object representing the sub-process */
  849         Command_T C;          /**< A Command_T object for creating the sub-process */
  850         command_t args;                                     /**< Program arguments */
  851         time_t started;                      /**< When the sub-process was started */
  852         int timeout;           /**< Seconds the program may run until it is killed */
  853         int exitStatus;                 /**< Sub-process exit status for reporting */
  854         StringBuffer_T lastOutput;                        /**< Last program output */
  855         StringBuffer_T inprogressOutput; /**< Output of the pending program instance */
  856 } *Program_T;
  857 
  858 
  859 /** Defines size object */
  860 typedef struct Size_T {
  861         bool initialized;                   /**< true if size was initialized */
  862         bool test_changes;       /**< true if we only should test for changes */
  863         Operator_Type operator;                           /**< Comparison operator */
  864         unsigned long long size;                               /**< Size watermark */
  865         EventAction_T action; /**< Description of the action upon event occurrence */
  866 
  867         /** For internal use */
  868         struct Size_T *next;                               /**< next size in chain */
  869 } *Size_T;
  870 
  871 
  872 /** Defines uptime object */
  873 typedef struct Uptime_T {
  874         Operator_Type operator;                           /**< Comparison operator */
  875         unsigned long long uptime;                           /**< Uptime watermark */
  876         EventAction_T action; /**< Description of the action upon event occurrence */
  877 
  878         /** For internal use */
  879         struct Uptime_T *next;                           /**< next uptime in chain */
  880 } *Uptime_T;
  881 
  882 
  883 typedef struct LinkStatus_T {
  884         bool check_invers;                      /**< Whether to alert on a link up */
  885         EventAction_T action; /**< Description of the action upon event occurrence */
  886 
  887         /** For internal use */
  888         struct LinkStatus_T *next;                      /**< next link in chain */
  889 } *LinkStatus_T;
  890 
  891 
  892 typedef struct LinkSpeed_T {
  893         int duplex;                                        /**< Last duplex status */
  894         long long speed;                                     /**< Last speed [bps] */
  895         EventAction_T action; /**< Description of the action upon event occurrence */
  896 
  897         /** For internal use */
  898         struct LinkSpeed_T *next;                       /**< next link in chain */
  899 } *LinkSpeed_T;
  900 
  901 
  902 typedef struct LinkSaturation_T {
  903         Operator_Type operator;                           /**< Comparison operator */
  904         float limit;                                     /**< Saturation limit [%] */
  905         EventAction_T action; /**< Description of the action upon event occurrence */
  906 
  907         /** For internal use */
  908         struct LinkSaturation_T *next;                  /**< next link in chain */
  909 } *LinkSaturation_T;
  910 
  911 
  912 typedef struct Bandwidth_T {
  913         Operator_Type operator;                           /**< Comparison operator */
  914         Time_Type range;                            /**< Time range to watch: unit */
  915         int rangecount;                            /**< Time range to watch: count */
  916         unsigned long long limit;                              /**< Data watermark */
  917         EventAction_T action; /**< Description of the action upon event occurrence */
  918 
  919         /** For internal use */
  920         struct Bandwidth_T *next;                     /**< next bandwidth in chain */
  921 } *Bandwidth_T;
  922 
  923 
  924 /** Defines checksum object */
  925 typedef struct Checksum_T {
  926         bool initialized;                    /**< true if checksum was initialized */
  927         bool test_changes;            /**< true if we only should test for changes */
  928         Hash_Type type;                   /**< The type of hash (e.g. md5 or sha1) */
  929         int   length;                                      /**< Length of the hash */
  930         char  hash[MD_SIZE + 1];        /**< A checksum hash computed for the path */
  931         EventAction_T action; /**< Description of the action upon event occurrence */
  932 } *Checksum_T;
  933 
  934 
  935 /** Defines permission object */
  936 typedef struct Perm_T {
  937         bool test_changes;       /**< true if we only should test for changes */
  938         int perm;                                           /**< Access permission */
  939         EventAction_T action; /**< Description of the action upon event occurrence */
  940 } *Perm_T;
  941 
  942 /** Defines match object */
  943 typedef struct Match_T {
  944         bool ignore;                                        /**< Ignore match */
  945         bool not;                                           /**< Invert match */
  946         char    *match_string;                                   /**< Match string */ //FIXME: union?
  947         char    *match_path;                         /**< File with matching rules */ //FIXME: union?
  948         regex_t *regex_comp;                                    /**< Match compile */
  949         StringBuffer_T log;   /**< The temporary buffer used to record the matches */
  950         EventAction_T action; /**< Description of the action upon event occurrence */
  951 
  952         /** For internal use */
  953         struct Match_T *next;                             /**< next match in chain */
  954 } *Match_T;
  955 
  956 
  957 /** Defines uid object */
  958 typedef struct Uid_T {
  959         uid_t     uid;                                            /**< Owner's uid */
  960         EventAction_T action; /**< Description of the action upon event occurrence */
  961 } *Uid_T;
  962 
  963 
  964 /** Defines gid object */
  965 typedef struct Gid_T {
  966         gid_t     gid;                                            /**< Owner's gid */
  967         EventAction_T action; /**< Description of the action upon event occurrence */
  968 } *Gid_T;
  969 
  970 
  971 typedef struct SecurityAttribute_T {
  972         char *attribute;                                   /**< Security attribute */
  973         EventAction_T action; /**< Description of the action upon event occurrence */
  974 
  975         /** For internal use */
  976         struct SecurityAttribute_T *next;
  977 } *SecurityAttribute_T;
  978 
  979 typedef struct Filedescriptors_T {
  980         bool total;             /**<Whether to include filedescriptors of children */
  981         long long limit_absolute;                      /**<  Filedescriptors limit */
  982         float limit_percent;                            /**< Filedescriptors limit */
  983         Operator_Type operator;                           /**< Comparison operator */
  984         EventAction_T action; /**< Description of the action upon event occurrence */
  985 
  986         /** For internal use */
  987         struct Filedescriptors_T *next;
  988 } *Filedescriptors_T;
  989 
  990 /** Defines pid object */
  991 typedef struct Pid_T {
  992         EventAction_T action; /**< Description of the action upon event occurrence */
  993 
  994         /** For internal use */
  995         struct Pid_T *next;                                 /**< next pid in chain */
  996 } *Pid_T;
  997 
  998 
  999 typedef struct FsFlag_T {
 1000         EventAction_T action; /**< Description of the action upon event occurrence */
 1001 
 1002         /** For internal use */
 1003         struct FsFlag_T *next;
 1004 } *FsFlag_T;
 1005 
 1006 
 1007 typedef struct NonExist_T {
 1008         EventAction_T action; /**< Description of the action upon event occurrence */
 1009 
 1010         /** For internal use */
 1011         struct NonExist_T *next;
 1012 } *NonExist_T;
 1013 
 1014 
 1015 typedef struct Exist_T {
 1016         EventAction_T action; /**< Description of the action upon event occurrence */
 1017 
 1018         /** For internal use */
 1019         struct Exist_T *next;
 1020 } *Exist_T;
 1021 
 1022 
 1023 /** Defines filesystem configuration */
 1024 typedef struct FileSystem_T {
 1025         Resource_Type resource;               /**< Whether to check inode or space */
 1026         Operator_Type operator;                           /**< Comparison operator */
 1027         //FIXME: union
 1028         long long limit_absolute;                          /**< Watermark - blocks */
 1029         float limit_percent;                              /**< Watermark - percent */
 1030         EventAction_T action; /**< Description of the action upon event occurrence */
 1031 
 1032         /** For internal use */
 1033         struct FileSystem_T *next;                   /**< next filesystem in chain */
 1034 } *FileSystem_T;
 1035 
 1036 
 1037 typedef struct IOStatistics_T {
 1038         struct Statistics_T operations;                                         /**< Number of operations completed */
 1039         struct Statistics_T bytes;          /**< Number of bytes handled by operations (total including cached I/O) */
 1040         struct Statistics_T bytesPhysical;           /**< Number of bytes handled by operations (physical I/O only) */
 1041 } *IOStatistics_T;
 1042 
 1043 
 1044 typedef struct Device_T {
 1045         bool mounted;
 1046         int generation;
 1047         int instance;
 1048         struct {
 1049                 int major;
 1050                 int minor;
 1051         } number;
 1052         char partition;
 1053         char device[PATH_MAX];
 1054         char mountpoint[PATH_MAX];
 1055         char key[PATH_MAX];
 1056         char module[256];
 1057         char type[64];
 1058         unsigned long long flags;
 1059         bool (*getDiskUsage)(void *);
 1060         bool (*getDiskActivity)(void *);
 1061 } *Device_T;
 1062 
 1063 
 1064 typedef struct TimestampInfo_T {
 1065         unsigned long long access;
 1066         unsigned long long change;
 1067         unsigned long long modify;
 1068 } *TimestampInfo_T;
 1069 
 1070 
 1071 typedef struct FileSystemInfo_T {
 1072         long long  f_blocks;              /**< Total data blocks in filesystem */
 1073         long long  f_blocksfree;   /**< Free blocks available to non-superuser */
 1074         long long  f_blocksfreetotal;           /**< Free blocks in filesystem */
 1075         long long  f_blocksused;                  /**< Used space total blocks */
 1076         long long  f_files;                /**< Total file nodes in filesystem */
 1077         long long  f_filesfree;             /**< Free file nodes in filesystem */
 1078         long long  f_filesused;                  /**< Used inode total objects */
 1079         float inode_percent;                        /**< Used inode percentage */
 1080         float space_percent;                        /**< Used space percentage */
 1081         int f_bsize;                                  /**< Transfer block size */
 1082         int uid;                                              /**< Owner's uid */
 1083         int gid;                                              /**< Owner's gid */
 1084         int mode;                                              /**< Permission */
 1085         char flags[STRLEN];                              /**< Filesystem flags */
 1086         bool flagsChanged;          /**< True if filesystem flags changed */
 1087         struct IOStatistics_T read;                       /**< Read statistics */
 1088         struct IOStatistics_T write;                     /**< Write statistics */
 1089         struct {
 1090                 struct Statistics_T read;         /**< Time spend by read [ms] */
 1091                 struct Statistics_T write;       /**< Time spend by write [ms] */
 1092                 struct Statistics_T wait;   /**< Time spend in wait queue [ms] */
 1093                 struct Statistics_T run;     /**< Time spend in run queue [ms] */
 1094         } time;
 1095         struct Device_T object;                             /**< Device object */
 1096 } *FileSystemInfo_T;
 1097 
 1098 
 1099 typedef struct FileInfo_T {
 1100         struct TimestampInfo_T timestamp;
 1101         int mode;                                              /**< Permission */
 1102         int uid;                                              /**< Owner's uid */
 1103         int gid;                                              /**< Owner's gid */
 1104         off_t size;                                                  /**< Size */
 1105         off_t readpos;                        /**< Position for regex matching */
 1106         ino_t inode;                                                /**< Inode */
 1107         ino_t inode_prev;               /**< Previous inode for regex matching */
 1108         MD_T  cs_sum;                                            /**< Checksum */ //FIXME: allocate dynamically only when necessary
 1109 } *FileInfo_T;
 1110 
 1111 
 1112 typedef struct DirectoryInfo_T {
 1113         struct TimestampInfo_T timestamp;
 1114         int mode;                                              /**< Permission */
 1115         int uid;                                              /**< Owner's uid */
 1116         int gid;                                              /**< Owner's gid */
 1117 } *DirectoryInfo_T;
 1118 
 1119 
 1120 typedef struct FifoInfo_T {
 1121         struct TimestampInfo_T timestamp;
 1122         int mode;                                              /**< Permission */
 1123         int uid;                                              /**< Owner's uid */
 1124         int gid;                                              /**< Owner's gid */
 1125 } *FifoInfo_T;
 1126 
 1127 
 1128 typedef struct ProcessInfo_T {
 1129         bool zombie;
 1130         pid_t _pid;                           /**< Process PID from last cycle */
 1131         pid_t _ppid;                   /**< Process parent PID from last cycle */
 1132         pid_t pid;                          /**< Process PID from actual cycle */
 1133         pid_t ppid;                  /**< Process parent PID from actual cycle */
 1134         int uid;                                              /**< Process UID */
 1135         int euid;                                   /**< Effective Process UID */
 1136         int gid;                                              /**< Process GID */
 1137         int threads;
 1138         int children;
 1139         unsigned long long mem;
 1140         unsigned long long total_mem;
 1141         float mem_percent;                                     /**< percentage */
 1142         float total_mem_percent;                               /**< percentage */
 1143         float cpu_percent;                                     /**< percentage */
 1144         float total_cpu_percent;                               /**< percentage */
 1145         time_t uptime;                                     /**< Process uptime */
 1146         struct IOStatistics_T read;                       /**< Read statistics */
 1147         struct IOStatistics_T write;                     /**< Write statistics */
 1148         char secattr[STRLEN];                         /**< Security attributes */
 1149         struct {
 1150                 long long open;                        /**< number of opened files */
 1151                 long long openTotal;             /**< number of total opened files */
 1152                 struct {
 1153                         long long soft;                 /**< Filedescriptors soft limit */
 1154                         long long hard;                 /**< Filedescriptors hard limit */
 1155                 } limit;
 1156         } filedescriptors;
 1157 } *ProcessInfo_T;
 1158 
 1159 
 1160 typedef struct NetInfo_T {
 1161         Link_T stats;
 1162 } *NetInfo_T;
 1163 
 1164 
 1165 /** Defines service data */
 1166 typedef union Info_T {
 1167         //FIXME: move global SystemInfo_T systeminfo here (for System service context)
 1168         DirectoryInfo_T  directory;
 1169         FifoInfo_T       fifo;
 1170         FileInfo_T       file;
 1171         FileSystemInfo_T filesystem;
 1172         NetInfo_T        net;
 1173         ProcessInfo_T    process;
 1174 } *Info_T;
 1175 
 1176 
 1177 /** Defines service data */
 1178 //FIXME: use union for type-specific rules
 1179 typedef struct Service_T {
 1180 
 1181         /** Common parameters */
 1182         char *name;                                  /**< Service descriptive name */
 1183         char *name_urlescaped;                       /**< Service name URL escaped */
 1184         StringBuffer_T name_htmlescaped;            /**< Service name HTML escaped */
 1185         State_Type (*check)(struct Service_T *);/**< Service verification function */
 1186         bool onrebootRestored;
 1187         bool visited; /**< Service visited flag, set if dependencies are used */
 1188         bool inverseStatus;
 1189         Service_Type type;                             /**< Monitored service type */
 1190         Monitor_State monitor;                             /**< Monitor state flag */
 1191         Monitor_Mode mode;                    /**< Monitoring mode for the service */
 1192         Onreboot_Type onreboot;                                /**< On reboot mode */
 1193         Action_Type doaction;                 /**< Action scheduled by http thread */
 1194         int  ncycle;                          /**< The number of the current cycle */
 1195         int  nstart;           /**< The number of current starts with this service */
 1196         Every_T every;              /**< Timespec for when to run check of service */
 1197         command_t start;                    /**< The start command for the service */
 1198         command_t stop;                      /**< The stop command for the service */
 1199         command_t restart;                /**< The restart command for the service */
 1200         Program_T program;                            /**< Program execution check */
 1201 
 1202         Dependant_T dependantlist;                     /**< Dependant service list */
 1203         Mail_T maillist;                       /**< Alert notification mailinglist */
 1204 
 1205         /** Test rules and event handlers */
 1206         ActionRate_T actionratelist;                    /**< ActionRate check list */
 1207         Checksum_T  checksum;                                  /**< Checksum check */
 1208         FileSystem_T filesystemlist;                    /**< Filesystem check list */
 1209         Icmp_T      icmplist;                                 /**< ICMP check list */
 1210         Perm_T      perm;                                    /**< Permission check */
 1211         Port_T      portlist;                            /**< Portnumbers to check */
 1212         Port_T      socketlist;                         /**< Unix sockets to check */
 1213         Resource_T  resourcelist;                         /**< Resource check list */
 1214         Size_T      sizelist;                                 /**< Size check list */
 1215         Uptime_T    uptimelist;                             /**< Uptime check list */
 1216         Match_T     matchlist;                             /**< Content Match list */
 1217         Match_T     matchignorelist;                /**< Content Match ignore list */
 1218         Timestamp_T timestamplist;                       /**< Timestamp check list */
 1219         Pid_T       pidlist;                                   /**< Pid check list */
 1220         Pid_T       ppidlist;                                 /**< PPid check list */
 1221         Status_T    statuslist;           /**< Program execution status check list */
 1222         FsFlag_T    fsflaglist;           /**< Action upon filesystem flags change */
 1223         NonExist_T  nonexistlist;      /**< Actions if test subject does not exist */
 1224         Exist_T     existlist;                  /**< Actions if test subject exist */
 1225         Uid_T       uid;                                            /**< Uid check */
 1226         Uid_T       euid;                                 /**< Effective Uid check */
 1227         Gid_T       gid;                                            /**< Gid check */
 1228         SecurityAttribute_T secattrlist;             /**< Security attributes list */
 1229         Filedescriptors_T filedescriptorslist;                   /**< Filedescriptors list */
 1230         LinkStatus_T linkstatuslist;                 /**< Network link status list */
 1231         LinkSpeed_T linkspeedlist;                    /**< Network link speed list */
 1232         LinkSaturation_T linksaturationlist;     /**< Network link saturation list */
 1233         Bandwidth_T uploadbyteslist;                  /**< Upload bytes check list */
 1234         Bandwidth_T uploadpacketslist;              /**< Upload packets check list */
 1235         Bandwidth_T downloadbyteslist;              /**< Download bytes check list */
 1236         Bandwidth_T downloadpacketslist;          /**< Download packets check list */
 1237 
 1238         /** General event handlers */
 1239         EventAction_T action_DATA;       /**< Description of the action upon event */
 1240         EventAction_T action_EXEC;       /**< Description of the action upon event */
 1241         EventAction_T action_INVALID;    /**< Description of the action upon event */
 1242 
 1243         /** Internal monit events */
 1244         EventAction_T action_MONIT_START;  /**< Monit instance start/reload action */
 1245         EventAction_T action_MONIT_STOP;           /**< Monit instance stop action */
 1246         EventAction_T action_ACTION;           /**< Action requested by CLI or GUI */
 1247 
 1248         /** Runtime parameters */
 1249         int                error;                          /**< Error flags bitmap */
 1250         int                error_hint;   /**< Failed/Changed hint for error bitmap */
 1251         union Info_T       inf;                          /**< Service check result */
 1252         struct timeval     collected;                /**< When were data collected */ //FIXME: replace with unsigned long long? (all places where timeval is used) ... Time_milli()?
 1253 
 1254         /** Events */
 1255         struct myevent {
 1256                 #define           EVENT_VERSION  4      /**< The event structure version */
 1257                 long              id;                      /**< The event identification */
 1258                 struct timeval    collected;                /**< When the event occurred */
 1259                 struct Service_T *source;                              /**< Event source */
 1260                 Monitor_Mode      mode;             /**< Monitoring mode for the service */
 1261                 Service_Type      type;                      /**< Monitored service type */
 1262                 State_Type        state;                                 /**< Test state */
 1263                 bool         state_changed;              /**< true if state changed */
 1264                 Handler_Type      flag;                     /**< The handlers state flag */
 1265                 long long         state_map;           /**< Event bitmap for last cycles */
 1266                 unsigned int      count;                             /**< The event rate */
 1267                 char             *message;    /**< Optional message describing the event */
 1268                 EventAction_T     action;           /**< Description of the event action */
 1269                 /** For internal use */
 1270                 struct myevent   *next;                         /**< next event in chain */
 1271         } *eventlist;                                     /**< Pending events list */
 1272 
 1273         /** Context specific parameters */
 1274         char *path;  /**< Path to the filesys, file, directory or process pid file */
 1275 
 1276         /** For internal use */
 1277         Mutex_T mutex;                  /**< Mutex used for action synchronization */
 1278         struct Service_T *next;                         /**< next service in chain */
 1279         struct Service_T *next_conf;      /**< next service according to conf file */
 1280         struct Service_T *next_depend;           /**< next depend service in chain */
 1281 } *Service_T;
 1282 
 1283 
 1284 typedef struct myevent *Event_T;
 1285 
 1286 
 1287 typedef struct ServiceGroup_T {
 1288         char *name;                                     /**< name of service group */
 1289         List_T members;                                 /**< Service group members */
 1290 
 1291         /** For internal use */
 1292         struct ServiceGroup_T *next;              /**< next service group in chain */
 1293 } *ServiceGroup_T;
 1294 
 1295 
 1296 /** Data for application runtime */
 1297 struct Run_T {
 1298         uint8_t debug;                                            /**< Debug level */
 1299         volatile Run_Flags flags;
 1300         Handler_Type handler_flag;                    /**< The handlers state flag */
 1301         Onreboot_Type onreboot;
 1302         struct {
 1303                 char *control;            /**< The file to read configuration from */
 1304                 char *log;                     /**< The file to write logdata into */
 1305                 char *pid;                              /**< This programs pidfile */
 1306                 char *id;                       /**< The file with unique monit id */
 1307                 char *state;            /**< The file with the saved runtime state */
 1308         } files;
 1309         char *mygroup;                              /**< Group Name of the Service */
 1310         MD_T id;                                              /**< Unique monit id */
 1311         Limits_T limits;                                       /**< Default limits */
 1312         struct SslOptions_T ssl;                          /**< Default SSL options */
 1313         int  polltime;        /**< In daemon mode, the sleeptime (sec) between run */
 1314         int  startdelay;  /**< the sleeptime [s] on first start after machine boot */
 1315         int  facility;              /** The facility to use when running openlog() */
 1316         int  eventlist_slots;          /**< The event queue size - number of slots */
 1317         int mailserver_timeout; /**< Connect and read timeout ms for a SMTP server */
 1318         time_t incarnation;              /**< Unique ID for running monit instance */
 1319         int  handler_queue[Handler_Max + 1];       /**< The handlers queue counter */
 1320         Service_T system;                          /**< The general system service */
 1321         char *eventlist_dir;                   /**< The event queue base directory */
 1322 
 1323         /** An object holding Monit HTTP interface setup */
 1324         struct {
 1325                 Httpd_Flags flags;
 1326                 struct {
 1327                         struct {
 1328                                 int  port;
 1329                                 char *address;
 1330                                 struct SslOptions_T ssl;
 1331                         } net;
 1332                         struct {
 1333                                 int uid;
 1334                                 int gid;
 1335                                 int permission;
 1336                                 char *path;
 1337                         } unix;
 1338                 } socket;
 1339                 Auth_T credentials;
 1340         } httpd;
 1341 
 1342         /** An object holding program relevant "environment" data, see: env.c */
 1343         struct myenvironment {
 1344                 char *user;             /**< The the effective user running this program */
 1345                 char *home;                                    /**< Users home directory */
 1346                 char *cwd;                                /**< Current working directory */
 1347         } Env;
 1348 
 1349         char *mail_hostname;    /**< Used in HELO/EHLO/MessageID when sending mail */
 1350         Mail_T maillist;                /**< Global alert notification mailinglist */
 1351         MailServer_T mailservers;    /**< List of MTAs used for alert notification */
 1352         Mmonit_T mmonits;        /**< Event notification and status receivers list */
 1353         Auth_T mmonitcredentials;     /**< Pointer to selected credentials or NULL */
 1354         /** User selected standard mail format */
 1355         struct myformat {
 1356                 Address_T from;                      /**< The standard mail from address */
 1357                 Address_T replyto;                         /**< Optional reply-to header */
 1358                 char *subject;                            /**< The standard mail subject */
 1359                 char *message;                            /**< The standard mail message */
 1360         } MailFormat;
 1361 
 1362         Mutex_T mutex;            /**< Mutex used for service data synchronization */
 1363 };
 1364 
 1365 
 1366 /* -------------------------------------------------------- Global variables */
 1367 
 1368 
 1369 extern const char    *prog;
 1370 extern struct Run_T   Run;
 1371 extern Service_T      servicelist;
 1372 extern Service_T      servicelist_conf;
 1373 extern ServiceGroup_T servicegrouplist;
 1374 extern SystemInfo_T   systeminfo;
 1375 
 1376 extern const char *actionnames[];
 1377 extern const char *modenames[];
 1378 extern const char *onrebootnames[];
 1379 extern const char *checksumnames[];
 1380 extern const char *operatornames[];
 1381 extern const char *operatorshortnames[];
 1382 extern const char *servicetypes[];
 1383 extern const char *pathnames[];
 1384 extern const char *icmpnames[];
 1385 extern const char *socketnames[];
 1386 extern const char *timestampnames[];
 1387 extern const char *httpmethod[];
 1388 
 1389 
 1390 /* ------------------------------------------------------- Public prototypes */
 1391 
 1392 #include "util.h"
 1393 #include "file.h"
 1394 
 1395 // libmonit
 1396 #include "system/Mem.h"
 1397 
 1398 
 1399 /* FIXME: move remaining prototypes into separate header-files */
 1400 
 1401 bool parse(char *);
 1402 bool control_service(const char *, Action_Type);
 1403 bool control_service_string(List_T, const char *);
 1404 void spawn(Service_T, command_t, Event_T);
 1405 bool Log_init(void);
 1406 void Log_emergency(const char *, ...) __attribute__((format (printf, 1, 2)));
 1407 void Log_alert(const char *, ...) __attribute__((format (printf, 1, 2)));
 1408 void Log_critical(const char *, ...) __attribute__((format (printf, 1, 2)));
 1409 void Log_error(const char *, ...) __attribute__((format (printf, 1, 2)));
 1410 void Log_warning(const char *, ...) __attribute__((format (printf, 1, 2)));
 1411 void Log_notice(const char *, ...) __attribute__((format (printf, 1, 2)));
 1412 void Log_info(const char *, ...) __attribute__((format (printf, 1, 2)));
 1413 void Log_debug(const char *, ...) __attribute__((format (printf, 1, 2)));
 1414 void Log_vemergency(const char *, va_list ap) __attribute__((format (printf, 1, 0)));
 1415 void Log_valert(const char *, va_list ap) __attribute__((format (printf, 1, 0)));
 1416 void Log_vcritical(const char *, va_list ap) __attribute__((format (printf, 1, 0)));
 1417 void Log_verror(const char *, va_list ap) __attribute__((format (printf, 1, 0)));
 1418 void Log_vwarning(const char *,va_list ap) __attribute__((format (printf, 1, 0)));
 1419 void Log_vnotice(const char *, va_list ap) __attribute__((format (printf, 1, 0)));
 1420 void Log_vinfo(const char *, va_list ap) __attribute__((format (printf, 1, 0)));
 1421 void Log_vdebug(const char *, va_list ap) __attribute__((format (printf, 1, 0)));
 1422 void Log_abort_handler(const char *s, va_list ap) __attribute__((format (printf, 1, 0))) __attribute__((noreturn));
 1423 void Log_close(void);
 1424 int   validate(void);
 1425 void  daemonize(void);
 1426 void  gc(void);
 1427 void  gc_mail_list(Mail_T *);
 1428 void  gccmd(command_t *);
 1429 void  gc_event(Event_T *e);
 1430 bool kill_daemon(int);
 1431 int   exist_daemon(void);
 1432 bool sendmail(Mail_T);
 1433 void  init_env(void);
 1434 void  monit_http(Httpd_Action);
 1435 bool can_http(void);
 1436 void set_signal_block(void);
 1437 State_Type check_process(Service_T);
 1438 State_Type check_filesystem(Service_T);
 1439 State_Type check_file(Service_T);
 1440 State_Type check_directory(Service_T);
 1441 State_Type check_remote_host(Service_T);
 1442 State_Type check_system(Service_T);
 1443 State_Type check_fifo(Service_T);
 1444 State_Type check_program(Service_T);
 1445 State_Type check_net(Service_T);
 1446 int  check_URL(Service_T s);
 1447 void status_xml(StringBuffer_T, Event_T, int, const char *);
 1448 bool  do_wakeupcall(void);
 1449 bool interrupt(void);
 1450 
 1451 #endif