Пример #1
0
main()
{
int x;
spopen(2400,'n',8,1);
do
 {
 if(spcangetc()) printf("%c",spgetc());
 if(kbhit())
  {
  x=getch();
  if(x==29) break;
  spputc(x);
  }
 }
 while(1);
spclose();
return 0;
}
Пример #2
0
int
main (int argc, char **argv)
{
	char command_line[1024];
	int result = STATE_UNKNOWN;
	int line;
	char input_buffer[MAX_INPUT_BUFFER];
	char query_string[512];
	char *errmsg;
	char *temp_buffer;
	int line_status = ONLINE;
	int paper_status = 0;
	int intervention_required = 0;
	int peripheral_error = 0;
	int paper_jam = 0;
	int paper_out = 0;
	int toner_low = 0;
	int page_punt = 0;
	int memory_out = 0;
	int door_open = 0;
	int paper_output = 0;
	char display_message[MAX_INPUT_BUFFER];

	errmsg = malloc(MAX_INPUT_BUFFER);

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	/* Parse extra opts if any */
	argv=np_extra_opts (&argc, argv, progname);

	if (process_arguments (argc, argv) == ERROR)
		usage4 (_("Could not parse arguments"));

	/* removed ' 2>1' at end of command 10/27/1999 - EG */
	/* create the query string */
	sprintf
		(query_string,
		 "%s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0",
		 HPJD_LINE_STATUS,
		 HPJD_PAPER_STATUS,
		 HPJD_INTERVENTION_REQUIRED,
		 HPJD_GD_PERIPHERAL_ERROR,
		 HPJD_GD_PAPER_JAM,
		 HPJD_GD_PAPER_OUT,
		 HPJD_GD_TONER_LOW,
		 HPJD_GD_PAGE_PUNT,
		 HPJD_GD_MEMORY_OUT,
		 HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY);

	/* get the command to run */
	sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%hd %s", PATH_TO_SNMPGET, community,
									address, port, query_string);

	/* run the command */
	child_process = spopen (command_line);
	if (child_process == NULL) {
		printf (_("Could not open pipe: %s\n"), command_line);
		return STATE_UNKNOWN;
	}

	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
	if (child_stderr == NULL) {
		printf (_("Could not open stderr for %s\n"), command_line);
	}

	result = STATE_OK;

	line = 0;
	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {

		/* strip the newline character from the end of the input */
		if (input_buffer[strlen (input_buffer) - 1] == '\n')
			input_buffer[strlen (input_buffer) - 1] = 0;

		line++;

		temp_buffer = strtok (input_buffer, "=");
		temp_buffer = strtok (NULL, "=");

		if (temp_buffer == NULL && line < 13) {

				result = STATE_UNKNOWN;
				strcpy (errmsg, input_buffer);

		} else {

			switch (line) {

			case 1:										/* 1st line should contain the line status */
				line_status = atoi (temp_buffer);
				break;
			case 2:										/* 2nd line should contain the paper status */
				paper_status = atoi (temp_buffer);
				break;
			case 3:										/* 3rd line should be intervention required */
				intervention_required = atoi (temp_buffer);
				break;
			case 4:										/* 4th line should be peripheral error */
				peripheral_error = atoi (temp_buffer);
				break;
			case 5:										/* 5th line should contain the paper jam status */
				paper_jam = atoi (temp_buffer);
				break;
			case 6:										/* 6th line should contain the paper out status */
				paper_out = atoi (temp_buffer);
				break;
			case 7:										/* 7th line should contain the toner low status */
				toner_low = atoi (temp_buffer);
				break;
			case 8:										/* did data come too slow for engine */
				page_punt = atoi (temp_buffer);
				break;
			case 9:										/* did we run out of memory */
				memory_out = atoi (temp_buffer);
				break;
			case 10:										/* is there a door open */
				door_open = atoi (temp_buffer);
				break;
			case 11:										/* is output tray full */
				paper_output = atoi (temp_buffer);
				break;
			case 12:										/* display panel message */
				strcpy (display_message, temp_buffer + 1);
				break;
			default:										/* fold multiline message */
				strncat (display_message, input_buffer,
						sizeof (display_message) - strlen (display_message) - 1);
			}

		}

		/* break out of the read loop if we encounter an error */
		if (result != STATE_OK)
			break;
	}

	/* WARNING if output found on stderr */
	if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
		result = max_state (result, STATE_WARNING);
		/* remove CRLF */
		if (input_buffer[strlen (input_buffer) - 1] == '\n')
			input_buffer[strlen (input_buffer) - 1] = 0;
		sprintf (errmsg, "%s", input_buffer );

	}

	/* close stderr */
	(void) fclose (child_stderr);

	/* close the pipe */
	if (spclose (child_process))
		result = max_state (result, STATE_WARNING);

	/* if there wasn't any output, display an error */
	if (line == 0) {

		/* might not be the problem, but most likely is. */
		result = STATE_UNKNOWN ;
		xasprintf (&errmsg, "%s : Timeout from host %s\n", errmsg, address );

	}

	/* if we had no read errors, check the printer status results... */
	if (result == STATE_OK) {

		if (paper_jam) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Paper Jam"));
		}
		else if (paper_out) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Out of Paper"));
		}
		else if (line_status == OFFLINE) {
			if (strcmp (errmsg, "POWERSAVE ON") != 0) {
				result = STATE_WARNING;
				strcpy (errmsg, _("Printer Offline"));
			}
		}
		else if (peripheral_error) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Peripheral Error"));
		}
		else if (intervention_required) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Intervention Required"));
		}
		else if (toner_low) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Toner Low"));
		}
		else if (memory_out) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Insufficient Memory"));
		}
		else if (door_open) {
			result = STATE_WARNING;
			strcpy (errmsg, _("A Door is Open"));
		}
		else if (paper_output) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Output Tray is Full"));
		}
		else if (page_punt) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Data too Slow for Engine"));
		}
		else if (paper_status) {
			result = STATE_WARNING;
			strcpy (errmsg, _("Unknown Paper Error"));
		}
	}

	if (result == STATE_OK)
		printf (_("Printer ok - (%s)\n"), display_message);

	else if (result == STATE_UNKNOWN) {

		printf ("%s\n", errmsg);

		/* if printer could not be reached, escalate to critical */
		if (strstr (errmsg, "Timeout"))
			result = STATE_CRITICAL;
	}

	else if (result == STATE_WARNING)
		printf ("%s (%s)\n", errmsg, display_message);

	return result;
}
Пример #3
0
int main(int argc, char **argv){
	int result=STATE_OK;
	char command[MAX_INPUT_BUFFER];
	double temp=0.0L;
	char input_buffer[MAX_INPUT_BUFFER];
	int found=0;

	/* process command line arguments */
	result=process_arguments(argc,argv);

	/* display usage if there was a problem */
	if(result==ERROR){
		printf("Incorrect arguments supplied\n");
		printf("\n");
		printf("Hot Little Therm temperature plugin for Nagios\n");
		printf("Copyright (c) 1999-2002 Ethan Galstad ([email protected])\n");
		printf("Last Modified: 02-28-2002\n");
		printf("License: GPL\n");
		printf("\n");
		printf("Usage: %s <probe> <wtemp> <ctemp> [-l label] [-s scale] [-lower]\n",argv[0]);
		printf("\n");
		printf("Options:\n");
		printf(" <wtemp>  = Temperature necessary to result in a WARNING state\n");
		printf(" <ctemp>  = Temperature necessary to result in a CRITICAL state\n");
		printf(" [label]  = A descriptive label for the probe.  Example: \"Outside Temp\"\n");
		printf(" [scale]  = A descriptive label for the temperature scale.  Example: \"Celsius\"\n");
		printf(" [-lower] = Evaluate temperatures with lower values being more critical\n");
		printf("\n");
		printf("This plugin checks the temperature of a given temperature probe on a\n");
		printf("Hot Little Therm digital thermometer.  The plugin uses the 'therm' utility\n");
		printf("included with the HLT software to check the probe temperature.  Both the\n");
		printf("HLT digital thermometer and software are produced by Spiderplant. See\n");
		printf("their website at http://www.spiderplant.com/hlt for more information.\n");
		printf("\n");
		return STATE_UNKNOWN;
	        }


	result=STATE_OK;

	/* Set signal handling and alarm */
	if(signal(SIGALRM,timeout_alarm_handler)==SIG_ERR){
		printf("Cannot catch SIGALRM");
		return STATE_UNKNOWN;
	        }

	/* handle timeouts gracefully */
	alarm(timeout_interval);

	/* create the command line we're going to use */
	snprintf(command,sizeof(command),"%s %s",HLTHERM_COMMAND,probe);
	command[sizeof(command)-1]='\x0';

	/* run the command to check the temperature on the probe */
	fp=spopen(command);
	if(fp==NULL){
		printf("Could not open pipe: %s\n",command);
		return STATE_UNKNOWN;
	        }

	if(fgets(input_buffer,MAX_INPUT_BUFFER-1,fp)){
		found=1;
		temp=(double)atof(input_buffer);
	        }

	/* close the pipe */
	spclose(fp);

	if(result==STATE_OK){

		if(found==0){
			printf("Therm problem - Could not read program output\n");
			result=STATE_CRITICAL;
		        }
		else{
			if(check_lower_temps==TRUE){
				if(temp<=ctemp)
					result=STATE_CRITICAL;
				else if(temp<=wtemp)
				       result=STATE_WARNING;
			        }
			else{
				if(temp>=ctemp)
					result=STATE_CRITICAL;
				else if(temp>=wtemp)
					result=STATE_WARNING;
			        }

			printf("Therm %s: %s = %2.1f %s\n",(result==STATE_OK)?"ok":"problem",label,temp,scale);
		        }
	        }

	return result;
        }
Пример #4
0
int
main (int argc, char **argv)
{
/* normaly should be  int result = STATE_UNKNOWN; */

  int status = STATE_UNKNOWN;
  int result = 0;
  char *fping_prog = NULL;
  char *server = NULL;
  char *command_line = NULL;
  char *input_buffer = NULL;
  char *option_string = "";
  input_buffer = malloc (MAX_INPUT_BUFFER);

  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);

  /* Parse extra opts if any */
  argv=np_extra_opts (&argc, argv, progname);

  if (process_arguments (argc, argv) == ERROR)
    usage4 (_("Could not parse arguments"));

  server = strscpy (server, server_name);

  /* compose the command */
  if (target_timeout)
    xasprintf(&option_string, "%s-t %d ", option_string, target_timeout);
  if (packet_interval)
    xasprintf(&option_string, "%s-p %d ", option_string, packet_interval);
  if (sourceip)
    xasprintf(&option_string, "%s-S %s ", option_string, sourceip);
  if (sourceif)
    xasprintf(&option_string, "%s-I %s ", option_string, sourceif);

#ifdef PATH_TO_FPING6
  if (address_family == AF_INET6)
    fping_prog = strdup(PATH_TO_FPING6);
  else
    fping_prog = strdup(PATH_TO_FPING);
#else
  fping_prog = strdup(PATH_TO_FPING);
#endif

  xasprintf (&command_line, "%s %s-b %d -c %d %s", fping_prog,
            option_string, packet_size, packet_count, server);

  if (verbose)
    printf ("%s\n", command_line);

  /* run the command */
  child_process = spopen (command_line);
  if (child_process == NULL) {
    printf (_("Could not open pipe: %s\n"), command_line);
    return STATE_UNKNOWN;
  }

  child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
  if (child_stderr == NULL) {
    printf (_("Could not open stderr for %s\n"), command_line);
  }

  while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
    if (verbose)
      printf ("%s", input_buffer);
    status = max_state (status, textscan (input_buffer));
  }

  /* If we get anything on STDERR, at least set warning */
  while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
    status = max_state (status, STATE_WARNING);
    if (verbose)
      printf ("%s", input_buffer);
    status = max_state (status, textscan (input_buffer));
  }
  (void) fclose (child_stderr);

  /* close the pipe */
  if (result = spclose (child_process))
    /* need to use max_state not max */
    status = max_state (status, STATE_WARNING);

  if (result > 1 ) {
    status = max_state (status, STATE_UNKNOWN);
    if (result == 2) {
      die (STATE_UNKNOWN, _("FPING UNKNOWN - IP address not found\n"));
    }
    if (result == 3) {
      die (STATE_UNKNOWN, _("FPING UNKNOWN - invalid commandline argument\n"));
    }
    if (result == 4) {
      die (STATE_UNKNOWN, _("FPING UNKNOWN - failed system call\n"));
    }

  }

  printf ("FPING %s - %s\n", state_text (status), server_name);

  return status;
}
Пример #5
0
int
main (int argc, char **argv)
{
	int users = -1;
	int result = STATE_UNKNOWN;
	char *perf;
#if HAVE_WTSAPI32_H
	WTS_SESSION_INFO *wtsinfo;
	DWORD wtscount;
	DWORD index;
#elif HAVE_UTMPX_H
	struct utmpx *putmpx;
#else
	char input_buffer[MAX_INPUT_BUFFER];
#endif

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	perf = strdup ("");

	/* Parse extra opts if any */
	argv = np_extra_opts (&argc, argv, progname);

	if (process_arguments (argc, argv) == ERROR)
		usage4 (_("Could not parse arguments"));

	users = 0;

#if HAVE_WTSAPI32_H
	if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
	  0, 1, &wtsinfo, &wtscount)) {
		printf(_("Could not enumerate RD sessions: %d\n"), GetLastError());
		return STATE_UNKNOWN;
	}

	for (index = 0; index < wtscount; index++) {
		LPTSTR username;
		DWORD size;
		int len;

		if (!WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE,
		  wtsinfo[index].SessionId, WTSUserName, &username, &size))
			continue;

		len = lstrlen(username);

		WTSFreeMemory(username);

		if (len == 0)
			continue;

		if (wtsinfo[index].State == WTSActive ||
		  wtsinfo[index].State == WTSDisconnected)
			users++;
	}

	WTSFreeMemory(wtsinfo);
#elif HAVE_UTMPX_H
	/* get currently logged users from utmpx */
	setutxent ();

	while ((putmpx = getutxent ()) != NULL)
		if (putmpx->ut_type == USER_PROCESS)
			users++;

	endutxent ();
#else
	/* run the command */
	child_process = spopen (WHO_COMMAND);
	if (child_process == NULL) {
		printf (_("Could not open pipe: %s\n"), WHO_COMMAND);
		return STATE_UNKNOWN;
	}

	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
	if (child_stderr == NULL)
		printf (_("Could not open stderr for %s\n"), WHO_COMMAND);

	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
		/* increment 'users' on all lines except total user count */
		if (input_buffer[0] != '#') {
			users++;
			continue;
		}

		/* get total logged in users */
		if (sscanf (input_buffer, _("# users=%d"), &users) == 1)
			break;
	}

	/* check STDERR */
	if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
		result = possibly_set (result, STATE_UNKNOWN);
	(void) fclose (child_stderr);

	/* close the pipe */
	if (spclose (child_process))
		result = possibly_set (result, STATE_UNKNOWN);
#endif

	/* check the user count against warning and critical thresholds */
	if (users > cusers)
		result = STATE_CRITICAL;
	else if (users > wusers)
		result = STATE_WARNING;
	else if (users >= 0)
		result = STATE_OK;

	if (result == STATE_UNKNOWN)
		printf ("%s\n", _("Unable to read output"));
	else {
		xasprintf (&perf, "%s", perfdata ("users", users, "",
		  TRUE, wusers,
		  TRUE, cusers,
		  TRUE, 0,
		  FALSE, 0));
		printf (_("USERS %s - %d users currently logged in |%s\n"), state_text (result),
		  users, perf);
	}

	return result;
}
Пример #6
0
int
main (int argc, char **argv)
{
	int found = 0, result = STATE_UNKNOWN;
	char *url = NULL;
	char *cmd;
	char *buf;
	char *nstr;
	char tstr[MAX_INPUT_BUFFER];

	int c;
	int option = 0;
	static struct option longopts[] = {
		{"help", no_argument, 0, 'h'},
		{"version", no_argument, 0, 'V'},
		{"url", required_argument, 0, 'u'},
		{0, 0, 0, 0}
	};

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	/* Need at least 2 args */
	if (argc < 3) {
		print_help();
		exit (STATE_UNKNOWN);
	}

	while (1) {
		c = getopt_long (argc, argv, "+hVu:", longopts, &option);

		if (c == -1 || c == EOF)
			break;

		switch (c) {
		case 'h':     /* help */
			print_help ();
			exit (EXIT_SUCCESS);
			break;
		case 'V':     /* version */
			print_revision (progname, NP_VERSION);
			exit (EXIT_SUCCESS);
			break;
		case 'u':
			url = strdup (argv[optind]);
			break;
		case '?':
		default:
			usage5 ();
		}
	}

	if (url == NULL)
		url = strdup (argv[optind++]);

	cmd = strdup (argv[optind++]);
	for (c = optind; c < argc; c++) {
		xasprintf (&cmd, "%s %s", cmd, argv[c]);
	}

	child_process = spopen (cmd);
	if (child_process == NULL) {
		printf (_("Could not open pipe: %s\n"), cmd);
		exit (STATE_UNKNOWN);
	}

	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
	if (child_stderr == NULL) {
		printf (_("Could not open stderr for %s\n"), cmd);
	}

	bzero(tstr, sizeof(tstr));
	buf = malloc(MAX_INPUT_BUFFER);
	printf ("<A href=\"%s\">", argv[1]);
	while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
		found++;
		/* Collect the string in temp str so we can tokenize */
		strcat(tstr, buf);
	}

	if (!found)
		die (STATE_UNKNOWN,
		     _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"),
		     argv[0], cmd);


	/* chop the newline character */
	if ((nstr = strchr(tstr, NEWLINE_CHARACTER)) != NULL)
		*nstr = '\0';

	/* tokenize the string for Perfdata if there is some */
	nstr = strtok(tstr, PERF_CHARACTER);
	printf ("%s", nstr);
	printf ("</A>");
	nstr = strtok(NULL, PERF_CHARACTER);
	if (nstr != NULL)
		printf (" | %s", nstr);

	/* close the pipe */
	result = spclose (child_process);

	/* WARNING if output found on stderr */
	if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
		result = max_state (result, STATE_WARNING);

	/* close stderr */
	(void) fclose (child_stderr);

	return result;
}
Пример #7
0
main(int argc,char *argv[])
{
long old;

int sport= -1;  /* Serial port number */
long baud= -1;  /* Baud rate */
int vecno= -1;  /* Vector number */

int port= -1;   /* Printer port number */
unsigned short c;

if(argc!=3)
 {
 oops:
 fprintf(stderr,"jterm COMx:[BAUD][,IRQ] LPy:\n");
 exit(1);
 }
sscanf(argv[1],"com%d:%ld,%d",&sport,&baud,&vecno);
if(sport== -1) sscanf(argv[1],"COM%d:%ld,%d",&sport,&baud,&vecno);

sscanf(argv[2],"lp%d:",&port);
if(port== -1) sscanf(argv[2],"LP%d:",&port);
--sport;
if(port<0 || port>2 || sport<0 || sport>3) goto oops;

/* Install break interrupt handler */
disable();
old= *(long far *)0x0000006C;
*(long far *)0x0000006C=(long)brkint;
enable();

if(vecno== -1) vecno=ints[sport];
else vecno+=8;

if(baud!= -1) spbaud(ports[sport],baud);

/* Open serial port */
spopen(ports[sport],vecno,1<<(vecno-8));

/* Open parallel port */
port=lports[port];

/* Initialize tty */
ttyinit();

loop:

/* Print chracters */
if(psize) if(pcheck(port))
 {
 pout(port,pbuf[pold++]);
 if(pold==pbufsiz) pold=0;
 psize--;
 }

if(intflg)
 {
 intflg=0;
 spbreak();
 }

/* Check keyboard */
/* The trick here is to use the DOS interrupt 6 instead of the bios interrupt.
 * This eliminates untold numbers of problems with ^C and Ctrl-Break for
 * some microsoft's-programmers-only-know reason.
 */
_DL=0xFF;
_AH=0x6;
geninterrupt(0x21);
__emit__(0x75,0x2,0x31,0xC0);   /* Clear AX if no chars ready */
c=_AX;
if(c)
 {
 c&=0xFF;
 if(!c)
  {
  _DL=0xFF;
  _AH=0x6;
  geninterrupt(0x21);
  c=_AX;
  c<<=8;
  }

 /* Check for exit key */
 if((c&0xff)==']'-64)
  {
  spclose();
  disable();
  *(long far *)0x0000006C=old;
  enable();
  bioscpos(0,height-1);
  exit(1);
  }

 if(c&0xff) spputc(c&0xff);	/* ASCII code */
 else switch(c)			/* Xenix special keys */
  {
  case 0x0300: spputc(0); break;
  case 0x4800: spputc('\033'); if(mapplication) spputc('O'), spputc('A'); else spputc('['), spputc('A'); break;
  case 0x5000: spputc('\033'); if(mapplication) spputc('O'), spputc('B'); else spputc('['), spputc('B'); break;
  case 0x4d00: spputc('\033'); if(mapplication) spputc('O'), spputc('C'); else spputc('['), spputc('C'); break;
  case 0x4b00: spputc('\033'); if(mapplication) spputc('O'), spputc('D'); else spputc('['), spputc('D'); break;
  case 0x4700: spputc('\033'), spputc('['), spputc('H'); break;
  case 0x4f00: spputc('\033'), spputc('['), spputc('F'); break;
  case 0x4900: spputc('\033'), spputc('['), spputc('I'); break;
  case 0x5100: spputc('\033'), spputc('['), spputc('G'); break;
  case 0x5200: spputc('\033'), spputc('['), spputc('L'); break;
  case 0x5300: spputc(127); break;
  case 0x0f00: spputc('\033'), spputc('['), spputc('Z'); break;
  case 0x3b00: spputc('\033'), spputc('['), spputc('M'); break;
  case 0x3c00: spputc('\033'), spputc('['), spputc('N'); break;
  case 0x3d00: spputc('\033'), spputc('['), spputc('O'); break;
  case 0x3e00: spputc('\033'), spputc('['), spputc('P'); break;
  case 0x3f00: spputc('\033'), spputc('['), spputc('Q'); break;
  case 0x4000: spputc('\033'), spputc('['), spputc('R'); break;
  case 0x4100: spputc('\033'), spputc('['), spputc('S'); break;
  case 0x4200: spputc('\033'), spputc('['), spputc('T'); break;
  case 0x4300: spputc('\033'), spputc('['), spputc('U'); break;
  case 0x4400: spputc('\033'), spputc('['), spputc('V'); break;
  case 0x5400: spputc('\033'), spputc('['), spputc('Y'); break;
  case 0x5500: spputc('\033'), spputc('['), spputc('Z'); break;
  case 0x5600: spputc('\033'), spputc('['), spputc('a'); break;
  case 0x5700: spputc('\033'), spputc('['), spputc('b'); break;
  case 0x5800: spputc('\033'), spputc('['), spputc('c'); break;
  case 0x5900: spputc('\033'), spputc('['), spputc('d'); break;
  case 0x5a00: spputc('\033'), spputc('['), spputc('e'); break;
  case 0x5b00: spputc('\033'), spputc('['), spputc('f'); break;
  case 0x5c00: spputc('\033'), spputc('['), spputc('g'); break;
  case 0x5d00: spputc('\033'), spputc('['), spputc('h'); break;
  case 0x5e00: spputc('\033'), spputc('['), spputc('k'); break;
  case 0x5f00: spputc('\033'), spputc('['), spputc('l'); break;
  case 0x6000: spputc('\033'), spputc('['), spputc('m'); break;
  case 0x6100: spputc('\033'), spputc('['), spputc('n'); break;
  case 0x6200: spputc('\033'), spputc('['), spputc('o'); break;
  case 0x6300: spputc('\033'), spputc('['), spputc('p'); break;
  case 0x6400: spputc('\033'), spputc('['), spputc('q'); break;
  case 0x6500: spputc('\033'), spputc('['), spputc('r'); break;
  case 0x6600: spputc('\033'), spputc('['), spputc('s'); break;
  case 0x6700: spputc('\033'), spputc('['), spputc('t'); break;
  case 0x6800: spputc('\033'), spputc('['), spputc('w'); break;
  case 0x6900: spputc('\033'), spputc('['), spputc('x'); break;
  case 0x6a00: spputc('\033'), spputc('['), spputc('y'); break;
  case 0x6b00: spputc('\033'), spputc('['), spputc('z'); break;
  case 0x6c00: spputc('\033'), spputc('['), spputc('@'); break;
  case 0x6d00: spputc('\033'), spputc('['), spputc('['); break;
  case 0x6e00: spputc('\033'), spputc('['), spputc('\\'); break;
  case 0x6f00: spputc('\033'), spputc('['), spputc(']'); break;
  case 0x7000: spputc('\033'), spputc('['), spputc('^'); break;
  case 0x7100: spputc('\033'), spputc('['), spputc('_'); break;
  }
 }

/* Check serial port */
if(spcangetc()) ttyout(spgetc());
goto loop;
}
Пример #8
0
int
main (int argc, char **argv)
{
/* normaly should be  int result = STATE_UNKNOWN; */

  int status = STATE_UNKNOWN;
  char *server = NULL;
  char *command_line = NULL;
  char *input_buffer = NULL;
  char *option_string = "";
  input_buffer = malloc (MAX_INPUT_BUFFER);

  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);

  /* Parse extra opts if any */
  argv=np_extra_opts (&argc, argv, progname);

  if (process_arguments (argc, argv) == ERROR)
    usage4 (_("Could not parse arguments"));

  server = strscpy (server, server_name);

  /* compose the command */
  if (target_timeout)
    asprintf(&option_string, "%s-t %d ", option_string, target_timeout);
  if (packet_interval)
    asprintf(&option_string, "%s-p %d ", option_string, packet_interval);

  asprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING,
            option_string, packet_size, packet_count, server);

  if (verbose)
    printf ("%s\n", command_line);

  /* run the command */
  child_process = spopen (command_line);
  if (child_process == NULL) {
    printf (_("Could not open pipe: %s\n"), command_line);
    return STATE_UNKNOWN;
  }

  child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
  if (child_stderr == NULL) {
    printf (_("Could not open stderr for %s\n"), command_line);
  }

  while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
    if (verbose)
      printf ("%s", input_buffer);
    status = max_state (status, textscan (input_buffer));
  }

  /* If we get anything on STDERR, at least set warning */
  while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
    status = max_state (status, STATE_WARNING);
    if (verbose)
      printf ("%s", input_buffer);
    status = max_state (status, textscan (input_buffer));
  }
  (void) fclose (child_stderr);

  /* close the pipe */
  if (spclose (child_process))
    /* need to use max_state not max */
    status = max_state (status, STATE_WARNING);

  printf ("FPING %s - %s\n", state_text (status), server_name);

  return status;
}
Пример #9
0
int
run_ping (const char *cmd, const char *addr)
{
    char buf[MAX_INPUT_BUFFER];
    int result = STATE_UNKNOWN;
    int match;

    if ((child_process = spopen (cmd)) == NULL)
        die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd);

    child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
    if (child_stderr == NULL)
        printf (_("Cannot open stderr for %s\n"), cmd);

    while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {

        if (verbose >= 3)
            printf("Output: %s", buf);

        result = max_state (result, error_scan (buf, addr));

        /* get the percent loss statistics */
        match = 0;
        if((sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
                (sscanf(buf,"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n",&pl,&match) && match) ||
                (sscanf(buf,"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n",&pl,&match) && match) ||
                (sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% packet loss%n",&pl,&match) && match) ||
                (sscanf(buf,"%*d packets transmitted, %*d packets received, %d%% loss, time%n",&pl,&match) && match) ||
                (sscanf(buf,"%*d packets transmitted, %*d received, %d%% loss, time%n",&pl,&match) && match) ||
                (sscanf(buf,"%*d packets transmitted, %*d received, %d%% packet loss, time%n",&pl,&match) && match) ||
                (sscanf(buf,"%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
                (sscanf(buf,"%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n",&pl,&match) && match) ||
                (sscanf(buf,"%*[^(](%d%% %*[^)])%n",&pl,&match) && match)
          )
            continue;

        /* get the round trip average */
        else if((sscanf(buf,"round-trip min/avg/max = %*f/%f/%*f%n",&rta,&match) && match) ||
                (sscanf(buf,"round-trip min/avg/max/mdev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
                (sscanf(buf,"round-trip min/avg/max/sdev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
                (sscanf(buf,"round-trip min/avg/max/stddev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
                (sscanf(buf,"round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
                (sscanf(buf,"round-trip (ms) min/avg/max = %*f/%f/%*f%n",&rta,&match) && match) ||
                (sscanf(buf,"round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f%n",&rta,&match) && match) ||
                (sscanf(buf,"rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms%n",&rta,&match) && match) ||
                (sscanf(buf, "%*[^=] = %*fms, %*[^=] = %*fms, %*[^=] = %fms%n", &rta, &match) && match)
               )
            continue;
    }

    /* this is needed because there is no rta if all packets are lost */
    if (pl == 100)
        rta = crta;

    /* check stderr, setting at least WARNING if there is output here */
    /* Add warning into warn_text */
    while (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr)) {
        if (
            ! strstr(buf,"WARNING - no SO_TIMESTAMP support, falling back to SIOCGSTAMP")
            && ! strstr(buf,"Warning: time of day goes back")

        ) {
            if (verbose >= 3) {
                printf("Got stderr: %s", buf);
            }
            if ((result=error_scan(buf, addr)) == STATE_OK) {
                result = STATE_WARNING;
                if (warn_text == NULL) {
                    warn_text = strdup(_("System call sent warnings to stderr "));
                } else {
                    xasprintf(&warn_text, "%s %s", warn_text, _("System call sent warnings to stderr "));
                }
            }
        }
    }

    (void) fclose (child_stderr);


    spclose (child_process);

    if (warn_text == NULL)
        warn_text = strdup("");

    return result;
}
Пример #10
0
int
main (int argc, char **argv)
{
	int users = -1;
	int result = STATE_UNKNOWN;
	char input_buffer[MAX_INPUT_BUFFER];
	char *perf;

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	perf = strdup("");

	if (process_arguments (argc, argv) == ERROR)
		usage4 (_("Could not parse arguments"));

	/* run the command */
	child_process = spopen (WHO_COMMAND);
	if (child_process == NULL) {
		printf (_("Could not open pipe: %s\n"), WHO_COMMAND);
		return STATE_UNKNOWN;
	}

	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
	if (child_stderr == NULL)
		printf (_("Could not open stderr for %s\n"), WHO_COMMAND);

	users = 0;

	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {

		/* increment 'users' on all lines except total user count */
		if (input_buffer[0] != '#') {
			users++;
			continue;
		}

		/* get total logged in users */
		if (sscanf (input_buffer, _("# users=%d"), &users) == 1)
			break;

	}

	/* check STDERR */
	if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
		result = possibly_set (result, STATE_UNKNOWN);
	(void) fclose (child_stderr);

	/* close the pipe */
	if (spclose (child_process))
		result = possibly_set (result, STATE_UNKNOWN);

	/* else check the user count against warning and critical thresholds */
	if (users >= cusers)
		result = STATE_CRITICAL;
	else if (users >= wusers)
		result = STATE_WARNING;
	else if (users >= 0)
		result = STATE_OK;

	if (result == STATE_UNKNOWN)
		printf ("%s\n", _("Unable to read output"));
	else {
		asprintf(&perf, "%s", perfdata ("users", users, "",
		  TRUE, wusers,
		  TRUE, cusers,
		  TRUE, 0,
		  FALSE, 0));
		printf (_("USERS %s - %d users currently logged in |%s\n"), state_text (result),
		  users, perf);
	}

	return result;
}
Пример #11
0
int
main (int argc, char **argv)
{
	int percent_used, percent;
	float total_swap_mb = 0, used_swap_mb = 0, free_swap_mb = 0;
	float dsktotal_mb = 0, dskused_mb = 0, dskfree_mb = 0, tmp_mb = 0;
	int result = STATE_UNKNOWN;
	char input_buffer[MAX_INPUT_BUFFER];
#ifdef HAVE_PROC_MEMINFO
	FILE *fp;
#else
	int conv_factor = SWAP_CONVERSION;
# ifdef HAVE_SWAP
	char *temp_buffer;
	char *swap_command;
	char *swap_format;
# else
#  ifdef HAVE_DECL_SWAPCTL
	int i=0, nswaps=0, swapctl_res=0;
#   ifdef CHECK_SWAP_SWAPCTL_SVR4
	swaptbl_t *tbl=NULL;
	swapent_t *ent=NULL;
#   else
#    ifdef CHECK_SWAP_SWAPCTL_BSD
	struct swapent *ent;
#    endif /* CHECK_SWAP_SWAPCTL_BSD */
#   endif /* CHECK_SWAP_SWAPCTL_SVR4 */
#  endif /* HAVE_DECL_SWAPCTL */
# endif
#endif
	char str[32];
	char *status;

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	status = strdup ("");

	/* Parse extra opts if any */
	argv=np_extra_opts (&argc, argv, progname);

	if (process_arguments (argc, argv) == ERROR)
		usage4 (_("Could not parse arguments"));

#ifdef HAVE_PROC_MEMINFO
	if (verbose >= 3) {
		printf("Reading PROC_MEMINFO at %s\n", PROC_MEMINFO);
	}
	fp = fopen (PROC_MEMINFO, "r");
	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
		if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %f %f %f", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) {
			dsktotal_mb = dsktotal_mb / 1048576;	/* Apply conversion */
			dskused_mb = dskused_mb / 1048576;
			dskfree_mb = dskfree_mb / 1048576;
			total_swap_mb += dsktotal_mb;
			used_swap_mb += dskused_mb;
			free_swap_mb += dskfree_mb;
			if (allswaps) {
				if (dsktotal_mb == 0)
					percent=100.0;
				else
					percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
				result = max_state (result, check_swap (percent, dskfree_mb));
				if (verbose)
					xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
			}
		}
		else if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%[TotalFre]%*[:] %f %*[k]%*[B]", str, &tmp_mb)) {
			if (verbose >= 3) {
				printf("Got %s with %f\n", str, tmp_mb);
			}
			/* I think this part is always in Kb, so convert to mb */
			if (strcmp ("Total", str) == 0) {
				dsktotal_mb = tmp_mb / 1024;
			}
			else if (strcmp ("Free", str) == 0) {
				dskfree_mb = tmp_mb / 1024;
			}
		}
	}
	fclose(fp);
	dskused_mb = dsktotal_mb - dskfree_mb;
	total_swap_mb = dsktotal_mb;
	used_swap_mb = dskused_mb;
	free_swap_mb = dskfree_mb;
#else
# ifdef HAVE_SWAP
	xasprintf(&swap_command, "%s", SWAP_COMMAND);
	xasprintf(&swap_format, "%s", SWAP_FORMAT);

/* These override the command used if a summary (and thus ! allswaps) is required */
/* The summary flag returns more accurate information about swap usage on these OSes */
#  ifdef _AIX
	if (!allswaps) {
		xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s");
		xasprintf(&swap_format, "%s", "%f%*s %f");
		conv_factor = 1;
	}
#  endif

	if (verbose >= 2)
		printf (_("Command: %s\n"), swap_command);
	if (verbose >= 3)
		printf (_("Format: %s\n"), swap_format);

	child_process = spopen (swap_command);
	if (child_process == NULL) {
		printf (_("Could not open pipe: %s\n"), swap_command);
		return STATE_UNKNOWN;
	}

	child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
	if (child_stderr == NULL)
		printf (_("Could not open stderr for %s\n"), swap_command);

	sprintf (str, "%s", "");
	/* read 1st line */
	fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
	if (strcmp (swap_format, "") == 0) {
		temp_buffer = strtok (input_buffer, " \n");
		while (temp_buffer) {
			if (strstr (temp_buffer, "blocks"))
				sprintf (str, "%s %s", str, "%f");
			else if (strstr (temp_buffer, "dskfree"))
				sprintf (str, "%s %s", str, "%f");
			else
				sprintf (str, "%s %s", str, "%*s");
			temp_buffer = strtok (NULL, " \n");
		}
	}

/* If different swap command is used for summary switch, need to read format differently */
#  ifdef _AIX
	if (!allswaps) {
		fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process);	/* Ignore first line */
		sscanf (input_buffer, swap_format, &total_swap_mb, &used_swap_mb);
		free_swap_mb = total_swap_mb * (100 - used_swap_mb) /100;
		used_swap_mb = total_swap_mb - free_swap_mb;
		if (verbose >= 3)
			printf (_("total=%.0f, used=%.0f, free=%.0f\n"), total_swap_mb, used_swap_mb, free_swap_mb);
	} else {
#  endif
		while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
			sscanf (input_buffer, swap_format, &dsktotal_mb, &dskfree_mb);

			dsktotal_mb = dsktotal_mb / conv_factor;
			/* AIX lists percent used, so this converts to dskfree in MBs */
#  ifdef _AIX
			dskfree_mb = dsktotal_mb * (100 - dskfree_mb) / 100;
#  else
			dskfree_mb = dskfree_mb / conv_factor;
#  endif
			if (verbose >= 3)
				printf (_("total=%.0f, free=%.0f\n"), dsktotal_mb, dskfree_mb);

			dskused_mb = dsktotal_mb - dskfree_mb;
			total_swap_mb += dsktotal_mb;
			used_swap_mb += dskused_mb;
			free_swap_mb += dskfree_mb;
			if (allswaps) {
				percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
				result = max_state (result, check_swap (percent, dskfree_mb));
				if (verbose)
					xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
			}
		}
#  ifdef _AIX
	}
#  endif

	/* If we get anything on STDERR, at least set warning */
	while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
		result = max_state (result, STATE_WARNING);

	/* close stderr */
	(void) fclose (child_stderr);

	/* close the pipe */
	if (spclose (child_process))
		result = max_state (result, STATE_WARNING);
# else
#  ifdef CHECK_SWAP_SWAPCTL_SVR4

	/* get the number of active swap devices */
	if((nswaps=swapctl(SC_GETNSWP, NULL))== -1)
		die(STATE_UNKNOWN, _("Error getting swap devices\n") );

	if(nswaps == 0)
		die(STATE_OK, _("SWAP OK: No swap devices defined\n"));

	if(verbose >= 3)
		printf("Found %d swap device(s)\n", nswaps);

	/* initialize swap table + entries */
	tbl=(swaptbl_t*)malloc(sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));

	if(tbl==NULL)
		die(STATE_UNKNOWN, _("malloc() failed!\n"));

	memset(tbl, 0, sizeof(swaptbl_t)+(sizeof(swapent_t)*nswaps));
	tbl->swt_n=nswaps;
	for(i=0;i<nswaps;i++){
		if((tbl->swt_ent[i].ste_path=(char*)malloc(sizeof(char)*MAXPATHLEN)) == NULL)
			die(STATE_UNKNOWN, _("malloc() failed!\n"));
	}

	/* and now, tally 'em up */
	swapctl_res=swapctl(SC_LIST, tbl);
	if(swapctl_res < 0){
		perror(_("swapctl failed: "));
		die(STATE_UNKNOWN, _("Error in swapctl call\n"));
	}

	for(i=0;i<nswaps;i++){
		dsktotal_mb = (float) tbl->swt_ent[i].ste_pages / SWAP_CONVERSION;
		dskfree_mb = (float) tbl->swt_ent[i].ste_free /  SWAP_CONVERSION;
		dskused_mb = ( dsktotal_mb - dskfree_mb );

		if (verbose >= 3)
			printf ("dsktotal_mb=%.0f dskfree_mb=%.0f dskused_mb=%.0f\n", dsktotal_mb, dskfree_mb, dskused_mb);

		if(allswaps && dsktotal_mb > 0){
			percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
			result = max_state (result, check_swap (percent, dskfree_mb));
			if (verbose) {
				xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
			}
		}

		total_swap_mb += dsktotal_mb;
		free_swap_mb += dskfree_mb;
		used_swap_mb += dskused_mb;
	}

	/* and clean up after ourselves */
	for(i=0;i<nswaps;i++){
		free(tbl->swt_ent[i].ste_path);
	}
	free(tbl);
#  else
#   ifdef CHECK_SWAP_SWAPCTL_BSD

	/* get the number of active swap devices */
	nswaps=swapctl(SWAP_NSWAP, NULL, 0);

	/* initialize swap table + entries */
	ent=(struct swapent*)malloc(sizeof(struct swapent)*nswaps);

	/* and now, tally 'em up */
	swapctl_res=swapctl(SWAP_STATS, ent, nswaps);
	if(swapctl_res < 0){
		perror(_("swapctl failed: "));
		die(STATE_UNKNOWN, _("Error in swapctl call\n"));
	}

	for(i=0;i<nswaps;i++){
		dsktotal_mb = (float) ent[i].se_nblks / conv_factor;
		dskused_mb = (float) ent[i].se_inuse / conv_factor;
		dskfree_mb = ( dsktotal_mb - dskused_mb );

		if(allswaps && dsktotal_mb > 0){
			percent = 100 * (((double) dskused_mb) / ((double) dsktotal_mb));
			result = max_state (result, check_swap (percent, dskfree_mb));
			if (verbose) {
				xasprintf (&status, "%s [%.0f (%d%%)]", status, dskfree_mb, 100 - percent);
			}
		}

		total_swap_mb += dsktotal_mb;
		free_swap_mb += dskfree_mb;
		used_swap_mb += dskused_mb;
	}

	/* and clean up after ourselves */
	free(ent);

#   endif /* CHECK_SWAP_SWAPCTL_BSD */
#  endif /* CHECK_SWAP_SWAPCTL_SVR4 */
# endif /* HAVE_SWAP */
#endif /* HAVE_PROC_MEMINFO */

	/* if total_swap_mb == 0, let's not divide by 0 */
	if(total_swap_mb) {
		percent_used = 100 * ((double) used_swap_mb) / ((double) total_swap_mb);
	} else {
		percent_used = 0;
	}

	result = max_state (result, check_swap (percent_used, free_swap_mb));
	printf (_("SWAP %s - %d%% free (%d MB out of %d MB) %s|"),
			state_text (result),
			(100 - percent_used), (int) free_swap_mb, (int) total_swap_mb, status);

	puts (perfdata ("swap", (long) free_swap_mb, "MB",
	                TRUE, (long) max (warn_size_bytes/(1024 * 1024), warn_percent/100.0*total_swap_mb),
	                TRUE, (long) max (crit_size_bytes/(1024 * 1024), crit_percent/100.0*total_swap_mb),
	                TRUE, 0,
	                TRUE, (long) total_swap_mb));

	return result;
}