Back to index

nagios-plugins  1.4.16
Classes | Defines | Enumerations | Functions | Variables
check_ide_smart.c File Reference
#include "common.h"
#include "utils.h"
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/hdreg.h>
#include <linux/types.h>
#include <errno.h>

Go to the source code of this file.

Classes

struct  threshold_s

Defines

#define NR_ATTRIBUTES   30
#define TRUE   1
#define PREFAILURE   2
#define ADVISORY   1
#define OPERATIONAL   0
#define UNKNOWN   -1

Enumerations

enum  SmartCommand { SMART_CMD_ENABLE, SMART_CMD_DISABLE, SMART_CMD_IMMEDIATE_OFFLINE, SMART_CMD_AUTO_OFFLINE }

Functions

void print_help (void)
void print_usage (void)
struct threshold_s __attribute__ ((packed))
void print_values (values_t *p, thresholds_t *t)
int smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
int main (int argc, char *argv[])
char * get_offline_text (int status)
int smart_read_values (int fd, values_t *values)
int values_not_passed (values_t *p, thresholds_t *t)
int nagios (values_t *p, thresholds_t *t)
void print_value (value_t *p, threshold_t *t)
int smart_read_thresholds (int fd, thresholds_t *thresholds)

Variables

const char * progname = "check_ide_smart"
const char * copyright = "1998-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
__u8 id
__u8 threshold
__u8 reserved [10]
 offline_status_text []
struct {
__u8 value
char * text
smart_command []

Class Documentation

struct threshold_s

Definition at line 64 of file check_ide_smart.c.

Class Members
__u8 id
__u8 reserved
__u8 threshold

Define Documentation

#define ADVISORY   1

Definition at line 60 of file check_ide_smart.c.

#define NR_ATTRIBUTES   30

Definition at line 53 of file check_ide_smart.c.

#define OPERATIONAL   0

Definition at line 61 of file check_ide_smart.c.

#define PREFAILURE   2

Definition at line 59 of file check_ide_smart.c.

#define TRUE   1

Definition at line 56 of file check_ide_smart.c.

#define UNKNOWN   -1

Definition at line 62 of file check_ide_smart.c.


Enumeration Type Documentation

Enumerator:
SMART_CMD_ENABLE 
SMART_CMD_DISABLE 
SMART_CMD_IMMEDIATE_OFFLINE 
SMART_CMD_AUTO_OFFLINE 

Definition at line 139 of file check_ide_smart.c.


Function Documentation

__attribute__ ( (packed)  )

Definition at line 70 of file check_ide_smart.c.

{
       __u16 revision;
       threshold_t thresholds[NR_ATTRIBUTES];
       __u8 reserved[18];
       __u8 vendor[131];
       __u8 checksum;
}
char* get_offline_text ( int  status)

Definition at line 271 of file check_ide_smart.c.

{
       int i;
       for (i = 0; offline_status_text[i].text; i++) {
              if (offline_status_text[i].value == status) {
                     return offline_status_text[i].text;
              }
       }
       return "UNKNOW";
}

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 150 of file check_ide_smart.c.

{
       char *device = NULL;
       int command = -1;
       int o, longindex;
       int retval = 0;

       thresholds_t thresholds;
       values_t values;
       int fd;

       static struct option longopts[] = { 
              {"device", required_argument, 0, 'd'}, 
              {"immediate", no_argument, 0, 'i'}, 
              {"quiet-check", no_argument, 0, 'q'}, 
              {"auto-on", no_argument, 0, '1'}, 
              {"auto-off", no_argument, 0, '0'}, 
              {"nagios", no_argument, 0, 'n'}, 
              {"help", no_argument, 0, 'h'}, 
              {"version", no_argument, 0, 'V'},
              {0, 0, 0, 0}
       };

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

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

       while (1) {
              
              o = getopt_long (argc, argv, "+d:iq10nhV", longopts, &longindex);

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

              switch (o) {
              case 'd':
                     device = optarg;
                     break;
              case 'q':
                     command = 3;
                     break;
              case 'i':
                     command = 2;
                     break;
              case '1':
                     command = 1;
                     break;
              case '0':
                     command = 0;
                     break;
              case 'n':
                     command = 4;
                     break;
              case 'h':
                     print_help ();
                     return STATE_OK;
              case 'V':
                     print_revision (progname, NP_VERSION);
                     return STATE_OK;
              default:
                     usage5 ();
              }
       }

       if (optind < argc) {
              device = argv[optind];
       }

       if (!device) {
              print_help ();
              return STATE_OK;
       }

       fd = open (device, O_RDONLY);

       if (fd < 0) {
              printf (_("CRITICAL - Couldn't open device %s: %s\n"), device, strerror (errno));
              return STATE_CRITICAL;
       }

       if (smart_cmd_simple (fd, SMART_CMD_ENABLE, 0, TRUE)) {
              printf (_("CRITICAL - SMART_CMD_ENABLE\n"));
              return STATE_CRITICAL;
       }

       switch (command) {
       case 0:
              retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0, TRUE);
              break;
       case 1:
              retval = smart_cmd_simple (fd, SMART_CMD_AUTO_OFFLINE, 0xF8, TRUE);
              break;
       case 2:
              retval = smart_cmd_simple (fd, SMART_CMD_IMMEDIATE_OFFLINE, 0, TRUE);
              break;
       case 3:
              smart_read_values (fd, &values);
              smart_read_thresholds (fd, &thresholds);
              retval = values_not_passed (&values, &thresholds);
              break;
       case 4:
              smart_read_values (fd, &values);
              smart_read_thresholds (fd, &thresholds);
              retval = nagios (&values, &thresholds);
              break;
       default:
              smart_read_values (fd, &values);
              smart_read_thresholds (fd, &thresholds);
              print_values (&values, &thresholds);
              break;
       }
       close (fd);
       return retval;
}

Here is the call graph for this function:

int nagios ( values_t *  p,
thresholds_t *  t 
)

Definition at line 330 of file check_ide_smart.c.

{
       value_t * value = p->values;
       threshold_t * threshold = t->thresholds;
       int status = OPERATIONAL;
       int prefailure = 0;
       int advisory = 0;
       int failed = 0;
       int passed = 0;
       int total = 0;
       int i;
       for (i = 0; i < NR_ATTRIBUTES; i++) {
              if (value->id && threshold->id && value->id == threshold->id) {
                     if (value->value <= threshold->threshold) {
                            ++failed;
                            if (value->status & 1) {
                                   status = PREFAILURE;
                                   ++prefailure;
                            }
                            else {
                                   status = ADVISORY;
                                   ++advisory;
                            }
                     }
                     else {
                            ++passed;
                     }
                     ++total;
              }
              ++value;
              ++threshold;
       }
       switch (status) {
       case PREFAILURE:
              printf (_("CRITICAL - %d Harddrive PreFailure%cDetected! %d/%d tests failed.\n"),
                      prefailure,
                      prefailure > 1 ? 's' : ' ',
                      failed,
                 total);
              status=STATE_CRITICAL;
              break;
       case ADVISORY:
              printf (_("WARNING - %d Harddrive Advisor%s Detected. %d/%d tests failed.\n"),
                      advisory,
                      advisory > 1 ? "ies" : "y",
                      failed,
                      total);
              status=STATE_WARNING;
              break;
       case OPERATIONAL:
              printf (_("OK - Operational (%d/%d tests passed)\n"), passed, total);
              status=STATE_OK;
              break;
       default:
              printf (_("ERROR - Status '%d' unkown. %d/%d tests passed\n"), status,
                                          passed, total);
              status = STATE_UNKNOWN;
              break;
       }
       return status;
}

Here is the caller 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");
}
void print_value ( value_t *  p,
threshold_t *  t 
)

Definition at line 395 of file check_ide_smart.c.

{
       printf ("Id=%3d, Status=%2d {%s , %s}, Value=%3d, Threshold=%3d, %s\n",
                                   p->id, p->status, p->status & 1 ? "PreFailure" : "Advisory   ",
                                   p->status & 2 ? "OnLine " : "OffLine", p->value, t->threshold,
                                   p->value > t->threshold ? "Passed" : "Failed");
}

Here is the caller graph for this function:

void print_values ( values_t *  p,
thresholds_t *  t 
)

Definition at line 406 of file check_ide_smart.c.

{
       value_t * value = p->values;
       threshold_t * threshold = t->thresholds;
       int i;
       for (i = 0; i < NR_ATTRIBUTES; i++) {
              if (value->id && threshold->id && value->id == threshold->id) {
                     print_value (value++, threshold++);
              }
       }
       printf
              (_("OffLineStatus=%d {%s}, AutoOffLine=%s, OffLineTimeout=%d minutes\n"),
               p->offline_status,
               get_offline_text (p->offline_status & 0x7f),
               (p->offline_status & 0x80 ? "Yes" : "No"),
               p->offline_timeout / 60);
       printf
              (_("OffLineCapability=%d {%s %s %s}\n"),
               p->offline_capability,
               p->offline_capability & 1 ? "Immediate" : "",
               p->offline_capability & 2 ? "Auto" : "",
               p->offline_capability & 4 ? "AbortOnCmd" : "SuspendOnCmd");
       printf
              (_("SmartRevision=%d, CheckSum=%d, SmartCapability=%d {%s %s}\n"),
               p->revision,
               p->checksum,
               p->smart_capability,
               p->smart_capability & 1 ? "SaveOnStandBy" : "",
               p->smart_capability & 2 ? "AutoSave" : "");
}

Here is the call graph for this function:

Here is the caller graph for this function:

int smart_cmd_simple ( int  fd,
enum SmartCommand  command,
__u8  val0,
char  show_error 
)

Definition at line 439 of file check_ide_smart.c.

{
       int e = 0;
       __u8 args[4];
       args[0] = WIN_SMART;
       args[1] = val0;
       args[2] = smart_command[command].value;
       args[3] = 0;
       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
              e = errno;
              if (show_error) {
                     printf (_("CRITICAL - %s: %s\n"), smart_command[command].text, strerror (errno));
              }
       }
       return e;
}

Here is the caller graph for this function:

int smart_read_thresholds ( int  fd,
thresholds_t *  thresholds 
)

Definition at line 459 of file check_ide_smart.c.

{
       int e;
       __u8 args[4 + 512];
       args[0] = WIN_SMART;
  args[1] = 0;
  args[2] = SMART_READ_THRESHOLDS;
  args[3] = 1;
       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
              e = errno;
              printf (_("CRITICAL - SMART_READ_THRESHOLDS: %s\n"), strerror (errno));
              return e;
       }
       memcpy (thresholds, args + 4, 512);
       return 0;
}

Here is the caller graph for this function:

int smart_read_values ( int  fd,
values_t *  values 
)

Definition at line 285 of file check_ide_smart.c.

{
       int e;
       __u8 args[4 + 512];
       args[0] = WIN_SMART;
       args[1] = 0;
       args[2] = SMART_READ_VALUES;
       args[3] = 1;
       if (ioctl (fd, HDIO_DRIVE_CMD, &args)) {
              e = errno;
              printf (_("CRITICAL - SMART_READ_VALUES: %s\n"), strerror (errno));
              return e;
       }
       memcpy (values, args + 4, 512);
       return 0;
}

Here is the caller graph for this function:

int values_not_passed ( values_t *  p,
thresholds_t *  t 
)

Definition at line 305 of file check_ide_smart.c.

{
       value_t * value = p->values;
       threshold_t * threshold = t->thresholds;
       int failed = 0;
       int passed = 0;
       int i;
       for (i = 0; i < NR_ATTRIBUTES; i++) {
              if (value->id && threshold->id && value->id == threshold->id) {
                     if (value->value <= threshold->threshold) {
                            ++failed;
                     }
                     else {
                            ++passed;
                     }
              }
              ++value;
              ++threshold;
       }
       return (passed ? -failed : 2);
}

Here is the caller graph for this function:


Variable Documentation

const char* copyright = "1998-2007"

Definition at line 37 of file check_ide_smart.c.

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

Definition at line 38 of file check_ide_smart.c.

__u8 id

Definition at line 74 of file check_ide_smart.c.

Initial value:
       {
              {0x00, "NeverStarted"},
              {0x02, "Completed"},
              {0x04, "Suspended"},
              {0x05, "Aborted"},
              {0x06, "Failed"},
              {0, 0}
       }

Definition at line 113 of file check_ide_smart.c.

const char* progname = "check_ide_smart"

Definition at line 36 of file check_ide_smart.c.

__u8 reserved[10]

Definition at line 76 of file check_ide_smart.c.

struct { ... } smart_command[]
__u8 threshold

Definition at line 75 of file check_ide_smart.c.