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