PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|C|nagios-2.9|contrib|daemonchk.c =

page 1 of 3



#include "../common/config.h"
#include "../common/common.h"
#include "../common/locations.h"
#include "../cgi/cgiutils.h"
#include "../cgi/getcgi.h"
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <stdarg.h>

#define CHARLEN 256
#define max(a,b) ((a)>(b))?(a):(b)

void document_header(void);
void document_footer(void);
int process_cgivars(void);

char *strscpy(char *dest, const char *src);
char *ssprintf(char *str, const char *fmt, ...);
void terminate (int result, const char *fmt, ...);

int main (int argc, char **argv){
  FILE *fp;
  char *status_file=NULL;
  char *lock_file=NULL;
  char *proc_file=NULL;
	char input_buffer[CHARLEN];
  int c, age, pid, testpid, found;
  int wt=-1;
  int ct=-1;
  struct stat statbuf;
  time_t current_time;

#ifdef DEFAULT_STATUS_FILE
  status_file=strscpy(status_file,DEFAULT_STATUS_FILE);
#else
  status_file=strscpy(status_file,"/var/log/nagios/status.log");
#endif

#ifdef DEFAULT_LOCK_FILE
  lock_file=strscpy(lock_file,DEFAULT_LOCK_FILE);
#else
  lock_file=strscpy(lock_file,"/tmp/nagios.lock");
#endif

  if(getenv("REQUEST_METHOD")){
    process_cgivars();
    document_header();
  } else { /* get arguments */
    while ( (c = getopt(argc,argv,"+c:w:s:l:")) != EOF) {
      switch (c)
	{
	case 'c':
	  ct = atoi(optarg);
	  break;
	case 'w':
	  wt = atoi(optarg);
	  break;
	case 's':
	  status_file=optarg;
	  break;
	case 'l':
	  lock_file=optarg;
	  break;
	}
    }
  }

  /* find status file, get lastmod time */
  if(stat(status_file,&statbuf)==-1){
    printf("NAGIOS CRITICAL - could not find status log: %s\n",status_file);
    exit(STATE_CRITICAL);
  }
  time(¤t_time);
  age = (int)(current_time-statbuf.st_mtime);

  /* find lock file.  get pid if it exists */
  if(stat(lock_file, &statbuf)==-1){
    printf("NAGIOS CRITICAL - could not find lock file: %s\n",lock_file);
    exit(STATE_CRITICAL);
  }
  fp=fopen(lock_file,"r");
  fscanf(fp,"%d",&pid);
  fclose(fp);
	proc_file=ssprintf(proc_file,"/proc/%d",pid);

  if (stat("/proc",&statbuf)==0) {
		if (stat(proc_file,&statbuf)==-1) {
			printf("NAGIOS CRITICAL - could not find proc file: %s\n",proc_file);
			exit(STATE_CRITICAL);
		}
  } else if (snprintf(proc_file,CHARLEN-1,"/bin/ps -o pid -p %d",pid) &&
						 (fp=popen(proc_file,"r"))!=NULL) {
		fgets(input_buffer,CHARLEN-1,fp);
		fgets(input_buffer,CHARLEN-1,fp);
		if (sscanf(input_buffer,"%d",&testpid)==1) {
			if (testpid!=pid) {
				printf("NAGIOS CRITICAL - could not find process(1): %d\n",pid);
				exit(STATE_CRITICAL);
			}
=1=

= PAGE 1 = NEXT > |2|3

UP TO ROOT | UP TO DIR

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.030462 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)