78b042763d034a53cd5fa3465aba27bff0a44ea3
[public/netxms.git] / src / agent / subagents / openbsd / disk.cpp
1 /* $Id: disk.cpp,v 1.3 2007-09-27 10:33:46 alk Exp $ */
2
3 /*
4 ** NetXMS subagent for FreeBSD
5 ** Copyright (C) 2004 Alex Kirhenshtein
6 **
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software
19 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 **
21 **/
22
23 #include <nms_common.h>
24 #include <nms_agent.h>
25
26 #include <sys/param.h>
27 #include <sys/mount.h>
28
29 #include "disk.h"
30
31 LONG H_DiskInfo(char *pszParam, char *pArg, char *pValue)
32 {
33 int nRet = SYSINFO_RC_ERROR;
34 char szArg[512] = {0};
35 struct statfs s;
36
37 NxGetParameterArg(pszParam, 1, szArg, sizeof(szArg));
38
39 if (szArg[0] != 0 && statfs(szArg, &s) == 0)
40 {
41 nRet = SYSINFO_RC_SUCCESS;
42
43 QWORD usedBlocks = (QWORD)(s.f_blocks - s.f_bfree);
44 QWORD totalBlocks = (QWORD)s.f_blocks;
45 QWORD blockSize = (QWORD)s.f_bsize;
46 QWORD freeBlocks = (QWORD)s.f_bfree;
47 QWORD availableBlocks = (QWORD)s.f_bavail;
48
49 switch((long)pArg)
50 {
51 case DISK_TOTAL:
52 ret_uint64(pValue, totalBlocks * blockSize);
53 break;
54 case DISK_USED:
55 ret_uint64(pValue, usedBlocks * blockSize);
56 break;
57 case DISK_FREE:
58 ret_uint64(pValue, freeBlocks * blockSize);
59 break;
60 case DISK_AVAIL:
61 ret_uint64(pValue, availableBlocks * blockSize);
62 break;
63 case DISK_USED_PERC:
64 ret_double(pValue, (usedBlocks * 100) / totalBlocks);
65 break;
66 case DISK_AVAIL_PERC:
67 ret_double(pValue, (availableBlocks * 100) / totalBlocks);
68 break;
69 case DISK_FREE_PERC:
70 ret_double(pValue, (freeBlocks * 100) / totalBlocks);
71 break;
72 default:
73 nRet = SYSINFO_RC_ERROR;
74 break;
75 }
76 }
77
78 return nRet;
79 }
80
81 ///////////////////////////////////////////////////////////////////////////////
82 /*
83
84 $Log: not supported by cvs2svn $
85 Revision 1.2 2007/09/27 09:20:41 alk
86 DISK_* params fixed in all subagents
87
88 Revision 1.1 2006/03/07 09:42:48 alk
89 OpenBSD subagent incorporated
90 flex params changed in libnxsl's makefile
91
92 Revision 1.1 2005/01/17 17:14:32 alk
93 freebsd agent, incomplete (but working)
94
95 Revision 1.1 2004/10/22 22:08:34 alk
96 source restructured;
97 implemented:
98 Net.IP.Forwarding
99 Net.IP6.Forwarding
100 Process.Count(*)
101 Net.ArpCache
102 Net.InterfaceList (if-type not implemented yet)
103 System.ProcessList
104
105
106 */