#include "dnxServerMain.h"
#include "dnxNebMain.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxCfgParser.h"
#include "dnxLogging.h"
#include "dnxCollector.h"
#include "dnxDispatcher.h"
#include "dnxRegistrar.h"
#include "dnxJobList.h"
#include "dnxStats.h"
#include "dnxXml.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include <signal.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
Go to the source code of this file.
Data Structures | |
struct | DnxCfgData |
The internal server module configuration data structure. More... | |
Defines | |
#define | VERSION "<unknown>" |
#define | SYSCONFDIR "/etc" |
#define | SYSLOGDIR "/var/log" |
#define | COMPILE_FLAGS "<unknown>" |
#define | elemcount(x) (sizeof(x)/sizeof(*(x))) |
#define | DNX_DEFAULT_SERVER_CONFIG_FILE SYSCONFDIR "/dnxServer.cfg" |
#define | DNX_DEFAULT_LOG SYSLOGDIR "/dnxsrv.log" |
#define | DNX_DEFAULT_DBGLOG SYSLOGDIR "/dnxsrv.dbg.log" |
#define | DNX_DEFAULT_SERVER_PATH SYSBINDIR "/dnxServer" |
#define | OL_CFGFILE |
#define | OL_QUEUESIZE |
#define | OL_VERSION |
#define | OL_HELP |
Functions | |
static void | version (FILE *fp) |
Display program version information to a specified stream. | |
static void | usage (void) |
Display program usage text to STDERR and exit with an error. | |
static int | getOptions (int argc, char **argv) |
Parse command line options. | |
static int | validateCfg (DnxCfgDict *dict, void **vptrs, void *passthru) |
Validate a configuration data structure in context. | |
static int | initConfig (char *cfgfile) |
Read and parse the dnxServer configuration file. | |
static void | freeCfgData (DnxCfgData *cpy) |
Release a previously copied configuration data structure. | |
static DnxCfgData * | copyCfgData (DnxCfgData *org) |
Make a dynamic copy of all configuration data. | |
static void | logGblConfigChanges (DnxCfgData *ocp, DnxCfgData *ncp) |
Log changes between old and new global configuration data sets. | |
static int | dnxCalculateJobListSize (void) |
Calculate the optimal size of the job list. | |
static int | dnxPostNewJob (DnxJobList *joblist, DnxJobTransfer *job, DnxNodeRequest *pNode) |
Post a new job from Nagios to the dnxServer job queue. | |
static int | ProcessJobTransferMsg (DnxJobTransfer *job, DnxNodeRequest *node) |
Transfer a job from the plubin and post it for execution. | |
static int | GetMsgHeader (DnxMsgHeader *phdr) |
Retrieve and validate the next message's header. | |
static int | SendMsgResponse (int result) |
Send ACK/NAK (result code of requested operation) to plugin. | |
static int | processRequests () |
Process inbound service requests. | |
static int | dnxServerDeInit (void) |
Deinitialize the dnx server. | |
static int | dnxServerInit (void) |
Initialize the dnxServer. | |
static void | sighandler (int sig) |
The global signal handler for the dnxServer process. | |
char * | versionText (void) |
Format version text to an allocated string buffer. | |
void | dnxReconfigure (void) |
Configuration changes have been made; reread the config file. | |
int | dnxPostResult (void *payload, unsigned long serial, time_t start_time, unsigned delta, int early_timeout, int res_code, char *res_data) |
Post a completed service request to the Nagios service result buffer. | |
void | dnxJobCleanup (DnxNewJob *pJob) |
Release all resources associated with a job object. | |
int | dnxAuditJob (DnxNewJob *pJob, char *action) |
Send an audit message to the dnx server audit log. | |
int | main (int argc, char **argv) |
The main program entry point for the dnx server daemon. | |
Variables | |
static DnxCfgData | cfg |
The server configuration parameters. | |
static DnxCfgParser * | parser |
The system configuration parser. | |
static DnxJobList * | joblist |
The master job list. | |
static DnxRegistrar * | registrar |
The client node registrar. | |
static DnxDispatcher * | dispatcher |
The job list dispatcher. | |
static DnxCollector * | collector |
The job list results collector. | |
static time_t | start_time |
The module start time. | |
static char * | s_cfgfile |
The configuration file. | |
static int | s_queuesize |
The Nagios service queue size. | |
static char * | s_progname |
The base program name. | |
static char * | s_cmdover = 0 |
The command line overrides string. |
Listens on an IPC pipe for service check requests sent by the DNX Nagios Plugin module and dispatches them to distributed worker nodes.
Definition in file dnxServerMain.c.
#define COMPILE_FLAGS "<unknown>" |
Definition at line 68 of file dnxServerMain.c.
#define DNX_DEFAULT_DBGLOG SYSLOGDIR "/dnxsrv.dbg.log" |
Definition at line 87 of file dnxServerMain.c.
#define DNX_DEFAULT_LOG SYSLOGDIR "/dnxsrv.log" |
Definition at line 86 of file dnxServerMain.c.
#define DNX_DEFAULT_SERVER_CONFIG_FILE SYSCONFDIR "/dnxServer.cfg" |
Definition at line 85 of file dnxServerMain.c.
#define DNX_DEFAULT_SERVER_PATH SYSBINDIR "/dnxServer" |
Definition at line 88 of file dnxServerMain.c.
#define elemcount | ( | x | ) | (sizeof(x)/sizeof(*(x))) |
Definition at line 83 of file dnxServerMain.c.
#define OL_CFGFILE |
#define OL_HELP |
#define OL_QUEUESIZE |
Referenced by usage().
#define OL_VERSION |
#define SYSCONFDIR "/etc" |
Definition at line 60 of file dnxServerMain.c.
#define SYSLOGDIR "/var/log" |
Definition at line 64 of file dnxServerMain.c.
#define VERSION "<unknown>" |
Definition at line 38 of file dnxServerMain.c.
static DnxCfgData* copyCfgData | ( | DnxCfgData * | org | ) | [static] |
Make a dynamic copy of all configuration data.
[in] | org | - the structure to be copied. |
Definition at line 358 of file dnxServerMain.c.
References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, DnxCfgData::expirePollInterval, DnxCfgData::logFilePath, DnxCfgData::maxNodeRequests, DnxCfgData::minServiceSlots, xmalloc, and xstrdup.
int dnxAuditJob | ( | DnxNewJob * | pJob, | |
char * | action | |||
) |
Send an audit message to the dnx server audit log.
[in] | pJob | - the job to be audited. |
[in] | action | - the audit action that we're logging. |
Definition at line 953 of file dnxServerMain.c.
Referenced by dnxCollector(), dnxDispatcher(), dnxPostNewJob(), and dnxTimer().
static int dnxCalculateJobListSize | ( | void | ) | [static] |
Calculate the optimal size of the job list.
Assumes the caller will actually use the returned value to allocate the job list. Based on this assumption, this routine logs messages indicating when various configuration overrides have taken effect.
Definition at line 460 of file dnxServerMain.c.
References dnxLog(), DnxCfgData::maxNodeRequests, DnxCfgData::minServiceSlots, and s_queuesize.
void dnxJobCleanup | ( | DnxNewJob * | pJob | ) |
Release all resources associated with a job object.
[in] | pJob | - the job to be freed. |
Definition at line 942 of file dnxServerMain.c.
Referenced by dnxCollector(), and dnxTimer().
static int dnxPostNewJob | ( | DnxJobList * | joblist, | |
DnxJobTransfer * | job, | |||
DnxNodeRequest * | pNode | |||
) | [static] |
Post a new job from Nagios to the dnxServer job queue.
[in] | joblist | - the job list to which the new job should be posted. |
[in] | job | - the job as transferred from the plugin module. |
[in] | pNode | - a dnxServer node request structure that is being posted with this job. The dispatcher thread will send the job to the associated node. |
Definition at line 504 of file dnxServerMain.c.
References DnxJobTransfer::cmd, DnxNewJob::cmd, DNX_OBJ_JOB, DNX_OK, dnxAuditJob(), dnxDebug(), dnxJobListAdd(), dnxLog(), dnxMakeXID(), dnxStatsInc(), DnxJobTransfer::expires, DnxNewJob::expires, JOBS_HANDLED, JOBS_REJECTED_NO_SLOTS, DnxXID::objSerial, DnxJobTransfer::payload, DnxNewJob::payload, DnxNewJob::pNode, DnxJobTransfer::serial, DnxJobTransfer::start_time, DnxNewJob::start_time, DnxJobTransfer::timeout, DnxNewJob::timeout, DnxNewJob::xid, and xstrdup.
int dnxPostResult | ( | void * | payload, | |
unsigned long | serial, | |||
time_t | start_time, | |||
unsigned | delta, | |||
int | early_timeout, | |||
int | res_code, | |||
char * | res_data | |||
) |
Post a completed service request to the Nagios service result buffer.
If early_timeout
is true (1), then res_code
will be reset to STATE_UNKNOWN, so you might as well pass zero for res_code
.
[in] | payload | - An opaque pointer to the nagios service structure and other relevant results data. |
[in] | serial | - the job serial number. |
[in] | start_time | - the nagios service object start time. |
[in] | delta | - the running time of the nagios service object in seconds. |
[in] | early_timeout | - boolean; true means the job DID time out. |
[in] | res_code | - the result code of this job. |
[in] | res_data | - the resulting STDOUT output text of this job. |
Definition at line 881 of file dnxServerMain.c.
References DnxResultTransfer::delta, DNX_ERR_MEMORY, DNX_MSG_RESULT_TRANSFER, DNX_MSG_SIGNATURE, DNX_PLGFD, dnxDebug(), dnxStatsInc(), DnxResultTransfer::early_timeout, DnxResultTransfer::hdr, DnxMsgHeader::msgtype, DnxResultTransfer::payload, POST_RESULTS_FAILED, POST_RESULTS_OK, DnxResultTransfer::res_code, DnxResultTransfer::res_data, RESULTS_FAILED, RESULTS_OK, RESULTS_TIMED_OUT, DnxResultTransfer::serial, DnxMsgHeader::signature, DnxResultTransfer::start_time, DnxMsgHeader::structsz, xfree, and xmalloc.
void dnxReconfigure | ( | void | ) |
Configuration changes have been made; reread the config file.
Normally, this routine would be called by the signal handler, but we may do things in here that are not legal in a signal handlers. So instead this routine is called from the agent thread, and the signal handler merely notifies the agent that a reconfigure should be done.
Definition at line 863 of file dnxServerMain.c.
References copyCfgData(), dnxCfgParserParse(), dnxErrorString(), dnxLog(), freeCfgData(), and logGblConfigChanges().
Referenced by dnxAgentServer().
static int dnxServerDeInit | ( | void | ) | [static] |
Deinitialize the dnx server.
Definition at line 737 of file dnxServerMain.c.
References dnxChanMapRelease(), dnxCollectorDestroy(), dnxDispatcherDestroy(), dnxJobListDestroy(), dnxRegistrarDestroy(), dnxReleaseAgent(), and dnxStatsCleanup().
Referenced by ehProcessData(), main(), and nebmodule_deinit().
static int dnxServerInit | ( | void | ) | [static] |
Initialize the dnxServer.
Definition at line 767 of file dnxServerMain.c.
References DnxCfgData::agentUrl, DnxCfgData::collectorUrl, DnxCfgData::dispatcherUrl, dnxCalculateJobListSize(), dnxChanMapInit(), dnxCollectorCreate(), dnxDispatcherCreate(), dnxDispatcherGetChannel(), dnxErrorString(), dnxInitAgent(), dnxJobListCreate(), dnxLog(), and dnxRegistrarCreate().
Referenced by ehProcessData(), and main().
static void freeCfgData | ( | DnxCfgData * | cpy | ) | [static] |
Release a previously copied configuration data structure.
[in] | cpy | - the structure to be freed. |
Definition at line 337 of file dnxServerMain.c.
References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::dispatcherUrl, DnxCfgData::logFilePath, and xfree.
static int GetMsgHeader | ( | DnxMsgHeader * | phdr | ) | [static] |
Retrieve and validate the next message's header.
[in] | phdr | - the header buffer to be filled. |
Definition at line 590 of file dnxServerMain.c.
References DNX_ERR_UNSUPPORTED, DNX_MAX_XFER_SIZE, DNX_MSG_SIGNATURE, DNX_SRVFD, dnxDebug(), DnxMsgHeader::signature, and DnxMsgHeader::structsz.
static int getOptions | ( | int | argc, | |
char ** | argv | |||
) | [static] |
Parse command line options.
[in] | argc | - the number of elements in the argv array. |
[in] | argv | - a null-terminated array of command-line arguments. |
Definition at line 180 of file dnxServerMain.c.
References DNX_DEFAULT_SERVER_CONFIG_FILE, s_cfgfile, s_progname, s_queuesize, usage(), and version().
static int initConfig | ( | char * | cfgfile | ) | [static] |
Read and parse the dnxServer configuration file.
[in] | cfgfile | - the configuration file to be read. |
Definition at line 290 of file dnxServerMain.c.
References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, DNX_CFG_FSPATH, DNX_CFG_STRING, DNX_CFG_UNSIGNED, DNX_CFG_URL, DNX_DEFAULT_DBGLOG, DNX_DEFAULT_LOG, dnxCfgParserCreate(), dnxCfgParserDestroy(), dnxCfgParserParse(), DnxCfgData::expirePollInterval, DnxCfgData::logFilePath, DnxCfgData::maxNodeRequests, DnxCfgData::minServiceSlots, s_cmdover, and validateCfg().
static void logGblConfigChanges | ( | DnxCfgData * | ocp, | |
DnxCfgData * | ncp | |||
) | [static] |
Log changes between old and new global configuration data sets.
Dynamic reconfiguration of dispatcher and collector URL's is not allowed so we don't need to check differences in those string values.
[in] | ocp | - a reference to the old configuration data set. |
[in] | ncp | - a reference to the new configuration data set. |
Definition at line 395 of file dnxServerMain.c.
References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, dnxLog(), DnxCfgData::expirePollInterval, DnxCfgData::logFilePath, DnxCfgData::maxNodeRequests, and DnxCfgData::minServiceSlots.
int main | ( | int | argc, | |
char ** | argv | |||
) |
The main program entry point for the dnx server daemon.
[in] | argc | - the number of elements in the argv array. |
[in] | argv | - a null-terminated array of command-line arguments. |
Definition at line 991 of file dnxServerMain.c.
References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, DNX_OK, dnxCfgParserDestroy(), dnxDebug(), dnxErrorString(), dnxLog(), dnxLogInit(), dnxServerDeInit(), dnxServerInit(), getOptions(), initConfig(), DnxCfgData::logFilePath, processRequests(), s_cfgfile, sighandler(), start_time, VERSION, and xheapchk.
static int ProcessJobTransferMsg | ( | DnxJobTransfer * | job, | |
DnxNodeRequest * | node | |||
) | [static] |
Transfer a job from the plubin and post it for execution.
[in,out] | job | - the address of the current job structure pointer. |
[in] | node | - the client node request to associate with this job. This value may be null, in which case this routine should allocate it. |
Definition at line 546 of file dnxServerMain.c.
References DNX_SRVFD, dnxDebug(), dnxErrorString(), dnxGetNodeRequest(), dnxPostNewJob(), DnxJobTransfer::hdr, and DnxMsgHeader::structsz.
Referenced by processRequests().
static int processRequests | ( | ) | [static] |
Process inbound service requests.
If there's a worker node request available, hang on a read request waiting to assign that node to an inbound service request. Otherwise don't wait for a request node to become available.
Definition at line 672 of file dnxServerMain.c.
References DNX_MSG_JOB_TRANSFER, DNX_MSG_RESERVE_NODEREQ, DNX_MSG_TERMINATE, DNX_SAKFD, DNX_SRVFD, dnxDebug(), dnxGetNodeRequest(), dnxLog(), GetMsgHeader(), DnxJobTransfer::hdr, DnxMsgHeader::msgtype, ProcessJobTransferMsg(), SendMsgResponse(), DnxMsgHeader::structsz, xfree, and xrealloc.
Referenced by main().
static int SendMsgResponse | ( | int | result | ) | [static] |
Send ACK/NAK (result code of requested operation) to plugin.
[in] | result | - the result code to be sent. |
Definition at line 634 of file dnxServerMain.c.
References DNX_SAKFD, and dnxDebug().
Referenced by processRequests().
static void sighandler | ( | int | sig | ) | [static] |
The global signal handler for the dnxServer process.
[in] | sig | - the signal number received from the system. |
Definition at line 823 of file dnxServerMain.c.
References dnxAgentSignalReconfig().
static void usage | ( | void | ) | [static] |
Display program usage text to STDERR and exit with an error.
Definition at line 142 of file dnxServerMain.c.
References OL_CFGFILE, OL_HELP, OL_QUEUESIZE, OL_VERSION, s_progname, and version().
static int validateCfg | ( | DnxCfgDict * | dict, | |
void ** | vptrs, | |||
void * | passthru | |||
) | [static] |
Validate a configuration data structure in context.
[in] | dict | - the dictionary used by the DnxCfgParser. |
[in] | vptrs | - an array of opaque objects (either pointers or values) to be checked. |
[in] | passthru | - an opaque pointer passed through from dnxCfgParserCreate. In this routine, it's the regex_t object into which we should parse the regular expression if one is given. |
Definition at line 243 of file dnxServerMain.c.
References DnxCfgData::agentUrl, DnxCfgData::auditFilePath, DnxCfgData::authWorkerNodes, DnxCfgData::collectorUrl, DnxCfgData::debugFilePath, DnxCfgData::debugLevel, DnxCfgData::dispatcherUrl, DNX_ERR_INVALID, dnxLog(), DnxCfgData::expirePollInterval, DnxCfgData::logFilePath, DnxCfgData::maxNodeRequests, and DnxCfgData::minServiceSlots.
static void version | ( | FILE * | fp | ) | [static] |
Display program version information to a specified stream.
[in] | fp | - the stream to which version info should be printed. |
Definition at line 127 of file dnxServerMain.c.
References versionText(), and xfree.
char* versionText | ( | void | ) |
Format version text to an allocated string buffer.
Caller is responsible to free memory buffer returned, using xfree.
Definition at line 836 of file dnxServerMain.c.
DnxCfgData cfg [static] |
DnxCollector* collector [static] |
DnxDispatcher* dispatcher [static] |
DnxJobList* joblist [static] |
DnxCfgParser* parser [static] |
DnxRegistrar* registrar [static] |
char* s_cfgfile [static] |
char* s_cmdover = 0 [static] |
char* s_progname [static] |
int s_queuesize [static] |
The Nagios service queue size.
Definition at line 115 of file dnxServerMain.c.
Referenced by dnxCalculateJobListSize(), and getOptions().
time_t start_time [static] |