hostres_snmp.h revision 154133
1154133Sharti/* 2154133Sharti * Copyright (c) 2005-2006 The FreeBSD Project 3154133Sharti * All rights reserved. 4154133Sharti * 5154133Sharti * Author: Victor Cruceru <soc-victor@freebsd.org> 6154133Sharti * 7154133Sharti * Redistribution of this software and documentation and use in source and 8154133Sharti * binary forms, with or without modification, are permitted provided that 9154133Sharti * the following conditions are met: 10154133Sharti * 11154133Sharti * 1. Redistributions of source code or documentation must retain the above 12154133Sharti * copyright notice, this list of conditions and the following disclaimer. 13154133Sharti * 2. Redistributions in binary form must reproduce the above copyright 14154133Sharti * notice, this list of conditions and the following disclaimer in the 15154133Sharti * documentation and/or other materials provided with the distribution. 16154133Sharti * 17154133Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18154133Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19154133Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20154133Sharti * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21154133Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22154133Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23154133Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24154133Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25154133Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26154133Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27154133Sharti * SUCH DAMAGE. 28154133Sharti * 29154133Sharti * Host Resources MIB for SNMPd. 30154133Sharti * 31154133Sharti * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h 154133 2006-01-09 12:33:45Z harti $ 32154133Sharti */ 33154133Sharti 34154133Sharti#ifndef HOSTRES_SNMP_H_1132245017 35154133Sharti#define HOSTRES_SNMP_H_1132245017 36154133Sharti 37154133Sharti#include <sys/types.h> 38154133Sharti#include <sys/queue.h> 39154133Sharti 40154133Sharti#include <stdio.h> 41154133Sharti#include <fcntl.h> 42154133Sharti#include <kvm.h> 43154133Sharti#include <devinfo.h> 44154133Sharti 45154133Sharti#include <bsnmp/asn1.h> 46154133Sharti#include <bsnmp/snmp.h> 47154133Sharti 48154133Sharti#include <bsnmp/snmpmod.h> 49154133Sharti 50154133Sharti/* 51154133Sharti * Default package directory for hrSWInstalledTable. Can be overridden 52154133Sharti * via SNMP or configuration file. 53154133Sharti */ 54154133Sharti#define PATH_PKGDIR "/var/db/pkg" 55154133Sharti 56154133Sharti/* 57154133Sharti * These are the default maximum caching intervals for the various tables 58154133Sharti * in seconds. They can be overridden from the configuration file. 59154133Sharti */ 60154133Sharti#define HR_STORAGE_TBL_REFRESH 7 61154133Sharti#define HR_FS_TBL_REFRESH 7 62154133Sharti#define HR_DISK_TBL_REFRESH 7 63154133Sharti#define HR_NETWORK_TBL_REFRESH 7 64154133Sharti#define HR_SWINS_TBL_REFRESH 120 65154133Sharti#define HR_SWRUN_TBL_REFRESH 3 66154133Sharti 67154133Shartistruct tm; 68154133Shartistruct statfs; 69154133Sharti 70154133Sharti/* a debug macro */ 71154133Sharti#ifndef NDEBUG 72154133Sharti 73154133Sharti#define HRDBG(...) do { \ 74154133Sharti fprintf(stderr, "HRDEBUG: %s: ", __func__); \ 75154133Sharti fprintf(stderr, __VA_ARGS__); \ 76154133Sharti fprintf(stderr, "\n"); \ 77154133Sharti } while (0) 78154133Sharti 79154133Sharti#else 80154133Sharti 81154133Sharti#define HRDBG(...) do { } while (0) 82154133Sharti 83154133Sharti#endif /*NDEBUG*/ 84154133Sharti 85154133Sharti/* path to devd(8) output pipe */ 86154133Sharti#define PATH_DEVD_PIPE "/var/run/devd.pipe" 87154133Sharti 88154133Sharti#define IS_KERNPROC(kp) (((kp)->ki_flag & P_KTHREAD) == P_KTHREAD) 89154133Sharti 90154133Shartienum snmpTCTruthValue { 91154133Sharti SNMP_TRUE = 1, 92154133Sharti SNMP_FALSE= 2 93154133Sharti}; 94154133Sharti 95154133Sharti/* The number of CPU load samples per one minute, per each CPU */ 96154133Sharti#define MAX_CPU_SAMPLES 4 97154133Sharti 98154133Sharti/* 99154133Sharti * This structure is used to hold a SNMP table entry 100154133Sharti * for HOST-RESOURCES-MIB's hrDeviceTable 101154133Sharti */ 102154133Shartistruct device_entry { 103154133Sharti int32_t index; 104154133Sharti struct asn_oid type; 105154133Sharti u_char descr[64 + 1]; 106154133Sharti struct asn_oid id; 107154133Sharti int32_t status; /* enum DeviceStatus */ 108154133Sharti uint32_t errors; 109154133Sharti 110154133Sharti#define HR_DEVICE_FOUND 0x001 111154133Sharti /* not dectected by libdevice, so don't try to refresh it*/ 112154133Sharti#define HR_DEVICE_IMMUTABLE 0x002 113154133Sharti 114154133Sharti /* next 3 are not from the SNMP mib table, only to be used internally */ 115154133Sharti uint32_t flags; 116154133Sharti u_char name[32 + 1]; 117154133Sharti u_char location[128 + 1]; 118154133Sharti TAILQ_ENTRY(device_entry) link; 119154133Sharti}; 120154133Sharti 121154133Sharti/* 122154133Sharti * Next structure is used to keep o list of mappings from a specific 123154133Sharti * name (a_name) to an entry in the hrFSTblEntry; 124154133Sharti * We are trying to keep the same index for a specific name at least 125154133Sharti * for the duration of one SNMP agent run. 126154133Sharti */ 127154133Shartistruct device_map_entry { 128154133Sharti int32_t hrIndex; /* used for hrDeviceTblEntry::index */ 129154133Sharti 130154133Sharti /* map key is the pair (name_key, location_key) */ 131154133Sharti u_char name_key[32 + 1]; /* copy of device name */ 132154133Sharti u_char location_key[128 + 1]; 133154133Sharti 134154133Sharti /* 135154133Sharti * Next may be NULL if the respective hrDeviceTblEntry 136154133Sharti * is (temporally) gone. 137154133Sharti */ 138154133Sharti struct device_entry *entry_p; 139154133Sharti STAILQ_ENTRY(device_map_entry) link; 140154133Sharti}; 141154133ShartiSTAILQ_HEAD(device_map, device_map_entry); 142154133Sharti 143154133Sharti/* descriptor to access kernel memory */ 144154133Shartiextern kvm_t *hr_kd; 145154133Sharti 146154133Sharti/* Table used for consistent device table indexing. */ 147154133Shartiextern struct device_map device_map; 148154133Sharti 149154133Sharti/* Maximum number of ticks between two updates for hrStorageTable */ 150154133Shartiextern uint32_t storage_tbl_refresh; 151154133Sharti 152154133Sharti/* Maximum number of ticks between updated of FS table */ 153154133Shartiextern uint32_t fs_tbl_refresh; 154154133Sharti 155154133Sharti/* maximum number of ticks between updates of SWRun and SWRunPerf table */ 156154133Shartiextern uint32_t swrun_tbl_refresh; 157154133Sharti 158154133Sharti/* Maximum number of ticks between device table refreshs. */ 159154133Shartiextern uint32_t device_tbl_refresh; 160154133Sharti 161154133Sharti/* maximum number of ticks between refreshs */ 162154133Shartiextern uint32_t disk_storage_tbl_refresh; 163154133Sharti 164154133Sharti/* maximum number of ticks between updates of network table */ 165154133Shartiextern uint32_t swins_tbl_refresh; 166154133Sharti 167154133Sharti/* maximum number of ticks between updates of network table */ 168154133Shartiextern uint32_t network_tbl_refresh; 169154133Sharti 170154133Sharti/* package directory */ 171154133Shartiextern u_char *pkg_dir; 172154133Sharti 173154133Sharti/* Initialize and populate storage table */ 174154133Shartivoid init_storage_tbl(void); 175154133Sharti 176154133Sharti/* Finalization routine for hrStorageTable. */ 177154133Shartivoid fini_storage_tbl(void); 178154133Sharti 179154133Sharti/* Refresh routine for hrStorageTable. */ 180154133Shartivoid refresh_storage_tbl(int); 181154133Sharti 182154133Sharti/* 183154133Sharti * Get the type of filesystem referenced in a struct statfs * - 184154133Sharti * used by FSTbl and StorageTbl functions. 185154133Sharti */ 186154133Sharticonst struct asn_oid *fs_get_type(const struct statfs *); 187154133Sharti 188154133Sharti/* 189154133Sharti * Because hrFSTable depends to hrStorageTable we are 190154133Sharti * refreshing hrFSTable by refreshing hrStorageTable. 191154133Sharti * When one entry "of type" fs from hrStorageTable is refreshed 192154133Sharti * then the corresponding entry from hrFSTable is refreshed 193154133Sharti * FS_tbl_pre_refresh_v() is called before refeshing fs part of hrStorageTable 194154133Sharti */ 195154133Shartivoid fs_tbl_pre_refresh(void); 196154133Shartivoid fs_tbl_process_statfs_entry(const struct statfs *, int32_t); 197154133Sharti 198154133Sharti/* Called after refreshing fs part of hrStorageTable */ 199154133Shartivoid fs_tbl_post_refresh(void); 200154133Sharti 201154133Sharti/* Refresh the FS table if neccessary. */ 202154133Shartivoid refresh_fs_tbl(void); 203154133Sharti 204154133Sharti/* Finalization routine for hrFSTable. */ 205154133Shartivoid fini_fs_tbl(void); 206154133Sharti 207154133Sharti/* Init the things for both of hrSWRunTable and hrSWRunPerfTable */ 208154133Shartivoid init_swrun_tbl(void); 209154133Sharti 210154133Sharti/* Finalization routine for both of hrSWRunTable and hrSWRunPerfTable */ 211154133Shartivoid fini_swrun_tbl(void); 212154133Sharti 213154133Sharti/* Init and populate hrDeviceTable */ 214154133Shartivoid init_device_tbl(void); 215154133Sharti 216154133Sharti/* start devd monitoring */ 217154133Shartivoid start_device_tbl(struct lmodule *); 218154133Sharti 219154133Sharti/* Finalization routine for hrDeviceTable */ 220154133Shartivoid fini_device_tbl(void); 221154133Sharti 222154133Sharti/* Refresh routine for hrDeviceTable. */ 223154133Shartivoid refresh_device_tbl(int); 224154133Sharti 225154133Sharti/* Find an item in hrDeviceTbl by its entry->index. */ 226154133Shartistruct device_entry *device_find_by_index(int32_t); 227154133Sharti 228154133Sharti/* Find an item in hrDeviceTbl by name. */ 229154133Shartistruct device_entry *device_find_by_name(const char *); 230154133Sharti 231154133Sharti/* Create a new entry out of thin air. */ 232154133Shartistruct device_entry *device_entry_create(const char *, const char *, 233154133Sharti const char *); 234154133Sharti 235154133Sharti/* Init the things for hrProcessorTable. */ 236154133Shartivoid init_processor_tbl(void); 237154133Sharti 238154133Sharti/* Finalization routine for hrProcessorTable. */ 239154133Shartivoid fini_processor_tbl(void); 240154133Sharti 241154133Sharti/* Start the processor table CPU load collector. */ 242154133Shartivoid start_processor_tbl(struct lmodule *); 243154133Sharti 244154133Sharti/* Init the things for hrDiskStorageTable */ 245154133Shartiint init_disk_storage_tbl(void); 246154133Sharti 247154133Sharti/* Finalization routine for hrDiskStorageTable. */ 248154133Shartivoid fini_disk_storage_tbl(void); 249154133Sharti 250154133Sharti/* Refresh routine for hrDiskStorageTable. */ 251154133Shartivoid refresh_disk_storage_tbl(int); 252154133Sharti 253154133Sharti/* Finalization routine for hrPartitionTable. */ 254154133Shartivoid fini_partition_tbl(void); 255154133Sharti 256154133Sharti/* Finalization routine for hrNetworkTable. */ 257154133Shartivoid fini_network_tbl(void); 258154133Sharti 259154133Sharti/* populate network table */ 260154133Shartivoid start_network_tbl(void); 261154133Sharti 262154133Sharti/* initialize installed software table */ 263154133Shartivoid init_swins_tbl(void); 264154133Sharti 265154133Sharti/* finalize installed software table */ 266154133Shartivoid fini_swins_tbl(void); 267154133Sharti 268154133Sharti/* refresh the hrSWInstalledTable if necessary */ 269154133Shartivoid refresh_swins_tbl(void); 270154133Sharti 271154133Sharti/* Init the things for hrPrinterTable */ 272154133Shartivoid init_printer_tbl(void); 273154133Sharti 274154133Sharti/* Finalization routine for hrPrinterTable. */ 275154133Shartivoid fini_printer_tbl(void); 276154133Sharti 277154133Sharti/* Refresh printer table */ 278154133Shartivoid refresh_printer_tbl(void); 279154133Sharti 280154133Sharti/* get boot command line */ 281154133Shartiint OS_getSystemInitialLoadParameters(u_char **); 282154133Sharti 283154133Sharti/* Start refreshing the partition table */ 284154133Shartivoid partition_tbl_post_refresh(void); 285154133Sharti 286154133Sharti/* Handle refresh for the given disk */ 287154133Shartivoid partition_tbl_handle_disk(int32_t, const char *); 288154133Sharti 289154133Sharti/* Finish refreshing the partition table. */ 290154133Shartivoid partition_tbl_pre_refresh(void); 291154133Sharti 292154133Sharti/* Set the FS index in a partition table entry */ 293154133Shartivoid handle_partition_fs_index(const char *, int32_t); 294154133Sharti 295154133Sharti/* Make an SNMP DateAndTime from a struct tm. */ 296154133Shartiint make_date_time(u_char *, const struct tm *, u_int); 297154133Sharti 298154133Sharti/* Free all static data */ 299154133Shartivoid fini_scalars(void); 300154133Sharti 301154133Sharti#endif /* HOSTRES_SNMP_H_1132245017 */ 302