File: status.c

package info (click to toggle)
cpqarrayd 2.3-1.3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,008 kB
  • sloc: sh: 2,907; ansic: 1,039; makefile: 83
file content (274 lines) | stat: -rw-r--r-- 7,466 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
   CpqArray Deamon, a program to monitor and remotely configure a 
   SmartArray controller.
   Copyright (C) 1999-2003  Hugo Trippaers

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
   $Header: /spark/cpqarrayd/status.c,v 1.10 2007/12/03 17:06:22 spark Exp $
*/

#include "config.h"

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#if defined(HAVE_LINUX_COMPILER_H)
  #include <linux/compiler.h>
#endif

#include <sys/ioctl.h>

#ifdef HAVE_IDA
#include <ida_ioctl.h>
#include <ida_cmd.h>
#include <cpqarray.h>
#endif

#include <syslog.h>

#include "cpqarrayd.h"
#include "sendtrap.h"

#include <linux/cciss_ioctl.h>
#include "cciss_structs.h"
#include "cciss_functions.h"

#ifdef HAVE_IDA
int status_check (struct opts opts)
{
  
  int devicefd;
  int ctrl_cntr;
  int logd_cntr;
  ida_ioctl_t io, io2;
  int status, nr_blks, blks_tr, trap_stat;
  float pvalue;
  char statusmsg[1024];
  int counter;
  
    
  for ( ctrl_cntr=0;
        ctrl_cntr <  ctrls_found_num;
        ctrl_cntr++) {
    if (ctrls_found[ctrl_cntr].ctrl_type != CTRLTYPE_IDA) {
      break;
    }

    devicefd = open (ctrls_found[ctrl_cntr].devicefile, O_RDONLY);
    
    for ( logd_cntr=0;
          logd_cntr < ctrls_found[ctrl_cntr].num_logd_found;
          logd_cntr++) {
      
        memset (&io, 0, sizeof (io));

        io.cmd = SENSE_LOG_DRV_STAT;
        io.unit = logd_cntr  | UNITVALID;
        
        if (ioctl (devicefd, IDAPASSTHRU, &io) < 0)
          {
            perror ("SENSE_LOG_DRV_STAT ioctl");
            return 0;
          }

        status=io.c.sense_log_drv_stat.status;
        
        if ((status == 3) || (status == 5) || (status == 7)) {
          /* is a progress indicator required?
           */
          memset (&io2, 0, sizeof (io));
          
          io2.cmd = ID_LOG_DRV;
          io2.unit = logd_cntr  | UNITVALID;
          
          if (ioctl (devicefd, IDAPASSTHRU, &io2) < 0)
            {
              perror ("ID_LOG_DRV ioctl");
              /* return 0;   no return this isn't fatal for now */
            }
          else 
            {
              nr_blks = io2.c.id_log_drv.nr_blks;
              blks_tr = io.c.sense_log_drv_stat.blks_to_recover;
                  
              pvalue = ((float)(nr_blks - blks_tr)/(float)nr_blks) * 100;

            }
        }
        else {
          pvalue = 0.0;
        }

        if (opts.debug) {
	  fprintf(stdout, "DEBUG: Status of controller %d unit %d is %d\n", 
		  ctrl_cntr, logd_cntr, status);
          fprintf(stdout, "DEBUG: ");
	  fprintf(stdout, statusstr[status], 
		  ctrl_cntr, logd_cntr, pvalue);
	  fprintf(stdout, "\n");
	}
	
	if (status != ctrls_found[ctrl_cntr].log_disk[logd_cntr].status) {
	  /* status changed, time to send a trap */
	  syslog(LOG_WARNING, "/dev/c%dd%d: Status change.", ctrl_cntr, 
		 logd_cntr);
	  syslog(LOG_WARNING, statusstr[status], ctrl_cntr, logd_cntr,
		 pvalue);
	  if (opts.debug) {
	    printf ("DEBUG: status changed from %d to %d, pvalue = %f\n",
		    ctrls_found[ctrl_cntr].log_disk[logd_cntr].status, status,
		    pvalue);
	  }
	  sprintf(statusmsg, statusstr[status], ctrl_cntr, logd_cntr, pvalue);
	  if (opts.debug) {
	      printf("DEBUG: sending traps.\n");
	  }
	  /* Send a trap, syslog if send_trap returns !0. */
	  if (trap_stat = sendtrap(opts, "beheer", status, statusmsg)) {
	    syslog(LOG_WARNING, 
		   "problem sending snmp trap (sendtrap() returned %d)\n",
		   trap_stat);
	    if (opts.debug) {
	      printf("DEBUG: Problem sending snmp trap",
		     "(sendtrap() returned %d)\n", 
		     trap_stat);
	    }
	  }
	}
	else if ((status == 5) && 
		 ((pvalue - ctrls_found[ctrl_cntr].log_disk[logd_cntr].pvalue)
		  >= 25.0 )) {
	  /* pvalue changed by more than 25%, time to send a trap */
	  syslog(LOG_WARNING, "/dev/c%dd%d: Percentile value change.", 
		 ctrl_cntr, logd_cntr);
	  syslog(LOG_WARNING, statusstr[status], ctrl_cntr, logd_cntr,
		 pvalue);
	  if (opts.debug) {
	    printf ("DEBUG: pvalue changed from %f to %f\n",
		    ctrls_found[ctrl_cntr].log_disk[logd_cntr].pvalue,
		    pvalue);
	  }
	  sprintf(statusmsg, statusstr[status], ctrl_cntr, logd_cntr, pvalue);
	  if (opts.debug) {
	      printf("DEBUG: sending traps.\n");
	  }
	  if (trap_stat = sendtrap(opts, "beheer", status, statusmsg)) {
	    syslog(LOG_WARNING,
		   "problem sending snmp trap (sendtrap() returned %d)\n",
		   trap_stat);
	    if (opts.debug) {
	      printf("DEBUG: Problem sending snmp trap ",
		     "(sendtrap() returned %d)\n",
		     trap_stat);
	    }
	  }
	  ctrls_found[ctrl_cntr].log_disk[logd_cntr].pvalue = pvalue;
	}
	ctrls_found[ctrl_cntr].log_disk[logd_cntr].status = status;
    }
    close (devicefd);
  }

  return 1;
 
}
#endif

int cciss_status_check (struct opts opts) 
{
  
  int devicefd;
  int ctrl_cntr, result;
  int logd_cntr;
  int status, nr_blks, blks_tr, trap_stat;
  float pvalue;
  char statusmsg[2048];
  int counter;
  cciss_event_type event;
  
    
  for ( ctrl_cntr=0;
        ctrl_cntr <  ctrls_found_num;
        ctrl_cntr++) {
    if (ctrls_found[ctrl_cntr].ctrl_type != CTRLTYPE_CCISS) {
      break;
    }

    devicefd = open (ctrls_found[ctrl_cntr].devicefile, O_RDONLY);
    
    result = cciss_get_event(devicefd, 0, &event);
    while (!CompareEvent(event,0,0,0)) {
      printf ("DEBUG: Got event %d/%d/%d\n",
	      event.class.class, event.class.subclass, event.class.detail);
      if (CompareEvent(event,5,0,0)) {
	snprintf(statusmsg, 2048, "CCISS controller %s logical volume %d changed state to %s.",
		 ctrls_found[ctrl_cntr].devicefile,
		 event.detail.logstatchange.logicaldrivenumber,
		 logicaldrivestatusstr[event.detail.logstatchange.newlogicaldrivestate]);
	status = event.detail.logstatchange.newlogicaldrivestate;
	syslog(LOG_WARNING, statusmsg);
	if (opts.debug) {
	  printf (statusmsg);
	}
	if (trap_stat = sendtrap(opts, "public", status, statusmsg)) {
	  syslog(LOG_WARNING, 
		 "problem sending snmp trap (sendtrap() returned %d)\n",
		 trap_stat);
	  if (opts.debug) {
	    printf("DEBUG: Problem sending snmp trap",
		   "(sendtrap() returned %d)\n", 
		   trap_stat);
	  }
	}
      }
      else {
	snprintf(statusmsg, 2048, "CCISS controller %s reported: %s.",
		 ctrls_found[ctrl_cntr].devicefile,
		 event.mesgstring);
	status = 255;
	syslog(LOG_WARNING, statusmsg);
	if (opts.debug) {
	  printf (statusmsg);
	}
	if (trap_stat = sendtrap(opts, "public", status, statusmsg)) {
	  syslog(LOG_WARNING, 
		 "problem sending snmp trap (sendtrap() returned %d)\n",
		 trap_stat);
	  if (opts.debug) {
	    printf("DEBUG: Problem sending snmp trap",
		   "(sendtrap() returned %d)\n", 
		   trap_stat);
	  }
	}
      }
      result = cciss_get_event(devicefd, 0, &event);
    }

    close (devicefd);
  }

  return 1;
 
}