Back to index

nagios-plugins  1.4.16
check_oracle.c
Go to the documentation of this file.
00001 /*                                                                          
00002         Source: check_oracle.c
00003         Author: Adam G. Bowen (agbowen@bealenet.com)
00004         $Revision: 1.1 $
00005         $Date: 1999/05/17 14:46:57 $
00006  
00007  * Program: Oracle listener plugin for NetSaint
00008  * License: GPL
00009  * Copyright (c) 1999 Adam G. Bowen (agbowen@bealenet.com)
00010  *
00011  * Description:
00012  *
00013  * This plugin will establish a socket on the oracle port of the host specified 
00014  * by ipaddress and receives a responce from the host.  If any error occures 
00015  * while creating the socket, receiving data from the socket or closing the 
00016  * socket, this error will result in an alert.  The incorrect responce or 
00017  * responce time above the threshold vaules will also cause an alert. 
00018  *
00019  * Other errors result in a STATE_UNKNOWN return.
00020  *
00021  * Command line:
00022  *
00023  * check_oracle ipaddress sys_type
00024  * check_oracle ipaddress sys_type <warn_ms> <crit_ms>
00025  *
00026  * Required input:
00027  *
00028  * ipaddress = The ipaddress of the remote system to run the check on.
00029  * sys_type = The remote system type.
00030  *
00031  * Optional input:
00032  *
00033  * <warn_ms> = Number of miliseconds necessary to result in a WARNING state.
00034  * <crit_ms> = Number of miliseconds necessary to result in a CRITICAL state.
00035  *
00036  * Notes:
00037  *
00038  * If <warn_ms> and <crit_ms> are not passed on the command line, they will be 
00039  * set to the default values in the check_fs config file.
00040  *
00041  * sys_type is used to determine which config file to use to generate the
00042  * remote command.
00043  *
00044  * The configuration file /usr/local/netsaint/config/check_oracle/<sys_type>
00045  * contains the following values:
00046  *
00047  * ORACLE_PORT|<oracle listener port on system sys_type>|
00048  * ORACLE_PROTO|<protocol to use for socket>|
00049  * WARN_MS|<default number of miliseconds needed to generate a warning>|
00050  * CRIT_MS|<default number of miliseconds needed to generate a critical>|
00051  *
00052  * $Log: check_oracle.c,v $
00053  * Revision 1.1  1999/05/17 14:46:57  netsaint
00054  * Initial revision
00055  *
00056  *
00057 */
00058 
00059 #include "/usr/local/src/netsaint/include/plugins.h"
00060 
00061 int main(int argc, char *argv[])
00062 {
00063   char command_name[MAX_CHARS];
00064   char config_file_net[MAX_CHARS];
00065   char ip_address[MAX_CHARS];
00066   char ms_crit[MAX_CHARS];
00067   char ms_warn[MAX_CHARS];
00068   char port_oracle[MAX_CHARS];
00069   char protocol[MAX_CHARS];
00070   char system_name[MAX_CHARS];
00071 
00072   int crit_ms;
00073   int end_time;
00074   int oracle_port;
00075   int get_defaults;
00076   int micro_seconds;
00077   int result;
00078   int return_value;
00079   int seconds;
00080   int socket_name;
00081   int start_time;
00082   int total_time;
00083   int warn_ms;
00084 
00085   struct timeval end_buff;
00086   struct timeval start_buff;
00087   struct timezone end_tz;
00088   struct timezone start_tz;
00089 
00090   /* Initialize alarm signal handling */
00091 
00092   signal(SIGALRM,alarm_signal);
00093 
00094   strcpy(command_name,get_command_name(argv[0]));
00095   if(!((argc==3) || (argc==5)))
00096   {
00097     printf("\n");
00098     printf(" Incorrect number of arguments supplied\n");
00099     printf("\n");
00100     printf(" Oracle listener plugin for NetSaint\n");
00101     printf(" Copyright (c) 1999 Adam G. Bowen (agbowen@bealenet.com)\n");
00102     printf(" $Revision: 1.1 $\n");
00103     printf(" Last Modified $Date: 1999/05/17 14:46:57 $\n");
00104     printf(" License: GPL\n");
00105     printf("\n");
00106     printf(" Description:\n");
00107     printf("\n");
00108     printf(" This plugin will establish a socket on the oracle port of the host specified \n");
00109     printf(" by ipaddress and receives a responce from the host.  If any error occures \n");
00110     printf(" while creating the socket, receiving data from the socket or closing the \n");
00111     printf(" socket, this error will result in an alert.  The incorrect responce or \n");
00112     printf(" responce time above the threshold vaules will also cause an alert. \n");
00113     printf("\n");
00114     printf(" Usage: %s ipaddress sys_type\n",command_name);
00115     printf(" Usage: %s ipaddress sys_type <warn_ms> <crit_ms>\n",command_name);
00116     printf("\n");
00117     printf(" Required input:\n");
00118     printf("\n");
00119     printf(" ipaddress = The ipaddress of the remote system to run the check on.\n");
00120     printf(" sys_type = The remote system type.\n");
00121     printf("\n");
00122     printf(" Optional input:\n");
00123     printf("\n");
00124     printf(" <warn_ms> = Number of miliseconds necessary to result in a WARNING state.\n");
00125     printf(" <crit_ms> = Number of miliseconds necessary to result in a CRITICAL state.\n");
00126     printf("\n");
00127     printf(" If <warn_ms> and <crit_ms> are not passed on the command line, they will be\n");
00128     printf(" set to the default values in the %s config file.\n", command_name);
00129     printf("\n");
00130     printf(" sys_type is used to determine which config file to use to generate the\n");
00131     printf(" remote command.\n");
00132     printf("\n");
00133     return_value = STATE_UNKNOWN;
00134   }
00135   else
00136   {
00137     /* Set up config files and get the command line information */
00138 
00139     strcpy(ip_address,argv[1]);
00140     strcpy(system_name,argv[2]);
00141 
00142     strcpy(config_file_net,CONFIG_DIR);
00143     strcat(config_file_net,command_name);
00144     strcat(config_file_net,"/");
00145     strcat(config_file_net,system_name);
00146 
00147     if(argc == 3)
00148     {
00149       get_defaults = TRUE;
00150     }
00151     else
00152     {
00153       get_defaults = FALSE;
00154       strcpy(ms_warn,argv[3]);
00155       strcpy(ms_crit,argv[4]);
00156     }
00157 
00158     /* Check if config files exist */
00159 
00160     if (access(config_file_net, EXISTS) != 0 )
00161     {
00162       printf("Config file %s does not exist!\n",config_file_net);
00163       return_value = STATE_UNKNOWN;
00164     }
00165     else
00166     {
00167 
00168       /* Network config file variables */
00169 
00170       if((get_defaults == TRUE) && ((return_value=get_var("WARN_MS", config_file_net, ms_warn)) != STATE_OK))
00171       {
00172         printf("WARN_MS entry not found in config file %s!\n",config_file_net);
00173       }
00174       else if((get_defaults == TRUE) && ((return_value=get_var("CRIT_MS", config_file_net, ms_crit)) != STATE_OK))
00175       {
00176         printf("CRIT_MS entry not found in config file %s!\n",config_file_net);
00177       }
00178       else if((return_value=get_var("ORACLE_PORT", config_file_net, port_oracle)) != STATE_OK)
00179       {
00180         printf("ORACLE_PORT entry not found in config file %s!\n",config_file_net);
00181       }
00182       else if((return_value=get_var("ORACLE_PROTO", config_file_net, protocol)) != STATE_OK)
00183       {
00184         printf("ORACLE_PROTO entry not found in config file %s!\n",config_file_net);
00185       }
00186       else
00187       {
00188 
00189         /* Check alert level consistency */
00190 
00191         warn_ms=atoi(ms_warn);
00192         crit_ms=atoi(ms_crit);
00193         return_value = check_consistency(warn_ms, crit_ms);
00194         if(return_value == STATE_OK)
00195         {
00196 
00197           /* Check the network */
00198 
00199           oracle_port=atoi(port_oracle);
00200           gettimeofday(&start_buff, &start_tz);
00201 
00202           /* Set alarm */
00203 
00204           alarm(TIME_OUT); 
00205           if((result=open_socket(&socket_name, ip_address, oracle_port, protocol)) != STATE_OK)
00206           {
00207             return_value=exit_error(result,ip_address,protocol,oracle_port);
00208           }
00209           else if((result=close_socket(&socket_name)) != STATE_OK)
00210           {
00211             return_value=exit_error(result,ip_address,protocol,oracle_port);
00212           }
00213           else
00214           {
00215 
00216             /* Nothing hungup so reset alarm */
00217 
00218             alarm(0); 
00219             gettimeofday(&end_buff, &end_tz);
00220             seconds=(start_buff.tv_sec%1000);
00221             micro_seconds=start_buff.tv_usec;
00222             start_time=((seconds * 1000) + (micro_seconds/1000));
00223             seconds=(end_buff.tv_sec%1000);
00224             micro_seconds=end_buff.tv_usec;
00225             end_time=((seconds * 1000) + (micro_seconds/1000));
00226             total_time = end_time - start_time;
00227             if(total_time > crit_ms)
00228             {
00229               return_value = STATE_CRITICAL;
00230             }
00231             else if(total_time > warn_ms)
00232             {
00233               return_value = STATE_WARNING;
00234             }
00235             if(return_value == STATE_OK)
00236             {
00237               printf("Oracle ok - %d ms responce time.\n",total_time);
00238             }
00239             else
00240             {
00241               printf("Oracle error slow responce time - %d ms.\n",total_time);
00242             }
00243           }
00244         }
00245       }
00246     }
00247   }
00248   return return_value;
00249 }