2 * Copyright (c) 2005-2006 The FreeBSD Project
5 * Author: Victor Cruceru <soc-victor@freebsd.org>
7 * Redistribution of this software and documentation and use in source and
8 * binary forms, with or without modification, are permitted provided that
9 * the following conditions are met:
11 * 1. Redistributions of source code or documentation must retain the above
12 * copyright notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Host Resources MIB for SNMPd.
34 #ifndef HOSTRES_SNMP_H_1132245017
35 #define HOSTRES_SNMP_H_1132245017
37 #include <sys/types.h>
38 #include <sys/queue.h>
45 #include <bsnmp/asn1.h>
46 #include <bsnmp/snmp.h>
48 #include <bsnmp/snmpmod.h>
51 * Default package directory for hrSWInstalledTable. Can be overridden
52 * via SNMP or configuration file.
54 #define PATH_PKGDIR "/var/db/pkg"
57 * These are the default maximum caching intervals for the various tables
58 * in seconds. They can be overridden from the configuration file.
60 #define HR_STORAGE_TBL_REFRESH 7
61 #define HR_FS_TBL_REFRESH 7
62 #define HR_DISK_TBL_REFRESH 7
63 #define HR_NETWORK_TBL_REFRESH 7
64 #define HR_SWINS_TBL_REFRESH 120
65 #define HR_SWRUN_TBL_REFRESH 3
73 #define HRDBG(...) do { \
74 fprintf(stderr, "HRDEBUG: %s: ", __func__); \
75 fprintf(stderr, __VA_ARGS__); \
76 fprintf(stderr, "\n"); \
81 #define HRDBG(...) do { } while (0)
85 /* path to devd(8) output pipe */
86 #define PATH_DEVD_PIPE "/var/run/devd.pipe"
88 #define IS_KERNPROC(kp) (((kp)->ki_flag & P_KTHREAD) == P_KTHREAD)
90 enum snmpTCTruthValue {
95 /* The number of CPU load samples per one minute, per each CPU */
96 #define MAX_CPU_SAMPLES 4
100 * max len (including '\0'), for device_entry::descr field below,
103 #define DEV_DESCR_MLEN (64 + 1)
106 * max len (including '\0'), for device_entry::name and
107 * device_map_entry::name_key fields below, according to MIB
109 #define DEV_NAME_MLEN (32 + 1)
112 * max len (including '\0'), for device_entry::location and
113 * device_map_entry::location_key fields below, according to MIB
115 #define DEV_LOC_MLEN (128 + 1)
118 * This structure is used to hold a SNMP table entry
119 * for HOST-RESOURCES-MIB's hrDeviceTable
121 struct device_entry {
123 const struct asn_oid *type;
125 const struct asn_oid *id; /* only oid_zeroDotZero as (*id) value*/
126 int32_t status; /* enum DeviceStatus */
129 #define HR_DEVICE_FOUND 0x001
130 /* not dectected by libdevice, so don't try to refresh it*/
131 #define HR_DEVICE_IMMUTABLE 0x002
133 /* next 3 are not from the SNMP mib table, only to be used internally */
138 TAILQ_ENTRY(device_entry) link;
142 * Next structure is used to keep o list of mappings from a specific
143 * name (a_name) to an entry in the hrFSTblEntry;
144 * We are trying to keep the same index for a specific name at least
145 * for the duration of one SNMP agent run.
147 struct device_map_entry {
148 int32_t hrIndex; /* used for hrDeviceTblEntry::index */
150 /* map key is the pair (name_key, location_key) */
151 u_char *name_key; /* copy of device name */
152 u_char *location_key;
155 * Next may be NULL if the respective hrDeviceTblEntry
156 * is (temporally) gone.
158 struct device_entry *entry_p;
159 STAILQ_ENTRY(device_map_entry) link;
161 STAILQ_HEAD(device_map, device_map_entry);
163 /* descriptor to access kernel memory */
166 /* Table used for consistent device table indexing. */
167 extern struct device_map device_map;
169 /* Maximum number of ticks between two updates for hrStorageTable */
170 extern uint32_t storage_tbl_refresh;
172 /* Maximum number of ticks between updated of FS table */
173 extern uint32_t fs_tbl_refresh;
175 /* maximum number of ticks between updates of SWRun and SWRunPerf table */
176 extern uint32_t swrun_tbl_refresh;
178 /* Maximum number of ticks between device table refreshs. */
179 extern uint32_t device_tbl_refresh;
181 /* maximum number of ticks between refreshs */
182 extern uint32_t disk_storage_tbl_refresh;
184 /* maximum number of ticks between updates of network table */
185 extern uint32_t swins_tbl_refresh;
187 /* maximum number of ticks between updates of network table */
188 extern uint32_t network_tbl_refresh;
190 /* package directory */
191 extern u_char *pkg_dir;
193 /* Initialize and populate storage table */
194 void init_storage_tbl(void);
196 /* Finalization routine for hrStorageTable. */
197 void fini_storage_tbl(void);
199 /* Refresh routine for hrStorageTable. */
200 void refresh_storage_tbl(int);
203 * Get the type of filesystem referenced in a struct statfs * -
204 * used by FSTbl and StorageTbl functions.
206 const struct asn_oid *fs_get_type(const struct statfs *);
209 * Because hrFSTable depends to hrStorageTable we are
210 * refreshing hrFSTable by refreshing hrStorageTable.
211 * When one entry "of type" fs from hrStorageTable is refreshed
212 * then the corresponding entry from hrFSTable is refreshed
213 * FS_tbl_pre_refresh_v() is called before refeshing fs part of hrStorageTable
215 void fs_tbl_pre_refresh(void);
216 void fs_tbl_process_statfs_entry(const struct statfs *, int32_t);
218 /* Called after refreshing fs part of hrStorageTable */
219 void fs_tbl_post_refresh(void);
221 /* Refresh the FS table if neccessary. */
222 void refresh_fs_tbl(void);
224 /* Finalization routine for hrFSTable. */
225 void fini_fs_tbl(void);
227 /* Init the things for both of hrSWRunTable and hrSWRunPerfTable */
228 void init_swrun_tbl(void);
230 /* Finalization routine for both of hrSWRunTable and hrSWRunPerfTable */
231 void fini_swrun_tbl(void);
233 /* Init and populate hrDeviceTable */
234 void init_device_tbl(void);
236 /* start devd monitoring */
237 void start_device_tbl(struct lmodule *);
239 /* Finalization routine for hrDeviceTable */
240 void fini_device_tbl(void);
242 /* Refresh routine for hrDeviceTable. */
243 void refresh_device_tbl(int);
245 /* Find an item in hrDeviceTbl by its entry->index. */
246 struct device_entry *device_find_by_index(int32_t);
248 /* Find an item in hrDeviceTbl by name. */
249 struct device_entry *device_find_by_name(const char *);
251 /* Create a new entry out of thin air. */
252 struct device_entry *device_entry_create(const char *, const char *,
255 /* Delete an entry from hrDeviceTbl */
256 void device_entry_delete(struct device_entry *entry);
258 /* Init the things for hrProcessorTable. */
259 void init_processor_tbl(void);
261 /* Finalization routine for hrProcessorTable. */
262 void fini_processor_tbl(void);
264 /* Start the processor table CPU load collector. */
265 void start_processor_tbl(struct lmodule *);
267 /* Init the things for hrDiskStorageTable */
268 int init_disk_storage_tbl(void);
270 /* Finalization routine for hrDiskStorageTable. */
271 void fini_disk_storage_tbl(void);
273 /* Refresh routine for hrDiskStorageTable. */
274 void refresh_disk_storage_tbl(int);
276 /* Finalization routine for hrPartitionTable. */
277 void fini_partition_tbl(void);
279 /* Finalization routine for hrNetworkTable. */
280 void fini_network_tbl(void);
282 /* populate network table */
283 void start_network_tbl(void);
285 /* initialize installed software table */
286 void init_swins_tbl(void);
288 /* finalize installed software table */
289 void fini_swins_tbl(void);
291 /* refresh the hrSWInstalledTable if necessary */
292 void refresh_swins_tbl(void);
294 /* Init the things for hrPrinterTable */
295 void init_printer_tbl(void);
297 /* Finalization routine for hrPrinterTable. */
298 void fini_printer_tbl(void);
300 /* Refresh printer table */
301 void refresh_printer_tbl(void);
303 /* get boot command line */
304 int OS_getSystemInitialLoadParameters(u_char **);
306 /* Start refreshing the partition table */
307 void partition_tbl_post_refresh(void);
309 /* Handle refresh for the given disk */
310 void partition_tbl_handle_disk(int32_t, const char *);
312 /* Finish refreshing the partition table. */
313 void partition_tbl_pre_refresh(void);
315 /* Set the FS index in a partition table entry */
316 void handle_partition_fs_index(const char *, int32_t);
318 /* Make an SNMP DateAndTime from a struct tm. */
319 int make_date_time(u_char *, const struct tm *, u_int);
321 /* Free all static data */
322 void fini_scalars(void);
324 #endif /* HOSTRES_SNMP_H_1132245017 */