~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to src/libs/zbxsysinfo/solaris/SunOS5.9.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
** ZABBIX
3
 
** Copyright (C) 2000-2005 SIA Zabbix
4
 
**
5
 
** This program is free software; you can redistribute it and/or modify
6
 
** it under the terms of the GNU General Public License as published by
7
 
** the Free Software Foundation; either version 2 of the License, or
8
 
** (at your option) any later version.
9
 
**
10
 
** This program is distributed in the hope that it will be useful,
11
 
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
** GNU General Public License for more details.
14
 
**
15
 
** You should have received a copy of the GNU General Public License
16
 
** along with this program; if not, write to the Free Software
17
 
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 
**/
19
 
 
20
 
#include "config.h"
21
 
#include "log.h"
22
 
 
23
 
#include <dirent.h>
24
 
#include <errno.h>
25
 
#include <fcntl.h>
26
 
#include <kstat.h>
27
 
#include <memory.h>
28
 
#include <procfs.h>
29
 
#include <string.h>
30
 
#include <strings.h>
31
 
#include <stdio.h>
32
 
#include <stdlib.h>
33
 
#include <unistd.h>
34
 
#include <sys/loadavg.h>
35
 
#include <sys/proc.h>
36
 
#include <sys/stat.h>
37
 
#include <sys/statvfs.h>
38
 
#include <sys/sysinfo.h>
39
 
#include <sys/time.h>
40
 
#include <sys/types.h>
41
 
#include <sys/var.h>
42
 
 
43
 
#ifdef HAVE_LDAP
44
 
        #include <ldap.h>
45
 
#endif
46
 
 
47
 
#include "common.h"
48
 
#include "sysinfo.h"
49
 
 
50
 
/*
51
 
 * ADDED to /solaric/diskio.c
52
 
 *   
53
 
typedef struct busy_data
54
 
{
55
 
  hrtime_t clock;
56
 
  hrtime_t rtime;
57
 
} BUSY_DATA;
58
 
 
59
 
typedef struct svc_time_data
60
 
{
61
 
  hrtime_t rtime;
62
 
  uint_t reads;
63
 
  uint_t writes;
64
 
} SVC_TIME_DATA;
65
 
 
66
 
typedef struct read_ios_data
67
 
{
68
 
  hrtime_t clock;
69
 
  uint_t reads;
70
 
} READ_IOS_DATA;
71
 
 
72
 
typedef struct write_ios_data
73
 
{
74
 
  hrtime_t clock;
75
 
  uint_t writes;
76
 
} WRITE_IOS_DATA;
77
 
 
78
 
typedef struct rblocks_data
79
 
{
80
 
  hrtime_t clock;
81
 
  u_longlong_t nread;
82
 
} RBLOCKS_DATA;
83
 
 
84
 
typedef struct wblocks_data
85
 
{
86
 
  hrtime_t clock;
87
 
  u_longlong_t nwritten;
88
 
} WBLOCKS_DATA;
89
 
 
90
 
typedef struct disk_data
91
 
{
92
 
  struct disk_data *next;
93
 
  char *name;
94
 
  BUSY_DATA busy;
95
 
  SVC_TIME_DATA svc;
96
 
  READ_IOS_DATA reads;
97
 
  WRITE_IOS_DATA writes;
98
 
  RBLOCKS_DATA rblocks;
99
 
  WBLOCKS_DATA wblocks;
100
 
 } DISK_DATA;
101
 
*/
102
 
 
103
 
/*
104
 
 * ADDED to /solaric/net.c
105
 
 *   
106
 
typedef union value_overlay
107
 
{
108
 
  union 
109
 
  {
110
 
    zbx_uint64_t ui64;
111
 
    uint32_t ui32;
112
 
  } u;
113
 
} VALUE_OVERLAY;
114
 
 
115
 
typedef struct rbytes_data
116
 
{
117
 
  hrtime_t clock;
118
 
  VALUE_OVERLAY rbytes;
119
 
} RBYTES_DATA;
120
 
 
121
 
typedef struct obytes_data
122
 
{
123
 
  hrtime_t clock;
124
 
  VALUE_OVERLAY obytes;
125
 
} OBYTES_DATA;
126
 
 
127
 
typedef struct rpackets_data
128
 
{
129
 
  hrtime_t clock;
130
 
  VALUE_OVERLAY rpackets;
131
 
} RPACKETS_DATA;
132
 
 
133
 
typedef struct opackets_data
134
 
{
135
 
  hrtime_t clock;
136
 
  VALUE_OVERLAY opackets;
137
 
} OPACKETS_DATA;
138
 
 
139
 
typedef struct network_data
140
 
{
141
 
  struct network_data *next;
142
 
  char *name;
143
 
  RBYTES_DATA rb;
144
 
  OBYTES_DATA ob;
145
 
  RPACKETS_DATA rp;
146
 
  OPACKETS_DATA op;
147
 
} NETWORK_DATA;
148
 
 
149
 
static NETWORK_DATA *interfaces;
150
 
*/
151
 
 
152
 
/*
153
 
 * ADDED to /solaric/diskio.c
154
 
 *   
155
 
static DISK_DATA *disks;
156
 
 
157
 
static DISK_DATA *get_disk_data_record(const char *device)
158
 
{
159
 
  DISK_DATA *p;
160
 
 
161
 
  p = disks;
162
 
 
163
 
  while ((p) && (strcmp(p->name, device) != 0))
164
 
    p = p->next;  
165
 
 
166
 
  if (p == (DISK_DATA *) NULL)
167
 
    {
168
 
      p = (DISK_DATA *) calloc(1, sizeof(DISK_DATA));
169
 
 
170
 
      if (p)
171
 
        {
172
 
          p->name = strdup(device);
173
 
 
174
 
          if (p->name)
175
 
            {
176
 
              p->next = disks;
177
 
              
178
 
              disks = p;
179
 
            }
180
 
 
181
 
          else
182
 
            {
183
 
              free(p);
184
 
 
185
 
              p = NULL;
186
 
            }
187
 
        }
188
 
    }
189
 
 
190
 
  return p;
191
 
}
192
 
*/
193
 
 
194
 
/*
195
 
 * ADDED to /solaric/net.c
196
 
 *   
197
 
static NETWORK_DATA *get_net_data_record(const char *device)
198
 
{
199
 
  NETWORK_DATA *p;
200
 
 
201
 
  p = interfaces;
202
 
 
203
 
  while ((p) && (strcmp(p->name, device) != 0))
204
 
    p = p->next;  
205
 
 
206
 
  if (p == (NETWORK_DATA *) NULL)
207
 
    {
208
 
      p = (NETWORK_DATA *) calloc(1, sizeof(NETWORK_DATA));
209
 
 
210
 
      if (p)
211
 
        {
212
 
          p->name = strdup(device);
213
 
 
214
 
          if (p->name)
215
 
            {
216
 
              p->next = interfaces;
217
 
              
218
 
              interfaces = p;
219
 
            }
220
 
 
221
 
          else
222
 
            {
223
 
              free(p);
224
 
 
225
 
              p = NULL;
226
 
            }
227
 
        }
228
 
    }
229
 
 
230
 
  return p;
231
 
}
232
 
*/
233
 
 
234
 
/*
235
 
 * SKIPPED
236
 
 *
237
 
static int  PROCCNT(const char *cmd, const char *procname,double  *value, const char *msg, int mlen_max)
238
 
{
239
 
        DIR     *dir;
240
 
        struct  dirent *entries;
241
 
        struct  stat buf;
242
 
        char    filename[MAX_STRING_LEN];
243
 
 
244
 
        int     fd;
245
 
// In the correct procfs.h, the structure name is psinfo_t 
246
 
        psinfo_t psinfo;
247
 
 
248
 
        int     proccount=0;
249
 
 
250
 
        dir=opendir("/proc");
251
 
        if(NULL == dir)
252
 
        {
253
 
                return SYSINFO_RET_FAIL;
254
 
        }
255
 
 
256
 
        while((entries=readdir(dir))!=NULL)
257
 
        {
258
 
                strscpy(filename,"/proc/");     
259
 
                strncat(filename,entries->d_name,MAX_STRING_LEN);
260
 
                strncat(filename,"/psinfo",MAX_STRING_LEN);
261
 
 
262
 
                if(stat(filename,&buf)==0)
263
 
                {
264
 
                        fd = open (filename, O_RDONLY);
265
 
                        if (fd != -1)
266
 
                        {
267
 
                                if (read (fd, &psinfo, sizeof(psinfo)) == -1)
268
 
                                {
269
 
                                        closedir(dir);
270
 
                                        return SYSINFO_RET_FAIL;
271
 
                                }
272
 
                                else
273
 
                                {
274
 
                                        if(strcmp(procname,psinfo.pr_fname)==0)
275
 
                                        {
276
 
                                                proccount++;
277
 
                                        }
278
 
                                }
279
 
                                close (fd);
280
 
                        }
281
 
                        else
282
 
                        {
283
 
                                continue;
284
 
                        }
285
 
                }
286
 
        }
287
 
        closedir(dir);
288
 
        *value=(double)proccount;
289
 
        return  SYSINFO_RET_OK;
290
 
}
291
 
*/
292
 
 
293
 
/*
294
 
 * ADDED to /solaric/diskio.c
295
 
 *   
296
 
static int get_disk_kstat_record(const char *name,
297
 
                                 hrtime_t *crtime,
298
 
                                 hrtime_t *snaptime, 
299
 
                                 kstat_io_t *returned_data)
300
 
{
301
 
  int result = SYSINFO_RET_FAIL;
302
 
  kstat_ctl_t *kc;
303
 
 
304
 
  kc = kstat_open();
305
 
 
306
 
  if (kc)
307
 
    {
308
 
      kstat_t *kt;
309
 
 
310
 
      kt = kstat_lookup(kc, NULL, -1, (char *) name);
311
 
 
312
 
      if (kt)
313
 
        {
314
 
          if (    (kt->ks_type == KSTAT_TYPE_IO)
315
 
               && (kstat_read(kc, kt, returned_data) != -1)
316
 
             )
317
 
            {
318
 
               *crtime = kt->ks_crtime;
319
 
               *snaptime = kt->ks_snaptime;
320
 
               result = SYSINFO_RET_OK;
321
 
            }
322
 
        }
323
 
 
324
 
      kstat_close(kc);
325
 
    }
326
 
 
327
 
  return result;
328
 
}
329
 
 
330
 
static int DISKREADOPS(const char *cmd, const char *device,double  *value, const char *msg, int mlen_max)
331
 
{
332
 
  int result = SYSINFO_RET_FAIL;
333
 
  DISK_DATA *p;
334
 
 
335
 
  p = get_disk_data_record(device);
336
 
 
337
 
  if (p)
338
 
    {
339
 
       hrtime_t crtime, snaptime;
340
 
       kstat_io_t kio;
341
 
 
342
 
       result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
343
 
 
344
 
       if (result == SYSINFO_RET_OK)
345
 
          {
346
 
             int interval_seconds;
347
 
 
348
 
             interval_seconds = (snaptime - p->reads.clock) / 1000000000;
349
 
 
350
 
             if (interval_seconds > 0)
351
 
               *value = (kio.reads - p->reads.reads) / interval_seconds;
352
 
 
353
 
             else 
354
 
                *value = 0.0;
355
 
 
356
 
            p->reads.clock = snaptime;
357
 
 
358
 
            p->reads.reads = kio.reads;
359
 
          }
360
 
    }
361
 
 
362
 
  return result;
363
 
}
364
 
 
365
 
static int DISKREADBLOCKS(const char *cmd, const char *device,double  *value, const char *msg, int mlen_max)
366
 
{
367
 
  int result = SYSINFO_RET_FAIL;
368
 
  DISK_DATA *p;
369
 
 
370
 
  p = get_disk_data_record(device);
371
 
 
372
 
  if (p)
373
 
    {
374
 
       hrtime_t crtime, snaptime;
375
 
       kstat_io_t kio;
376
 
 
377
 
       result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
378
 
 
379
 
       if (result == SYSINFO_RET_OK)
380
 
          {
381
 
             int interval_seconds;
382
 
 
383
 
             interval_seconds = (snaptime - p->rblocks.clock) / 1000000000;
384
 
 
385
 
             if (interval_seconds > 0)
386
 
                *value = ((kio.nread - p->rblocks.nread) / 1024.0) / interval_seconds;
387
 
 
388
 
             else 
389
 
                *value = 0.0; 
390
 
 
391
 
            p->rblocks.clock = snaptime;
392
 
 
393
 
            p->rblocks.nread = kio.nread;
394
 
          }
395
 
    }
396
 
 
397
 
  return result;
398
 
}
399
 
 
400
 
static int DISKWRITEOPS(const char *cmd, const char *device,double  *value, const char *msg, int mlen_max)
401
 
{
402
 
  int result = SYSINFO_RET_FAIL;
403
 
  DISK_DATA *p;
404
 
 
405
 
  p = get_disk_data_record(device);
406
 
 
407
 
  if (p)
408
 
    {
409
 
       hrtime_t crtime, snaptime;
410
 
       kstat_io_t kio;
411
 
 
412
 
       result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
413
 
 
414
 
       if (result == SYSINFO_RET_OK)
415
 
          {
416
 
             int interval_seconds;
417
 
 
418
 
             interval_seconds = (snaptime - p->writes.clock) / 1000000000;
419
 
 
420
 
             if (interval_seconds > 0)
421
 
                *value = (kio.writes - p->writes.writes) / interval_seconds;
422
 
 
423
 
             else 
424
 
                *value = 0.0; 
425
 
 
426
 
            p->writes.clock = snaptime;
427
 
 
428
 
            p->writes.writes = kio.writes;
429
 
          }
430
 
    }
431
 
 
432
 
  return result;
433
 
}
434
 
 
435
 
static int DISKWRITEBLOCKS(const char *cmd, const char *device,double  *value, const char *msg, int mlen_max)
436
 
{
437
 
  int result = SYSINFO_RET_FAIL;
438
 
  DISK_DATA *p;
439
 
 
440
 
  p = get_disk_data_record(device);
441
 
 
442
 
  if (p)
443
 
    {
444
 
       hrtime_t crtime, snaptime;
445
 
       kstat_io_t kio;
446
 
 
447
 
       result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
448
 
 
449
 
       if (result == SYSINFO_RET_OK)
450
 
          {
451
 
             int interval_seconds;
452
 
 
453
 
             interval_seconds = (snaptime - p->wblocks.clock) / 1000000000;
454
 
 
455
 
             if (interval_seconds > 0)
456
 
                *value = ((kio.nwritten - p->wblocks.nwritten) / 1024.0) / interval_seconds;
457
 
 
458
 
             else 
459
 
                *value = 0.0; 
460
 
 
461
 
            p->wblocks.clock = snaptime;
462
 
 
463
 
            p->wblocks.nwritten = kio.nwritten;
464
 
          }
465
 
    }
466
 
 
467
 
  return result;
468
 
}
469
 
 
470
 
static int DISKBUSY(const char *cmd, const char *device, double  *value, const char *msg, int mlen_max)
471
 
{
472
 
  int result = SYSINFO_RET_FAIL;
473
 
  DISK_DATA *p;
474
 
 
475
 
  p = get_disk_data_record(device);
476
 
 
477
 
  if (p)
478
 
    {
479
 
       hrtime_t crtime, snaptime;
480
 
       kstat_io_t kio;
481
 
 
482
 
       result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
483
 
 
484
 
       if (result == SYSINFO_RET_OK)
485
 
          {
486
 
             if (snaptime > p->busy.clock)
487
 
                *value = ((kio.rtime - p->busy.rtime) * 100.0) / (snaptime - p->busy.clock);
488
 
 
489
 
             else 
490
 
               *value = 0.0;
491
 
 
492
 
             p->busy.clock = snaptime;
493
 
 
494
 
             p->busy.rtime = kio.rtime;
495
 
          }
496
 
    }
497
 
 
498
 
   return result;
499
 
}
500
 
 
501
 
static int DISKSVC(const char *cmd, const char *device, double  *value, const char *msg, int mlen_max)
502
 
{
503
 
  int result = SYSINFO_RET_FAIL;
504
 
  DISK_DATA *p;
505
 
 
506
 
  p = get_disk_data_record(device);
507
 
 
508
 
  if (p)
509
 
    {
510
 
       hrtime_t crtime, snaptime;
511
 
       kstat_io_t kio;
512
 
 
513
 
       result = get_disk_kstat_record(device, &crtime, &snaptime, &kio);
514
 
 
515
 
       if (result == SYSINFO_RET_OK)
516
 
          {
517
 
             unsigned long ios;
518
 
 
519
 
             ios = (kio.reads - p->svc.reads) + (kio.writes - p->svc.writes);
520
 
 
521
 
             if (ios > 0)
522
 
                *value = ((kio.rtime - p->svc.rtime)/ios)/1000000.0;
523
 
 
524
 
             else
525
 
                *value = 0.0;
526
 
 
527
 
             p->svc.writes = kio.writes;
528
 
             p->svc.reads = kio.reads;
529
 
             p->svc.rtime = kio.rtime;
530
 
          }
531
 
    }
532
 
 
533
 
   return result;
534
 
}
535
 
*/
536
 
 
537
 
/*
538
 
 * ADDED to /solaric/cpu.c
539
 
 *   
540
 
static int get_cpu_data(zbx_uint64_t *idle,
541
 
                        zbx_uint64_t *system,
542
 
                        zbx_uint64_t *user,
543
 
                        zbx_uint64_t *iowait)
544
 
{
545
 
  kstat_ctl_t *kc;
546
 
  int cpu_count = 0;
547
 
 
548
 
  *idle =
549
 
     *system =
550
 
     *user =
551
 
     *iowait = 0LL;
552
 
 
553
 
  kc = kstat_open();
554
 
 
555
 
  if (kc)
556
 
    {
557
 
      kstat_t *k = kc->kc_chain;
558
 
 
559
 
      while (k)
560
 
        {
561
 
          if (     (strncmp(k->ks_name, "cpu_stat", 8) == 0)
562
 
                && (kstat_read(kc, k, NULL) != -1)
563
 
             )
564
 
            {
565
 
               cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
566
 
 
567
 
               *idle +=  cpu->cpu_sysinfo.cpu[CPU_IDLE];
568
 
               *system +=  cpu->cpu_sysinfo.cpu[CPU_KERNEL];
569
 
               *iowait +=  cpu->cpu_sysinfo.cpu[CPU_WAIT];
570
 
               *user +=  cpu->cpu_sysinfo.cpu[CPU_USER];
571
 
 
572
 
               cpu_count += 1;
573
 
            }
574
 
 
575
 
          k = k->ks_next;
576
 
        }
577
 
 
578
 
      kstat_close(kc);
579
 
    }
580
 
 
581
 
  return cpu_count;
582
 
}
583
 
 
584
 
static int CPUIDLE(const char *cmd, const char *param, double  *value, const char *msg, int mlen_max)
585
 
{
586
 
   static zbx_uint64_t idle[2];
587
 
   static zbx_uint64_t system[2];
588
 
   static zbx_uint64_t user[2];
589
 
   static zbx_uint64_t iowait[2];
590
 
 
591
 
   int result = SYSINFO_RET_FAIL;
592
 
 
593
 
   if (get_cpu_data(&idle[1], &system[1], &user[1], &iowait[1]))
594
 
      {
595
 
         zbx_uint64_t interval_size;
596
 
 
597
 
         interval_size =    (idle[1] - idle[0])
598
 
                          + (system[1] - system[0])
599
 
                          + (user[1] - user[0])
600
 
                          + (iowait[1] - iowait[0]);
601
 
 
602
 
         if (interval_size > 0)
603
 
            {
604
 
               *value = ((idle[1] - idle[0]) * 100.0)/interval_size;
605
 
 
606
 
               idle[0] = idle[1];
607
 
               system[0] = system[1];
608
 
               user[0] = user[1];
609
 
               iowait[0] = iowait[1];
610
 
 
611
 
               result = SYSINFO_RET_OK;
612
 
            }
613
 
      }
614
 
 
615
 
   return result;
616
 
}
617
 
 
618
 
static int CPUUSER(const char *cmd, const char *param,double  *value, const char *msg, int mlen_max)
619
 
{
620
 
   static unsigned long long idle[2];
621
 
   static unsigned long long system[2];
622
 
   static unsigned long long user[2];
623
 
   static unsigned long long iowait[2];
624
 
 
625
 
   int result = SYSINFO_RET_FAIL;
626
 
 
627
 
   if (get_cpu_data(&idle[1], &system[1], &user[1], &iowait[1]))
628
 
      {
629
 
         unsigned interval_size;
630
 
 
631
 
         interval_size =    (idle[1] - idle[0])
632
 
                          + (system[1] - system[0])
633
 
                          + (user[1] - user[0])
634
 
                          + (iowait[1] - iowait[0]);
635
 
 
636
 
         if (interval_size > 0)
637
 
            {
638
 
               *value = ((user[1] - user[0]) * 100.0)/interval_size;
639
 
 
640
 
               idle[0] = idle[1];
641
 
               system[0] = system[1];
642
 
               user[0] = user[1];
643
 
               iowait[0] = iowait[1];
644
 
 
645
 
               result = SYSINFO_RET_OK;
646
 
            }
647
 
      }
648
 
 
649
 
   return result;
650
 
}
651
 
 
652
 
static int CPUSYSTEM(const char *cmd, const char *param,double  *value, const char *msg, int mlen_max)
653
 
{
654
 
   static unsigned long long idle[2];
655
 
   static unsigned long long system[2];
656
 
   static unsigned long long user[2];
657
 
   static unsigned long long iowait[2];
658
 
 
659
 
   int result = SYSINFO_RET_FAIL;
660
 
 
661
 
   if (get_cpu_data(&idle[1], &system[1], &user[1], &iowait[1]))
662
 
      {
663
 
         unsigned interval_size;
664
 
 
665
 
         interval_size =    (idle[1] - idle[0])
666
 
                          + (system[1] - system[0])
667
 
                          + (user[1] - user[0])
668
 
                          + (iowait[1] - iowait[0]);
669
 
 
670
 
         if (interval_size > 0)
671
 
            {
672
 
               *value = ((system[1] - system[0]) * 100.0)/interval_size;
673
 
 
674
 
               idle[0] = idle[1];
675
 
               system[0] = system[1];
676
 
               user[0] = user[1];
677
 
               iowait[0] = iowait[1];
678
 
 
679
 
               result = SYSINFO_RET_OK;
680
 
            }
681
 
      }
682
 
 
683
 
   return result;
684
 
}
685
 
 
686
 
static int CPUIOWAIT(const char *cmd, const char *param,double  *value, const char *msg, int mlen_max)
687
 
{
688
 
   static unsigned long long idle[2];
689
 
   static unsigned long long system[2];
690
 
   static unsigned long long user[2];
691
 
   static unsigned long long iowait[2];
692
 
 
693
 
   int result = SYSINFO_RET_FAIL;
694
 
 
695
 
   if (get_cpu_data(&idle[1], &system[1], &user[1], &iowait[1]))
696
 
      {
697
 
         unsigned interval_size;
698
 
 
699
 
         interval_size =    (idle[1] - idle[0])
700
 
                          + (system[1] - system[0])
701
 
                          + (user[1] - user[0])
702
 
                          + (iowait[1] - iowait[0]);
703
 
 
704
 
         if (interval_size > 0)
705
 
            {
706
 
               *value = ((iowait[1] - iowait[0]) * 100.0)/interval_size;
707
 
 
708
 
               idle[0] = idle[1];
709
 
               system[0] = system[1];
710
 
               user[0] = user[1];
711
 
               iowait[0] = iowait[1];
712
 
 
713
 
               result = SYSINFO_RET_OK;
714
 
            }
715
 
      }
716
 
 
717
 
   return result;
718
 
}
719
 
*/
720
 
 
721
 
/*
722
 
 * ADDED to /solaric/net.c
723
 
 *   
724
 
static int get_named_field(const char *name, 
725
 
                           const char *field,
726
 
                           kstat_named_t *returned_data,
727
 
                           hrtime_t *snaptime)
728
 
   {
729
 
      int result = SYSINFO_RET_FAIL;
730
 
      kstat_ctl_t   *kc;
731
 
 
732
 
      kc = kstat_open();
733
 
 
734
 
        if (kc)
735
 
          {
736
 
             kstat_t       *kp;
737
 
 
738
 
             kp = kstat_lookup(kc, NULL, -1, (char *) name);
739
 
 
740
 
             if ((kp) && (kstat_read(kc, kp, 0) != -1))
741
 
               {
742
 
                  kstat_named_t *kn;
743
 
 
744
 
                  kn = (kstat_named_t*) kstat_data_lookup(kp, (char *) field);
745
 
 
746
 
                  *snaptime = kp->ks_snaptime;
747
 
 
748
 
                  *returned_data = *kn;
749
 
 
750
 
                  result = SYSINFO_RET_OK;
751
 
               }
752
 
 
753
 
              kstat_close(kc);
754
 
          }
755
 
 
756
 
        return result;
757
 
   }
758
 
 
759
 
 
760
 
static int NETLOADIN(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
761
 
{
762
 
  int result = SYSINFO_RET_FAIL;
763
 
  NETWORK_DATA *p;
764
 
 
765
 
  p = get_net_data_record(parameter);
766
 
 
767
 
  if (p)
768
 
    {
769
 
       kstat_named_t kn;
770
 
       hrtime_t snaptime;
771
 
 
772
 
       result = get_named_field(parameter, "rbytes64", &kn, &snaptime);
773
 
 
774
 
       if (result == SYSINFO_RET_OK)
775
 
         {
776
 
           int interval_seconds;
777
 
 
778
 
           interval_seconds = (snaptime - p->rb.clock) / 1000000000;
779
 
 
780
 
           *value = (double) (kn.value.ui64 - p->rb.rbytes.u.ui64) / interval_seconds;
781
 
 
782
 
           p->rb.rbytes.u.ui64 = kn.value.ui64;
783
 
 
784
 
           p->rb.clock = snaptime;
785
 
         }
786
 
 
787
 
       else
788
 
         {
789
 
             result = get_named_field(parameter, "rbytes", &kn, &snaptime);
790
 
 
791
 
             if (result == SYSINFO_RET_OK)
792
 
                {
793
 
                   int interval_seconds;
794
 
 
795
 
                   interval_seconds = (snaptime - p->rb.clock) / 1000000000;
796
 
 
797
 
                   *value = (double) (kn.value.ui32 - p->rb.rbytes.u.ui32) / interval_seconds;
798
 
 
799
 
                   p->rb.rbytes.u.ui32 = kn.value.ui32;
800
 
 
801
 
                   p->rb.clock = snaptime;
802
 
                }
803
 
         }
804
 
    }
805
 
 
806
 
  return result;
807
 
}
808
 
 
809
 
static int NETPACKETSIN(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
810
 
{
811
 
  int result = SYSINFO_RET_FAIL;
812
 
  NETWORK_DATA *p;
813
 
 
814
 
  p = get_net_data_record(parameter);
815
 
 
816
 
  if (p)
817
 
    {
818
 
       kstat_named_t kn;
819
 
       hrtime_t snaptime;
820
 
 
821
 
       result = get_named_field(parameter, "ipackets64", &kn, &snaptime);
822
 
 
823
 
       if (result == SYSINFO_RET_OK)
824
 
         {
825
 
           int interval_seconds;
826
 
 
827
 
           interval_seconds = (snaptime - p->rp.clock) / 1000000000;
828
 
 
829
 
           *value = (double) (kn.value.ui64 - p->rp.rpackets.u.ui64) / interval_seconds;
830
 
 
831
 
           p->rp.rpackets.u.ui64 = kn.value.ui64;
832
 
 
833
 
           p->rp.clock = snaptime;
834
 
         }
835
 
 
836
 
       else
837
 
         {
838
 
             result = get_named_field(parameter, "ipacket", &kn, &snaptime);
839
 
 
840
 
             if (result == SYSINFO_RET_OK)
841
 
                {
842
 
                   int interval_seconds;
843
 
 
844
 
                   interval_seconds = (snaptime - p->rp.clock) / 1000000000;
845
 
 
846
 
                   *value = (double) (kn.value.ui32 - p->rp.rpackets.u.ui32) / interval_seconds;
847
 
 
848
 
                   p->rp.rpackets.u.ui32 = kn.value.ui32;
849
 
 
850
 
                   p->rp.clock = snaptime;
851
 
                }
852
 
         }
853
 
    }
854
 
 
855
 
  return result;
856
 
}
857
 
 
858
 
static int NETERRSIN(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
859
 
{
860
 
  int result;
861
 
  kstat_named_t kn;
862
 
  hrtime_t snaptime;
863
 
  
864
 
  result = get_named_field(parameter, "ierrors", &kn, &snaptime);
865
 
 
866
 
  if (result == SYSINFO_RET_OK)
867
 
    *value = (double) kn.value.ui32;
868
 
 
869
 
  return result;
870
 
}
871
 
 
872
 
static int NETLOADOUT(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
873
 
{
874
 
  int result = SYSINFO_RET_FAIL;
875
 
  NETWORK_DATA *p;
876
 
 
877
 
  p = get_net_data_record(parameter);
878
 
 
879
 
  if (p)
880
 
    {
881
 
       kstat_named_t kn;
882
 
       hrtime_t snaptime;
883
 
 
884
 
       result = get_named_field(parameter, "obytes64", &kn, &snaptime);
885
 
 
886
 
       if (result == SYSINFO_RET_OK)
887
 
         {
888
 
           int interval_seconds;
889
 
 
890
 
           interval_seconds = (snaptime - p->ob.clock) / 1000000000;
891
 
 
892
 
           *value = (double) (kn.value.ui64 - p->ob.obytes.u.ui64) / interval_seconds;
893
 
 
894
 
           p->ob.obytes.u.ui64 = kn.value.ui64;
895
 
 
896
 
           p->ob.clock = snaptime;
897
 
         }
898
 
 
899
 
       else
900
 
         {
901
 
             result = get_named_field(parameter, "obytes", &kn, &snaptime);
902
 
 
903
 
             if (result == SYSINFO_RET_OK)
904
 
                {
905
 
                   int interval_seconds;
906
 
 
907
 
                   interval_seconds = (snaptime - p->ob.clock) / 1000000000;
908
 
 
909
 
                   *value = (double) (kn.value.ui32 - p->ob.obytes.u.ui32) / interval_seconds;
910
 
 
911
 
                   p->ob.obytes.u.ui32 = kn.value.ui32;
912
 
 
913
 
                   p->ob.clock = snaptime;
914
 
                }
915
 
         }
916
 
    }
917
 
 
918
 
  return result;
919
 
}
920
 
 
921
 
static int NETPACKETSOUT(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
922
 
{
923
 
  int result = SYSINFO_RET_FAIL;
924
 
  NETWORK_DATA *p;
925
 
 
926
 
  p = get_net_data_record(parameter);
927
 
 
928
 
  if (p)
929
 
    {
930
 
       kstat_named_t kn;
931
 
       hrtime_t snaptime;
932
 
 
933
 
       result = get_named_field(parameter, "opackets64", &kn, &snaptime);
934
 
 
935
 
       if (result == SYSINFO_RET_OK)
936
 
         {
937
 
           int interval_seconds;
938
 
 
939
 
           interval_seconds = (snaptime - p->op.clock) / 1000000000;
940
 
 
941
 
           *value = (double) (kn.value.ui64 - p->op.opackets.u.ui64) / interval_seconds;
942
 
 
943
 
           p->op.opackets.u.ui64 = kn.value.ui64;
944
 
 
945
 
           p->op.clock = snaptime;
946
 
         }
947
 
 
948
 
       else
949
 
         {
950
 
             result = get_named_field(parameter, "opacket", &kn, &snaptime);
951
 
 
952
 
             if (result == SYSINFO_RET_OK)
953
 
                {
954
 
                   int interval_seconds;
955
 
 
956
 
                   interval_seconds = (snaptime - p->op.clock) / 1000000000;
957
 
 
958
 
                   *value = (double) (kn.value.ui32 - p->op.opackets.u.ui32) / interval_seconds;
959
 
 
960
 
                   p->op.opackets.u.ui32 = kn.value.ui32;
961
 
 
962
 
                   p->op.clock = snaptime;
963
 
                }
964
 
         }
965
 
    }
966
 
 
967
 
  return result;
968
 
}
969
 
 
970
 
static int NETERRSOUT(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
971
 
{
972
 
  int result;
973
 
  kstat_named_t kn;
974
 
  hrtime_t snaptime;
975
 
  
976
 
  result = get_named_field(parameter, "oerrors", &kn, &snaptime);
977
 
 
978
 
  if (result == SYSINFO_RET_OK)
979
 
    *value = (double) kn.value.ui32;
980
 
 
981
 
  return result;
982
 
}
983
 
 
984
 
static int NETCOLLOUT(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
985
 
{
986
 
  int result;
987
 
  kstat_named_t kn;
988
 
  hrtime_t snaptime;
989
 
  
990
 
  result = get_named_field(parameter, "collisions", &kn, &snaptime);
991
 
 
992
 
  if (result == SYSINFO_RET_OK)
993
 
    *value = (double) kn.value.ui32;
994
 
 
995
 
  return result;
996
 
}
997
 
*/
998
 
 
999
 
/*
1000
 
 * ADDED
1001
 
 * 
1002
 
int     INODEFREE(const char *cmd, const char *mountPoint,double  *value, const char *msg, int mlen_max)
1003
 
{
1004
 
        struct statvfs   s;
1005
 
 
1006
 
        if ( statvfs( (char *)mountPoint, &s) != 0 )
1007
 
        {
1008
 
                return  SYSINFO_RET_FAIL;
1009
 
        }
1010
 
 
1011
 
        *value=s.f_favail;
1012
 
        return SYSINFO_RET_OK;
1013
 
}
1014
 
*/
1015
 
 
1016
 
/*
1017
 
 * ADDED
1018
 
 * 
1019
 
int     INODETOTAL(const char *cmd, const char *mountPoint,double  *value, const char *msg, int mlen_max)
1020
 
{
1021
 
        struct statvfs   s;
1022
 
 
1023
 
        if ( statvfs( (char *)mountPoint, &s) != 0 )
1024
 
        {
1025
 
                return  SYSINFO_RET_FAIL;
1026
 
        }
1027
 
 
1028
 
        *value=s.f_files;
1029
 
        return SYSINFO_RET_OK;
1030
 
}
1031
 
*/
1032
 
 
1033
 
/*
1034
 
 * ADDED
1035
 
 * 
1036
 
int     DISKFREE(const char *cmd, const char *mountPoint,double  *value, const char *msg, int mlen_max)
1037
 
{
1038
 
        struct statvfs   s;
1039
 
 
1040
 
        if ( statvfs( (char *)mountPoint, &s) != 0 )
1041
 
        {
1042
 
                return  SYSINFO_RET_FAIL;
1043
 
        }
1044
 
 
1045
 
//      return  s.f_bavail * (s.f_bsize / 1024.0);
1046
 
        *value=s.f_bavail * (s.f_frsize / 1024.0);
1047
 
        return SYSINFO_RET_OK;
1048
 
}
1049
 
*/
1050
 
 
1051
 
/*
1052
 
 * ADDED
1053
 
 * 
1054
 
int     DISKUSED(const char *cmd, const char *mountPoint,double  *value, const char *msg, int mlen_max)
1055
 
{
1056
 
        struct statvfs   s;
1057
 
 
1058
 
        if ( statvfs( (char *)mountPoint, &s) != 0 )
1059
 
        {
1060
 
                return  SYSINFO_RET_FAIL;
1061
 
        }
1062
 
 
1063
 
//      return  (s.f_blocks-s.f_bavail) * (s.f_bsize / 1024.0);
1064
 
        *value=(s.f_blocks-s.f_bavail) * (s.f_frsize / 1024.0);
1065
 
        return SYSINFO_RET_OK;
1066
 
}
1067
 
*/
1068
 
 
1069
 
/*
1070
 
 * ADDED
1071
 
 * 
1072
 
int     DISKTOTAL(const char *cmd, const char *mountPoint,double  *value, const char *msg, int mlen_max)
1073
 
{
1074
 
        struct statvfs   s;
1075
 
 
1076
 
        if ( statvfs( (char *)mountPoint, &s) != 0 )
1077
 
        {
1078
 
                return  SYSINFO_RET_FAIL;
1079
 
        }
1080
 
 
1081
 
//      return  s.f_blocks * (s.f_bsize / 1024.0);
1082
 
        *value= s.f_blocks * (s.f_frsize / 1024.0);
1083
 
        return SYSINFO_RET_OK;
1084
 
}
1085
 
*/
1086
 
 
1087
 
/*
1088
 
 * ADDED
1089
 
 * 
1090
 
static int      TOTALMEM(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1091
 
{
1092
 
        *value=(double)sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE);
1093
 
        return SYSINFO_RET_OK;
1094
 
}
1095
 
*/
1096
 
 
1097
 
/*
1098
 
 * ADDED
1099
 
 * 
1100
 
static int      FREEMEM(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1101
 
{
1102
 
        *value=(double)sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE);
1103
 
        return SYSINFO_RET_OK;
1104
 
}
1105
 
*/
1106
 
 
1107
 
/*
1108
 
 * ADDED
1109
 
 * 
1110
 
static int KERNEL_MAXPROC(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1111
 
{
1112
 
  int result = SYSINFO_RET_FAIL;
1113
 
  kstat_ctl_t *kc;
1114
 
 
1115
 
  kc = kstat_open();
1116
 
 
1117
 
  if (kc)
1118
 
    {
1119
 
      kstat_t *kt;
1120
 
 
1121
 
      kt = kstat_lookup(kc, "unix", 0, "var");
1122
 
 
1123
 
      if (kt)
1124
 
        {
1125
 
          if (    (kt->ks_type == KSTAT_TYPE_RAW)
1126
 
               && (kstat_read(kc, kt, NULL) != -1)
1127
 
             )
1128
 
            {
1129
 
               struct var *v = (struct var *) kt->ks_data;
1130
 
 
1131
 
               *value = v->v_proc;
1132
 
               result = SYSINFO_RET_OK;
1133
 
            }
1134
 
        }
1135
 
 
1136
 
      kstat_close(kc);
1137
 
    }
1138
 
 
1139
 
  return result;
1140
 
}
1141
 
*/
1142
 
 
1143
 
/*
1144
 
 * ADDED
1145
 
 * 
1146
 
static int UPTIME(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1147
 
   {
1148
 
      int result = SYSINFO_RET_FAIL;
1149
 
      kstat_ctl_t   *kc;
1150
 
 
1151
 
      kc = kstat_open();
1152
 
 
1153
 
        if (kc)
1154
 
          {
1155
 
             kstat_t       *kp;
1156
 
 
1157
 
             kp = kstat_lookup(kc, "unix", 0, "system_misc");
1158
 
 
1159
 
             if ((kp) && (kstat_read(kc, kp, 0) != -1))
1160
 
               {
1161
 
                  time_t now;
1162
 
                  kstat_named_t *kn;
1163
 
 
1164
 
                  kn = (kstat_named_t*) kstat_data_lookup(kp, "boot_time");
1165
 
 
1166
 
                  time(&now);
1167
 
 
1168
 
                  *value=difftime(now, (time_t) kn->value.ul);
1169
 
                  
1170
 
                  result = SYSINFO_RET_OK;
1171
 
               }
1172
 
 
1173
 
              kstat_close(kc);
1174
 
          }
1175
 
 
1176
 
        return result;
1177
 
   }
1178
 
*/
1179
 
 
1180
 
/*
1181
 
 * ADDED
1182
 
 * 
1183
 
static int      PROCLOAD(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1184
 
{
1185
 
        double  load[3];
1186
 
 
1187
 
        if(getloadavg(load, 3))
1188
 
        {
1189
 
                *value=load[0];
1190
 
                return SYSINFO_RET_OK;
1191
 
        }
1192
 
        else
1193
 
        {
1194
 
                return SYSINFO_RET_FAIL;        
1195
 
        }
1196
 
}
1197
 
*/
1198
 
 
1199
 
/*
1200
 
 * ADDED
1201
 
 * 
1202
 
static int      PROCLOAD5(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1203
 
{
1204
 
        double  load[3];
1205
 
 
1206
 
        if(getloadavg(load, 3))
1207
 
        {
1208
 
                *value=load[1];
1209
 
                return SYSINFO_RET_OK;
1210
 
        }
1211
 
        else
1212
 
        {
1213
 
                return SYSINFO_RET_FAIL;        
1214
 
        }
1215
 
}
1216
 
*/
1217
 
 
1218
 
/*
1219
 
 * ADDED
1220
 
 * 
1221
 
static int      PROCLOAD15(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1222
 
{
1223
 
        double  load[3];
1224
 
 
1225
 
        if(getloadavg(load, 3))
1226
 
        {
1227
 
                *value=load[2]; 
1228
 
                return SYSINFO_RET_OK;
1229
 
        }
1230
 
        else
1231
 
        {
1232
 
                return SYSINFO_RET_FAIL;        
1233
 
        }
1234
 
}
1235
 
*/
1236
 
 
1237
 
/*
1238
 
 * ADDED
1239
 
 * 
1240
 
static int get_swap_data(zbx_uint64_t *resv,
1241
 
                         zbx_uint64_t *avail,
1242
 
                         zbx_uint64_t *free)
1243
 
{
1244
 
  int result = SYSINFO_RET_FAIL;
1245
 
  kstat_ctl_t *kc;
1246
 
 
1247
 
  kc = kstat_open();
1248
 
 
1249
 
  if (kc)
1250
 
    {
1251
 
      kstat_t *ksp;
1252
 
 
1253
 
      ksp = kstat_lookup(kc, "unix", 0, "vminfo");
1254
 
 
1255
 
      if ((ksp) && (kstat_read(kc, ksp, NULL) != -1))
1256
 
        {
1257
 
           vminfo_t *vm;
1258
 
           int i;
1259
 
           zbx_uint64_t oresv, ofree, oavail;
1260
 
 
1261
 
           vm = (vminfo_t *) ksp->ks_data;
1262
 
 
1263
 
           oresv = vm->swap_resv;
1264
 
           ofree = vm->swap_free;
1265
 
           oavail = vm->swap_avail;
1266
 
 
1267
 
           for (i = 0; i < 12; i++)
1268
 
              {
1269
 
                 usleep(100000);
1270
 
 
1271
 
                 if (kstat_read(kc, ksp, NULL) != -1)
1272
 
                   {
1273
 
                      vm = (vminfo_t *) ksp->ks_data;
1274
 
 
1275
 
                      if ((oresv != vm->swap_resv) || (ofree != vm->swap_free) || (oavail != vm->swap_avail))
1276
 
                         {  
1277
 
                            *resv = vm->swap_resv - oresv;
1278
 
                            *free = vm->swap_free - ofree;
1279
 
                            *avail = vm->swap_avail - oavail;
1280
 
                          
1281
 
                             result = SYSINFO_RET_OK;
1282
 
 
1283
 
                             break;
1284
 
                         }
1285
 
                   }
1286
 
              }
1287
 
        }
1288
 
 
1289
 
      kstat_close(kc);
1290
 
    }
1291
 
 
1292
 
  return result;
1293
 
}
1294
 
 
1295
 
static int SWAPFREE(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1296
 
{
1297
 
  int result;
1298
 
  zbx_uint64_t resv, avail, free;
1299
 
 
1300
 
  result = get_swap_data(&resv, &avail, &free);
1301
 
 
1302
 
  if (result == SYSINFO_RET_OK)
1303
 
    {
1304
 
      *value = free * sysconf(_SC_PAGESIZE);
1305
 
    }
1306
 
 
1307
 
   return result;
1308
 
}
1309
 
 
1310
 
int SWAPTOTAL(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1311
 
{
1312
 
  int result;
1313
 
  zbx_uint64_t resv, avail, free;
1314
 
 
1315
 
  result = get_swap_data(&resv, &avail, &free);
1316
 
 
1317
 
  if (result == SYSINFO_RET_OK)
1318
 
    {
1319
 
      zbx_uint64_t swap_total_bytes;
1320
 
 
1321
 
      swap_total_bytes = (resv + avail) * sysconf(_SC_PAGESIZE);
1322
 
      *value = (double) swap_total_bytes;
1323
 
    }
1324
 
 
1325
 
   return result;
1326
 
}
1327
 
*/
1328
 
 
1329
 
/*
1330
 
 * ADDED
1331
 
 * 
1332
 
static int SWAPIN(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1333
 
{
1334
 
  kstat_ctl_t *kc;
1335
 
  int cpu_count = 0;
1336
 
 
1337
 
  *value = 0.0;
1338
 
 
1339
 
  kc = kstat_open();
1340
 
 
1341
 
  if (kc)
1342
 
    {
1343
 
      kstat_t *k = kc->kc_chain;
1344
 
      
1345
 
      while (k)
1346
 
        {
1347
 
          if (     (strncmp(k->ks_name, "cpu_stat", 8) == 0)
1348
 
                && (kstat_read(kc, k, NULL) != -1)
1349
 
             )
1350
 
            {
1351
 
               cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
1352
 
 
1353
 
               *value +=  cpu->cpu_vminfo.swapin;
1354
 
 
1355
 
               cpu_count += 1;
1356
 
            }
1357
 
 
1358
 
          k = k->ks_next;
1359
 
        }
1360
 
 
1361
 
      kstat_close(kc);
1362
 
    }
1363
 
 
1364
 
  return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
1365
 
}
1366
 
*/
1367
 
 
1368
 
/*
1369
 
 * ADDED
1370
 
 * 
1371
 
static int SWAPOUT(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1372
 
{
1373
 
  kstat_ctl_t *kc;
1374
 
  int cpu_count = 0;
1375
 
 
1376
 
  *value = 0.0;
1377
 
 
1378
 
  kc = kstat_open();
1379
 
 
1380
 
  if (kc)
1381
 
    {
1382
 
      kstat_t *k = kc->kc_chain;
1383
 
      
1384
 
      while (k)
1385
 
        {
1386
 
          if (     (strncmp(k->ks_name, "cpu_stat", 8) == 0)
1387
 
                && (kstat_read(kc, k, NULL) != -1)
1388
 
             )
1389
 
            {
1390
 
               cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
1391
 
 
1392
 
               *value +=  cpu->cpu_vminfo.swapout;
1393
 
 
1394
 
               cpu_count += 1;
1395
 
            }
1396
 
 
1397
 
          k = k->ks_next;
1398
 
        }
1399
 
 
1400
 
      kstat_close(kc);
1401
 
    }
1402
 
 
1403
 
  return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
1404
 
}
1405
 
*/
1406
 
 
1407
 
/*
1408
 
 * SKIPPED
1409
 
 *
1410
 
static int PROCCOUNT(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1411
 
   {
1412
 
      int result = SYSINFO_RET_FAIL;
1413
 
      kstat_ctl_t *kc;
1414
 
 
1415
 
      kc = kstat_open();
1416
 
 
1417
 
        if (kc)
1418
 
          {
1419
 
             kstat_t   *kp;
1420
 
 
1421
 
             kp = kstat_lookup(kc, "unix", 0, "system_misc");
1422
 
 
1423
 
             if ((kp) && (kstat_read(kc, kp, 0) != -1))
1424
 
               {
1425
 
                  kstat_named_t *kn;
1426
 
 
1427
 
                  kn = (kstat_named_t*) kstat_data_lookup(kp, "nproc");
1428
 
 
1429
 
                  *value = (double) kn->value.ul;
1430
 
                  
1431
 
                  result = SYSINFO_RET_OK;
1432
 
               }
1433
 
 
1434
 
              kstat_close(kc);
1435
 
          }
1436
 
 
1437
 
        return result;
1438
 
   }
1439
 
*/
1440
 
 
1441
 
/*
1442
 
 * ADDED
1443
 
 * 
1444
 
static int PROCRUNNING(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1445
 
{
1446
 
        DIR     *dir;
1447
 
        struct  dirent *entries;
1448
 
        struct  stat buf;
1449
 
        char    filename[MAX_STRING_LEN];
1450
 
 
1451
 
        int     fd;
1452
 
// In the correct procfs.h, the structure name is psinfo_t
1453
 
 
1454
 
        psinfo_t psinfo;
1455
 
 
1456
 
        int     proccount=0;
1457
 
 
1458
 
        dir=opendir("/proc");
1459
 
        if(NULL == dir)
1460
 
        {
1461
 
                return SYSINFO_RET_FAIL;
1462
 
        }
1463
 
 
1464
 
        while((entries=readdir(dir))!=NULL)
1465
 
        {
1466
 
                strscpy(filename,"/proc/");     
1467
 
                strncat(filename,entries->d_name,MAX_STRING_LEN);
1468
 
                strncat(filename,"/psinfo",MAX_STRING_LEN);
1469
 
 
1470
 
                if(stat(filename,&buf)==0)
1471
 
                {
1472
 
                        fd = open (filename, O_RDONLY);
1473
 
                        if(fd != -1)
1474
 
                        {
1475
 
                                if(read (fd, &psinfo, sizeof(psinfo)) == -1)
1476
 
                                {
1477
 
                                        closedir(dir);
1478
 
                                        return SYSINFO_RET_FAIL;
1479
 
                                }
1480
 
                                else
1481
 
                                {
1482
 
                                        if(psinfo.pr_lwp.pr_state == SRUN)
1483
 
                                        {
1484
 
                                                proccount++;
1485
 
                                        }
1486
 
                                }
1487
 
                                close (fd);
1488
 
                        }
1489
 
                        else
1490
 
                        {
1491
 
                                continue;
1492
 
                        }
1493
 
                }
1494
 
        }
1495
 
        closedir(dir);
1496
 
        *value=(double)proccount;
1497
 
        return  SYSINFO_RET_OK;
1498
 
}
1499
 
*/
1500
 
 
1501
 
/*
1502
 
 * ADDED
1503
 
 * 
1504
 
static int CSWITCHES(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1505
 
{
1506
 
  kstat_ctl_t *kc;
1507
 
  int cpu_count = 0;
1508
 
 
1509
 
  *value = 0.0;
1510
 
 
1511
 
  kc = kstat_open();
1512
 
 
1513
 
  if (kc)
1514
 
    {
1515
 
      kstat_t *k = kc->kc_chain;
1516
 
      
1517
 
      while (k)
1518
 
        {
1519
 
          if (     (strncmp(k->ks_name, "cpu_stat", 8) == 0)
1520
 
                && (kstat_read(kc, k, NULL) != -1)
1521
 
             )
1522
 
            {
1523
 
               cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
1524
 
 
1525
 
               *value +=  cpu->cpu_sysinfo.pswitch;
1526
 
 
1527
 
               cpu_count += 1;
1528
 
            }
1529
 
 
1530
 
          k = k->ks_next;
1531
 
        }
1532
 
 
1533
 
      kstat_close(kc);
1534
 
    }
1535
 
 
1536
 
  return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
1537
 
}
1538
 
*/
1539
 
 
1540
 
/* 
1541
 
 * ADDED to /solaris/net.c
1542
 
 * 
1543
 
static int TCP_LISTEN(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1544
 
{
1545
 
  char command[MAX_STRING_LEN];
1546
 
  
1547
 
  memset(command, '\0', sizeof command);
1548
 
 
1549
 
  snprintf(command, sizeof command-1, "netstat -an | grep '*.%s' | wc -l", parameter);
1550
 
   
1551
 
  return EXECUTE(NULL, command, value, msg, mlen_max);
1552
 
}
1553
 
*/
1554
 
 
1555
 
/* 
1556
 
 * ADDED
1557
 
 * 
1558
 
static int INTERRUPTS(const char *cmd, const char *parameter,double  *value, const char *msg, int mlen_max)
1559
 
{
1560
 
  kstat_ctl_t *kc;
1561
 
  int cpu_count = 0;
1562
 
 
1563
 
  *value = 0.0;
1564
 
 
1565
 
  kc = kstat_open();
1566
 
 
1567
 
  if (kc)
1568
 
    {
1569
 
      kstat_t *k = kc->kc_chain;
1570
 
      
1571
 
      while (k)
1572
 
        {
1573
 
          if (     (strncmp(k->ks_name, "cpu_stat", 8) == 0)
1574
 
                && (kstat_read(kc, k, NULL) != -1)
1575
 
             )
1576
 
            {
1577
 
               cpu_stat_t *cpu = (cpu_stat_t *) k->ks_data;
1578
 
 
1579
 
               *value +=  cpu->cpu_sysinfo.intr;
1580
 
 
1581
 
               cpu_count += 1;
1582
 
            }
1583
 
 
1584
 
          k = k->ks_next;
1585
 
        }
1586
 
 
1587
 
      kstat_close(kc);
1588
 
    }
1589
 
 
1590
 
  return ((cpu_count > 0) ? SYSINFO_RET_OK : SYSINFO_RET_FAIL);
1591
 
}
1592
 
*/
1593
 
 
1594
 
/* 
1595
 
 * ALREADY ADDED
1596
 
 * 
1597
 
#ifdef HAVE_LDAP
1598
 
static int check_ldap(char *hostname, short port,int *value, const char *msg, int mlen_max)
1599
 
{
1600
 
        int rc;
1601
 
        LDAP *ldap;
1602
 
        LDAPMessage *res;
1603
 
        LDAPMessage *msg;
1604
 
 
1605
 
        char *base = "";
1606
 
        int scope = LDAP_SCOPE_BASE;
1607
 
        char *filter="(objectClass=*)";
1608
 
        int attrsonly=0;
1609
 
        char *attrs[2];
1610
 
 
1611
 
        attrs[0] = "namingContexts";
1612
 
        attrs[1] = NULL;
1613
 
 
1614
 
        BerElement *ber;
1615
 
        char *attr=NULL;
1616
 
        char **valRes=NULL;
1617
 
 
1618
 
        ldap = ldap_init(hostname, port);
1619
 
        if ( !ldap )
1620
 
        {
1621
 
                *value=0;
1622
 
                return  SYSINFO_RET_OK;
1623
 
        }
1624
 
 
1625
 
        rc = ldap_search_s(ldap, base, scope, filter, attrs, attrsonly, &res);
1626
 
        if( rc != 0 )
1627
 
        {
1628
 
                *value=0;
1629
 
                return  SYSINFO_RET_OK;
1630
 
        }
1631
 
 
1632
 
        msg = ldap_first_entry(ldap, res);
1633
 
        if( !msg )
1634
 
        {
1635
 
                *value=0;
1636
 
                return  SYSINFO_RET_OK;
1637
 
        }
1638
 
       
1639
 
        attr = ldap_first_attribute (ldap, msg, &ber);
1640
 
        valRes = ldap_get_values( ldap, msg, attr );
1641
 
 
1642
 
        ldap_value_free(valRes);
1643
 
        ldap_memfree(attr);
1644
 
        if (ber != NULL) {
1645
 
                ber_free(ber, 0);
1646
 
        }
1647
 
        ldap_msgfree(res);
1648
 
        ldap_unbind(ldap);
1649
 
       
1650
 
        *value=1;
1651
 
        return  SYSINFO_RET_OK;
1652
 
}
1653
 
#endif
1654
 
*/
1655
 
 
1656
 
ZBX_METRIC agent_commands[]=
1657
 
/*      KEY             FUNCTION (if double) FUNCTION (if string) PARAM*/
1658
 
        {
1659
 
          /*
1660
 
          {"kern[maxfiles]"       ,KERNEL_MAXFILES,       0, 0},
1661
 
          */
1662
 
 
1663
 
        {"kern[maxproc]"        ,KERNEL_MAXPROC,        0, 0},
1664
 
 
1665
 
        {"proc_cnt[*]"          ,PROCCNT,               0, "inetd"},
1666
 
 
1667
 
        {"memory[total]"        ,TOTALMEM,              0, 0},
1668
 
        {"memory[free]"         ,FREEMEM,               0, 0},
1669
 
        
1670
 
        /*
1671
 
        {"memory[shared]"       ,SHAREDMEM,             0, 0},
1672
 
        {"memory[buffers]"      ,BUFFERSMEM,            0, 0},
1673
 
        {"memory[cached]"       ,CACHEDMEM,             0, 0},
1674
 
        {"memory[free]"         ,FREEMEM,               0, 0},
1675
 
        */
1676
 
 
1677
 
        {"version[zabbix_agent]",0,                     VERSION, 0},
1678
 
 
1679
 
        {"diskfree[*]"          ,DISKFREE,              0, "/"},
1680
 
        {"disktotal[*]"         ,DISKTOTAL,             0, "/"},
1681
 
        {"diskused[*]"          ,DISKUSED,              0, "/"},
1682
 
 
1683
 
        {"diskfree_perc[*]"     ,DISKFREE_PERC,         0, "/"},
1684
 
        {"diskused_perc[*]"     ,DISKUSED_PERC,         0, "/"},
1685
 
 
1686
 
        {"inodefree[*]"         ,INODEFREE,             0, "/"},
1687
 
        {"inodefree_perc[*]"    ,INODEFREE_PERC,        0, "/"},
1688
 
        {"inodetotal[*]"        ,INODETOTAL,            0, "/"},
1689
 
 
1690
 
        {"cksum[*]"             ,CKSUM,                 0, "/etc/services"},
1691
 
 
1692
 
        {"md5sum[*]"            ,0,                     MD5SUM, "/etc/services"},
1693
 
 
1694
 
        {"filesize[*]"          ,FILESIZE,              0, "/etc/passwd"},
1695
 
        {"file[*]"              ,ISFILE,                0, "/etc/passwd"},
1696
 
 
1697
 
        {"cpu[idle]"            ,CPUIDLE,               0, 0},
1698
 
        {"cpu[user]"            ,CPUUSER,               0, 0},
1699
 
        {"cpu[system]"          ,CPUSYSTEM,             0, 0},
1700
 
        {"cpu[iowait]"          ,CPUIOWAIT,             0, 0},
1701
 
 
1702
 
        /*
1703
 
        {"cpu[nice]"            ,CPUNICE,               0, 0},
1704
 
        {"cpu[interrupt]"       ,CPUINTERRUPT,          0, 0},
1705
 
        */
1706
 
 
1707
 
        {"netloadin[*]"         ,NETLOADIN,             0, "lo"},
1708
 
        {"netloadout[*]"        ,NETLOADOUT,            0, "lo"},
1709
 
        {"netpacketsin[*]"      ,NETPACKETSIN,          0, "lo"},
1710
 
        {"netpacketsout[*]"     ,NETPACKETSOUT,         0, "lo"},
1711
 
        {"neterrsin[*]"         ,NETERRSIN,             0, "lo"},
1712
 
        {"neterrsout[*]"        ,NETERRSOUT,            0, "lo"},
1713
 
        {"netcollout[*]"        ,NETCOLLOUT,            0, "lo"},
1714
 
 
1715
 
 
1716
 
        {"disk_read_ops[*]"     ,DISKREADOPS,           0, "hda"},
1717
 
        {"disk_read_kbs[*]"     ,DISKREADBLOCKS,        0, "hda"},
1718
 
        {"disk_write_ops[*]"    ,DISKWRITEOPS,          0, "hda"},
1719
 
        {"disk_write_kbs[*]"    ,DISKWRITEBLOCKS,       0, "hda"},
1720
 
        {"disk_busy[*]"         ,DISKBUSY,              0, "hda"},
1721
 
        {"disk_svc[*]"          ,DISKSVC,               0, "hda"},
1722
 
 
1723
 
        /*
1724
 
        {"sensor[temp1]"        ,SENSOR,                0, "temp1"},
1725
 
        {"sensor[temp2]"        ,SENSOR,                0, "temp2"},
1726
 
        {"sensor[temp3]"        ,SENSOR,                0, "temp3"},
1727
 
        */
1728
 
 
1729
 
        {"swap[free]"           ,SWAPFREE,              0, 0},
1730
 
        {"swap[total]"          ,SWAPTOTAL,             0, 0},
1731
 
        {"swap[in]"             ,SWAPIN,                0, 0},
1732
 
        {"swap[out]"            ,SWAPOUT,               0, 0},
1733
 
 
1734
 
        {"system[interrupts]"   ,INTERRUPTS,            0, 0},
1735
 
        {"system[switches]"     ,CSWITCHES,             0, 0},
1736
 
        {"system[procload]"     ,PROCLOAD,              0, 0},
1737
 
        {"system[procload5]"    ,PROCLOAD5,             0, 0},
1738
 
        {"system[procload15]"   ,PROCLOAD15,            0, 0},
1739
 
        {"system[proccount]"    ,PROCCOUNT,             0, 0},
1740
 
        {"system[procrunning]"  ,PROCRUNNING,           0, 0},
1741
 
 
1742
 
        {"system[hostname]"     ,0,             EXECUTE_STR, "hostname"},
1743
 
        {"system[uname]"        ,0,             EXECUTE_STR, "uname -a"},
1744
 
        {"system[uptime]"       ,UPTIME,        0, 0},
1745
 
        {"system[users]"        ,EXECUTE,       0,"who|wc -l"},
1746
 
 
1747
 
        {"ping"                 ,PING,          0, 0},
1748
 
        {"tcp_count"            ,EXECUTE,       0, "netstat -s -P tcp | grep tcpCurrEstab | cut -f2 | tr -s ' ' | cut -d' ' -f3"},
1749
 
 
1750
 
        {"tcp_listen[*]"        ,TCP_LISTEN,    0, "22"},
1751
 
 
1752
 
        {"check_port[*]"        ,CHECK_PORT,    0, "80"},
1753
 
 
1754
 
        {"check_service[*]"     ,CHECK_SERVICE,         0, "ssh,127.0.0.1,22"},
1755
 
        {"check_service_perf[*]",CHECK_SERVICE_PERF,    0, "ssh,127.0.0.1,22"},
1756
 
 
1757
 
        {0}
1758
 
        };