Back to index

nagios-plugins  1.4.16
Defines | Functions | Variables
check_users.c File Reference
#include "common.h"
#include "utils.h"
#include <utmpx.h>

Go to the source code of this file.

Defines

#define possibly_set(a, b)   ((a) == 0 ? (b) : 0)

Functions

int process_arguments (int, char **)
void print_help (void)
void print_usage (void)
int main (int argc, char **argv)

Variables

const char * progname = "check_users"
const char * copyright = "2000-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
int wusers = -1
int cusers = -1

Define Documentation

#define possibly_set (   a,
 
)    ((a) == 0 ? (b) : 0)

Definition at line 41 of file check_users.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file check_users.c.

{
       int users = -1;
       int result = STATE_UNKNOWN;
       char *perf;
       struct utmpx *putmpx;

       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;

       /* get currently logged users from utmpx */
       setutxent ();

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

       endutxent ();

       /* 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;
}

Here is the call graph for this function:

void print_help ( void  )
void print_usage ( void  )

Definition at line 389 of file check_cpqarray.c.

{
  printf("cpqarrayd [options]\n");
  printf("   -h         prints this text\n");
  printf("   -d         enables debugging\n");
}
int process_arguments ( int  argc,
char **  argv 
)

Variable Documentation

const char* copyright = "2000-2007"

Definition at line 34 of file check_users.c.

int cusers = -1

Definition at line 48 of file check_users.c.

const char* email = "nagiosplug-devel@lists.sourceforge.net"

Definition at line 35 of file check_users.c.

const char* progname = "check_users"

Definition at line 33 of file check_users.c.

int wusers = -1

Definition at line 47 of file check_users.c.