From faf2b84083ffe822d9bb0e8955c82e41c5e75426 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 001/104] Adding sql-schema --- sql-schema/089.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sql-schema/089.sql diff --git a/sql-schema/089.sql b/sql-schema/089.sql new file mode 100644 index 000000000..d35435553 --- /dev/null +++ b/sql-schema/089.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); +ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_mac ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers_cbgp ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas DROP INDEX device_area, ADD UNIQUE KEY `device_area` (`device_id`,`ospfAreaId`,`context_name`); +ALTER TABLE ospf_instances ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_instances DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_instance_id`,`context_name`); +ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); +ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; From 9c0f0d7ea06f6c9969679eda88fe9f498e4beb9b Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:05:14 +0100 Subject: [PATCH 002/104] Adding mibs --- mibs/CISCO-BRIDGE-DOMAIN-MIB | 450 +++++++++++++++++ mibs/CISCO-CONTEXT-MAPPING-MIB | 853 +++++++++++++++++++++++++++++++++ 2 files changed, 1303 insertions(+) create mode 100644 mibs/CISCO-BRIDGE-DOMAIN-MIB create mode 100644 mibs/CISCO-CONTEXT-MAPPING-MIB diff --git a/mibs/CISCO-BRIDGE-DOMAIN-MIB b/mibs/CISCO-BRIDGE-DOMAIN-MIB new file mode 100644 index 000000000..68e9ddb9c --- /dev/null +++ b/mibs/CISCO-BRIDGE-DOMAIN-MIB @@ -0,0 +1,450 @@ +-- ***************************************************************** +-- CISCO-BRIDGE-DOMAIN-MIB.my : Cisco Bridge Domain MIB +-- +-- Oct 2007, Madhavi Dokku +-- +-- Copyright (c) 2007 by Cisco Systems, Inc. +-- +-- All rights reserved. +-- ***************************************************************** + +CISCO-BRIDGE-DOMAIN-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE, + Unsigned32 + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + TEXTUAL-CONVENTION, + TruthValue, + RowStatus, + StorageType + FROM SNMPv2-TC + ifIndex + FROM IF-MIB + ciscoMgmt + FROM CISCO-SMI; + + +ciscoBridgeDomainMIB MODULE-IDENTITY + LAST-UPDATED "200712290000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + Tel: +1 800 553-NETS + + E-mail: cs-ethermibs@cisco.com" + DESCRIPTION + "A bridge domain is one of the means by which it is possible + to define a broadcast domain on a bridging device. It is an + alternative to 802.1D bridge-groups and to 802.1Q VLAN + bridging. + + Bridge domain is the service specification, and specifies the + broadcast domain number on which this frame of this particular + service instance must be made available on. The physical and + virtual interfaces that can comprise a bridge domain are + heterogeneous in nature comprising Ethernet service instances, + WAN Virtual Circuit for ATM or Frame Relay and VFIs. However, + the frame encapsulations for all interface types are + essentially Ethernet. + + Without bridge-domains, VLANs would have to be globally unique + per device and one would only be restricted to the theoretical + maximum of 4095 VLANs for single tagged traffic. However + with the introduction of bridge-domains, one can + associate a service instance with a bridge-domain and all + service instances in the same bridge-domain form a + broadcast domain. Bridge-domain ID determines the + broadcast domain and the VLAN id is merely used to match + and map traffic. With bridge domain feature configured + VLAN IDs would be unique per interface only and not globally. + Thus bridge domains make VLAN ids have only local + significance per port + + + Differences between Bridge Domains and 802.1AD Bridges: + ======================================================= + 1. Scope of the VLAN technology which uses 802.1 AD is global to + the box. + But in case of Bridge domain, the scope of vlan is local to + interface + + 2. Switchport 802.1AD restricts the number of broadcast domain + on a box to 4095. + However, with Bridge domains, we can have up to 16k broadcast + domain. + + 3. Under a single Bridge domain service instance, there can be + flexible service mapping criterion.(i.e match based on + outer vlan, outer cos, inner vlan, inner cos and payload + ethertype). + Whereas in case of switch port 802.1AD/dot1q this is not + supported. + + Similarities between Bridge Domains and 802.1AD Bridges: + ======================================================= + + 1. Both use the same MAC address lookup for forwarding. + + 2. Both work with protocols like STP, DTP etc. + + 3. Both of them classify 'ports' in a system into Bridges/Bridge + Domains. + + Ethernet service instance is the instantiation of an Ethernet + virtual circuit on a given port on a given router. In other + words, an Ethernet service instance is an object that holds + information about the layer 2 service that is being offered + on a given port of a given router as part of a given Ethernet + virtual circuit. Bridge domains feature is currently supported + on ethernet service instances only and can be later extented + to other interfaces like ATM and Frame Relay. + + This MIB helps the network management personnel to find out the + details of various broadcast domains configured in the network. + + Definition of terms and acronyms: + + ATM: Asynchronous Transfer mode + + BD: Bridge Domain + + C-mac: Customer MAC + + EVC: Ethernet Virtual Circuit + + FR: Frame Relay + + SH: Split Horizon + + VFI: Virtual Forwarding Instance + + VLAN: Virtual Local Area Network + + WAN: Wide Area Network" + REVISION "200712290000Z" + DESCRIPTION + "Modified the MIB description with details on similarities and + differences between Bridge Domains and 802.1AD Bridges." + REVISION "200712040000Z" + DESCRIPTION + "Initial version of this MIB module." + ::= { ciscoMgmt 642 } + + +ciscoBdMIBNotifications OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 0 } + +ciscoBdMIBObjects OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 1 } + +ciscoBdMIBConformance OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 2 } + +cbdSystemInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 1 } + +cbdMemberInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 2 } + + +-- Textual Conventions + +CbdType ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "Defines the different types of bridge domain members: + + 'other': none of the following + + 'ether': Ethernet Service Instance + + 'atmVc': ATM Virtual connection + + 'frVc': Frame Relay Virtual Connection" + SYNTAX INTEGER { + other(1), + ether(2), + atmVc(3), + frVc(4) + } + +cbdMembersConfigured OBJECT-TYPE + SYNTAX Unsigned32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the number of bridge domain + members configured on this bridge domain." + ::= { cbdSystemInfo 1 } +-- Member Info Table + +cbdMemberInfoTable OBJECT-TYPE + SYNTAX SEQUENCE OF CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table provides the bridge domain member attributes + of the members currently configured for each bridge + domain." + ::= { cbdMemberInfo 1 } + +cbdMemberInfoEntry OBJECT-TYPE + SYNTAX CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A conceptual row in cbdMemberInfoTable. This is indexed + by ifIndex and cbdSIIndex. Each row is created when a bridge + domain member is configured under a service instance." + INDEX { + ifIndex, + cbdSIIndex + } + ::= { cbdMemberInfoTable 1 } + +CbdMemberInfoEntry ::= SEQUENCE { + cbdSIIndex Unsigned32, + cbdMemberType CbdType, + cbdMemberOperState INTEGER , + cbdMemberAdminState INTEGER , + cbdMemberSplitHorizon TruthValue, + cbdMemberSplitHorizonNum Unsigned32, + cbdMemberStorageType StorageType, + cbdMemberStatus RowStatus, + cbdMembercMac TruthValue +} + +cbdSIIndex OBJECT-TYPE + SYNTAX Unsigned32 (1..4294967295 ) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This object indicates an arbitary index that uniquely + identifies the Service Instance to which this bridge domain + member belongs to." + ::= { cbdMemberInfoEntry 1 } + +cbdMemberType OBJECT-TYPE + SYNTAX CbdType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the type of the bridge domain member + like ATM VC, Frame Relay VC, or Ethernet service." + DEFVAL { other } + ::= { cbdMemberInfoEntry 2 } + +cbdMemberOperState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the operational state of the bridge + domain Member. Operational state of the Bridge domain member + is same as the operational state of the underlying service + instance. Bridge domain members are configured under service + instances and multiple service instances can be attached to a + single physical interface defining various kinds of services. + Bridge domain members have many to one relationship with + interface + Indexes. When ifOperStatus of the underlying interface is down, + the state of cbdMemberOperState should be down. When + ifOperStatus + of the underlying interface is up, cbdMemberOperState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is an unknown state. + + 'up': the bridge domain member is fully operational and + able to bridge the traffic. This means that both the + physical interface and the underlying service instance + are administratively up. + + 'down': the Bridge Domain member is down and not + capable of bridging. This state means either the underlying + service instance is down or the interface is down." + ::= { cbdMemberInfoEntry 3 } + +cbdMemberAdminState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the administrative state of the + bridge domain Member. Admin state of the Bridge domain member + is same as the admin state of the underlying service instance. + Bridge domain members are configured under service instances + and multiple service instances can be attached to a single + physical interface defining various kinds of services. Bridge + Domain members have many to one relationship with interface + Indexes. When ifAdminStatus of the unerlying interface is down + the state of cbdMemberAdminState should be down. When ifOperStatus + of the underlying interface is up cbdMemberAdminState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is in unknown + administrative state. + + 'up': the Bridge Domain member is administratively up. This + means that both the physical interface and the underlying service + instance are administratively up. + + 'admindown': the Bridge Domain member is down as it is + administratively configured to be down and is not + capable of bridging. This means that either the underlying + service instance is configured as administratively down or + the physical interface is configured as administratively + down." + ::= { cbdMemberInfoEntry 4 } + +cbdMemberSplitHorizon OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates whether split horizon is + configured on this bridge domain member." + ::= { cbdMemberInfoEntry 5 } + +cbdMemberSplitHorizonNum OBJECT-TYPE + SYNTAX Unsigned32 (0..65535 ) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the split horizon number if + configured on the bridge domain member. Split horizon + is used to avoid sending traffic between interfaces. + Frames are not forwarded to the members belonging to the + same split horizon group." + DEFVAL { 0 } + ::= { cbdMemberInfoEntry 6 } + +cbdMemberStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object specifies the storage type of this conceptual + row. This object can only have a value 'nonVolatile'. Other + values are not applicable for this conceptual row and are + not supported." + DEFVAL { nonVolatile } + ::= { cbdMemberInfoEntry 7 } + +cbdMemberStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object enables the SNMP agent to create, modify, + and delete rows in the cbdMemberInfoTable." + DEFVAL { active } + ::= { cbdMemberInfoEntry 8 } + +cbdMembercMac OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates if cmac is configured on this + bridge domain member. Cmac denotes if this bridge domain is + configured as a customer domain." + ::= { cbdMemberInfoEntry 9 } + + +-- Notifications + +ciscoBdNotificationPrefix OBJECT IDENTIFIER + ::= { ciscoBdMIBNotifications 0 } + +-- Conformance + +ciscoBdMIBCompliances OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 1 } + +ciscoBdMIBGroups OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 2 } + + +ciscoBdMIBComplianceRev1 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-BRIDGE-DOMAIN-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cbdSystemInfoGroup, + cbdMemberInfoGroup + } + ::= { ciscoBdMIBCompliances 1 } + +-- Units of Conformance + +cbdSystemInfoGroup OBJECT-GROUP + OBJECTS { cbdMembersConfigured } + STATUS current + DESCRIPTION + "This group contain information about bridge domain." + ::= { ciscoBdMIBGroups 1 } + +cbdMemberInfoGroup OBJECT-GROUP + OBJECTS { + cbdMemberType, + cbdMemberOperState, + cbdMemberAdminState, + cbdMemberSplitHorizon, + cbdMemberSplitHorizonNum, + cbdMemberStorageType, + cbdMemberStatus, + cbdMembercMac + } + STATUS current + DESCRIPTION + "This group contain information related to bridge domain + members." + ::= { ciscoBdMIBGroups 2 } + +END + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mibs/CISCO-CONTEXT-MAPPING-MIB b/mibs/CISCO-CONTEXT-MAPPING-MIB new file mode 100644 index 000000000..94451564d --- /dev/null +++ b/mibs/CISCO-CONTEXT-MAPPING-MIB @@ -0,0 +1,853 @@ +-- ***************************************************************** +-- CISCO-CONTEXT-MAPPING-MIB.my: Cisco Context Mapping MIB +-- +-- January 2005, Chinna Pellacuru. +-- +-- May 2008, Sheethal Gunjal. +-- +-- Copyright (c) 2004-2005, 2008 by cisco Systems Inc. +-- All rights reserved. +-- +-- **************************************************************** + +CISCO-CONTEXT-MAPPING-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + SnmpAdminString + FROM SNMP-FRAMEWORK-MIB + RowStatus, + StorageType + FROM SNMPv2-TC + CiscoBridgeDomain + FROM CISCO-TC + ciscoMgmt + FROM CISCO-SMI; + + +ciscoContextMappingMIB MODULE-IDENTITY + LAST-UPDATED "200811220000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + + Tel: +1 800 553-NETS + + E-mail: cs-snmp@cisco.com" + DESCRIPTION + "A single SNMP agent sometimes needs to support multiple + instances of the same MIB module, and does so through the + use of multiple SNMP contexts. This typically occurs because + the technology has evolved to have extra dimension(s), i.e., + one or more extra data and/or identifier values which are + different in the different contexts, but were not defined in + INDEX clause(s) of the original MIB module. In such cases, + network management applications need to know the specific + data/identifier values in each context, and this MIB module + provides mapping tables which contain that information. + + Within a network there can be multiple Virtual Private + Networks (VPNs) configured using Virtual Routing and + Forwarding Instances (VRFs). Within a VPN there can be + multiple topologies when Multi-topology Routing (MTR) is + used. Also, Interior Gateway Protocols (IGPs) can have + multiple protocol instances running on the device. + A network can have multiple broadcast domains configured + using Bridge Domain Identifiers. + + With MTR routing, VRFs, and Bridge domains, a router now + needs to support multiple instances of several existing + MIB modules, and this can be achieved if the router's SNMP + agent provides access to each instance of the same MIB module + via a different SNMP context (see Section 3.1.1 of RFC 3411). + For MTR routing, VRFs, and Bridge domains, a different SNMP + context is needed depending on one or more of the following: + the VRF, the topology-identifier, the routing protocol instance, + and the bridge domain identifier. + In other words, the router's management information can be + accessed through multiple SNMP contexts where each such + context represents a specific VRF, a specific + topology-identifier, a specific routing protocol instance + and/or a bridge domain identifier. This MIB module provides + a mapping of each such SNMP context to the corresponding VRF, + the corresponding topology, the corresponding routing protocol + instance, and the corresponding bridge domain identifier. + Some SNMP contexts are independent of VRFs, independent of + a topology, independent of a routing protocol instance, or + independent of a bridge domain and in such a case, the mapping + is to the zero length string. + + With the Cisco package licensing strategy, the features + available in the image are grouped into multiple packages + and each packages can be managed to operate at different + feature levels based on the available license. This MIB + module provides option to associate an SNMP context to a + feature package group. This will allow manageability of + license MIB objects specific to a feature package group. + + As technology evolves more we may need additional + identifiers to identify the context. Then we would need + to add those additional identifiers into the mapping." + REVISION "200811220000Z" + DESCRIPTION + "Added New Table cContextMappingLicenseGroupTable + to provide SNMP Context support for license package groups. + + Added cContextMappingLicenseGroupDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev2 in MODULE-COMPLIANCE + + Updated the MIB description to indicate the use of + the above additions" + REVISION "200805300000Z" + DESCRIPTION + "Add cContextMappingBridgeInstanceTable. + + Added cContextMappingBridgeInstanceDataGroup. + Deprecated cContextMappingMIBComplianceRev1 and added + cContextMappingMIBComplianceRev2 compliance statement." + REVISION "200802010000Z" + DESCRIPTION + "Added New Table cContextMappingBridgeDomainTable + to provide SNMP context support to the Bridge Domain. + + Added cContextMappingBridgeDomainDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev1 in MODULE-COMPLIANCE" + REVISION "200503170000Z" + DESCRIPTION + "Initial version of the MIB module." + ::= { ciscoMgmt 468 } + + +cContextMappingMIBObjects OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 1 } + +cContextMappingMIBConformance OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 2 } + + +cContextMappingTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which VRF, topology, and routing protocol instance. + + This table is indexed by SNMP VACM context. + + Configuring a row in this table for an SNMP context + does not require that the context be already defined, + i.e., a row can be created in this table for a context + before the corresponding row is created in RFC 3415's + vacmContextTable. + + To create a row in this table, a manager must set + cContextMappingRowStatus to either 'createAndGo' or + 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingRowStatus to 'destroy'." + ::= { cContextMappingMIBObjects 1 } + +cContextMappingEntry OBJECT-TYPE + SYNTAX CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the corresponding VRF, + the corresponding topology, and the corresponding routing + protocol instance." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingTable 1 } + +CContextMappingEntry ::= SEQUENCE { + cContextMappingVacmContextName SnmpAdminString, + cContextMappingVrfName SnmpAdminString, + cContextMappingTopologyName SnmpAdminString, + cContextMappingProtoInstName SnmpAdminString, + cContextMappingStorageType StorageType, + cContextMappingRowStatus RowStatus +} + +cContextMappingVacmContextName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The vacmContextName given to the SNMP context. + + This is a human readable name identifying a particular + SNMP VACM context at a particular SNMP entity. + The empty contextName (zero length) represents the + default context." + ::= { cContextMappingEntry 1 } + +cContextMappingVrfName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the VRF to which the SNMP context + is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this VRF. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any VRF." + DEFVAL { ''H } + ::= { cContextMappingEntry 2 } + +cContextMappingTopologyName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the topology to which the SNMP + context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this topology. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any topology." + DEFVAL { ''H } + ::= { cContextMappingEntry 3 } + +cContextMappingProtoInstName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the protocol instance to which the + SNMP context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this protocol instance. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any protocol instance." + DEFVAL { ''H } + ::= { cContextMappingEntry 4 } + +cContextMappingStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingEntry 5 } + +cContextMappingRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingEntry 6 } + + + +cContextMappingBridgeDomainTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which bridge domain. + + A Bridge Domain is one of the means by which it is possible + to define an Ethernet broadcast domain on a bridging device. + A network can have multiple broadcast domains configured. + This table helps the network management personnel to find + out the details of various broadcast domains configured + in the network. + + An entry need to exist in cContextMappingTable, to create + an entry in this table." + ::= { cContextMappingMIBObjects 2 } + +cContextMappingBridgeDomainEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge domain. + + To create a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeDomainTable 1 } + +CContextMappingBridgeDomainEntry ::= SEQUENCE { + cContextMappingBridgeDomainIdentifier CiscoBridgeDomain, + cContextMappingBridgeDomainStorageType StorageType, + cContextMappingBridgeDomainRowStatus RowStatus +} + +cContextMappingBridgeDomainIdentifier OBJECT-TYPE + SYNTAX CiscoBridgeDomain + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the bridge domain to which the SNMP context is + mapped to." + REFERENCE "CISCO-BRIDGE-DOMAIN-MIB" + ::= { cContextMappingBridgeDomainEntry 1 } + +cContextMappingBridgeDomainStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeDomainEntry 2 } + +cContextMappingBridgeDomainRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeDomainEntry 3 } + + + +cContextMappingBridgeInstanceTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on mapping between + cContextMappingVacmContextName and bridge instance. + + Bridge instance is an instance of a physical or logical + bridge which has unique bridge-id. + + If an entry is deleted from cContextMappingTable, the + corresponding entry in this table will also get deleted. + + If an entry needs to be created in this table, the + corresponding entry must exist in cContextMappingTable." + REFERENCE "BRIDGE-MIB" + ::= { cContextMappingMIBObjects 3 } + +cContextMappingBridgeInstanceEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge instance. + + To create a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeInstanceTable 1 } + +CContextMappingBridgeInstanceEntry ::= SEQUENCE { + cContextMappingBridgeInstName SnmpAdminString, + cContextMappingBridgeInstStorageType StorageType, + cContextMappingBridgeInstRowStatus RowStatus +} + +cContextMappingBridgeInstName OBJECT-TYPE + SYNTAX SnmpAdminString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The object identifies the name given to bridge + instance to which the SNMP context is mapped to. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this bridge instance. + + When the value of this object is a zero length + string, it indicates that the SNMP context is + independent of any bridge instances." + ::= { cContextMappingBridgeInstanceEntry 1 } + +cContextMappingBridgeInstStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeInstanceEntry 2 } + +cContextMappingBridgeInstRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeInstanceEntry 3 } + + + +cContextMappingLicenseGroupTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which License Group. + Group level licensing is used where each + Technology Package is enabled via a License." + ::= { cContextMappingMIBObjects 4 } + +cContextMappingLicenseGroupEntry OBJECT-TYPE + SYNTAX CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + CContextMappingVacmContextName to the + corresponding License Group." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingLicenseGroupTable 1 } + +CContextMappingLicenseGroupEntry ::= SEQUENCE { + cContextMappingLicenseGroupName SnmpAdminString, + cContextMappingLicenseGroupStorageType StorageType, + cContextMappingLicenseGroupRowStatus RowStatus +} + +cContextMappingLicenseGroupName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the Group to which the SNMP context + is mapped. + + Feature sets from all groups will be combined to form + universal image. User can configure multiple groups as needed. + + For example: In Next generation ISRs will use + the universal image package level licensing model + for its licensing need. Each group has + the feature set needed for that specific technology. + Feature sets from different groups are combined to + form universal image and each feature set for a group + can be enabled using a valid license key. There will + be a base level ipbase package in which the router + boots with out any license key. + + The following are the different Technology Groups. + 1.crypto + 2.data + 3.ip + 4.legacy + 5.novpn-security + 6.security + 7.uc" + ::= { cContextMappingLicenseGroupEntry 1 } + +cContextMappingLicenseGroupStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingLicenseGroupEntry 2 } + +cContextMappingLicenseGroupRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingLicenseGroupEntry 3 } + + +-- Conformance + +cContextMappingMIBCompliances OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 1 } + +cContextMappingMIBGroups OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 2 } + + +-- Compliance + +cContextMappingMIBCompliance MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { cContextMappingDataGroup } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 1 } + +cContextMappingMIBComplianceRev1 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB. This compliance statement + is superceded by cContextMappingMIBComplianceRev2." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 2 } + +cContextMappingMIBComplianceRev2 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + ::= { cContextMappingMIBCompliances 3 } + +cContextMappingMIBComplianceRev3 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup, + cContextMappingLicenseGroupDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + + OBJECT cContextMappingLicenseGroupName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 4 } + +-- Units of Conformance + +cContextMappingDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingVrfName, + cContextMappingTopologyName, + cContextMappingProtoInstName, + cContextMappingStorageType, + cContextMappingRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding VRF, the corresponding topology, + and the corresponding routing protocol instance." + ::= { cContextMappingMIBGroups 1 } + +cContextMappingBridgeDomainDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeDomainIdentifier, + cContextMappingBridgeDomainStorageType, + cContextMappingBridgeDomainRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge domain." + ::= { cContextMappingMIBGroups 2 } + +cContextMappingBridgeInstanceDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeInstName, + cContextMappingBridgeInstStorageType, + cContextMappingBridgeInstRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge instance." + ::= { cContextMappingMIBGroups 3 } + +cContextMappingLicenseGroupDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingLicenseGroupName, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding LicenseGroupName." + ::= { cContextMappingMIBGroups 4 } + +END + + + + + + + + From 1bf8610f2348249cf8942b8fe6829a0659a72bee Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:13:53 +0100 Subject: [PATCH 003/104] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 158 ++++--- includes/discovery/bgp-peers.inc.php | 378 ++++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 114 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 125 +++-- includes/polling/ospf.inc.php | 548 +++++++++++----------- includes/snmp.inc.php | 8 +- 11 files changed, 957 insertions(+), 682 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index f80583a83..d1ce8b4e8 100644 --- a/includes/common.php +++ b/includes/common.php @@ -290,6 +290,16 @@ function device_by_id_cache($device_id, $refresh = '0') { } else { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id)); + + //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time + $vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id)); + $device['vrf_lite_cisco'] = array(); + if(!empty($vrfs_lite_cisco)){ + foreach ($vrfs_lite_cisco as $vrf){ + $device['vrf_lite_cisco'][$vrf['context_name']] = $vrf; + } + } + $cache['devices']['id'][$device_id] = $device; } return $device; diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 4b6dc05bc..8dc38b4be 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ $config['enable_pseudowires'] = 1; // Enable Pseudowires $config['enable_vrfs'] = 1; // Enable VRFs +$config['enable_vrf_lite_cisco'] = 1; +// Enable VRF lite cisco $config['enable_printers'] = 0; // Enable Printer support $config['enable_sla'] = 0; @@ -732,6 +734,7 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; // $config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index 69b0d9b75..c60d4ca95 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ unset($mac_table); echo 'ARP Table : '; -$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); -$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); -$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); - -foreach (explode("\n", $ipNetToMedia_data) as $data) { - list($oid, $mac) = explode(' ', $data); - list($if, $first, $second, $third, $fourth) = explode('.', $oid); - $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; - if ($ip != '...') { - $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); - - list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); - $m_a = zeropad($m_a); - $m_b = zeropad($m_b); - $m_c = zeropad($m_c); - $m_d = zeropad($m_d); - $m_e = zeropad($m_e); - $m_f = zeropad($m_f); - $md_a = hexdec($m_a); - $md_b = hexdec($m_b); - $md_c = hexdec($m_c); - $md_d = hexdec($m_d); - $md_e = hexdec($m_e); - $md_f = hexdec($m_f); - $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; - - $mac_table[$if][$mac]['ip'] = $ip; - $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; - $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; - $mac_table[$if][$mac]['cleanmac'] = $clean_mac; - $port_id = $interface['port_id']; - $mac_table[$port_id][$clean_mac] = 1; - - if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) { - // Commented below, no longer needed but leaving for reference. - // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; - $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id'])); - - if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { - d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); - - log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); - } - - dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); - echo '.'; - } - else if (isset($interface['port_id'])) { - echo '+'; - // echo("Add MAC $mac\n"); - $insert_data = array( - 'port_id' => $interface['port_id'], - 'mac_address' => $clean_mac, - 'ipv4_address' => $ip, - ); - - dbInsert($insert_data, 'ipv4_mac'); - }//end if - }//end if -}//end foreach - -$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'"; -foreach (dbFetchRows($sql) as $entry) { - $entry_mac = $entry['mac_address']; - $entry_if = $entry['port_id']; - if (!$mac_table[$entry_if][$entry_mac]) { - dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); - d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); - - echo '-'; - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; + + $ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); + $ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); + $ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); -echo "\n"; -unset($mac); + foreach (explode("\n", $ipNetToMedia_data) as $data) { + list($oid, $mac) = explode(' ', $data); + list($if, $first, $second, $third, $fourth) = explode('.', $oid); + $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; + if ($ip != '...') { + $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); + + list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); + $m_a = zeropad($m_a); + $m_b = zeropad($m_b); + $m_c = zeropad($m_c); + $m_d = zeropad($m_d); + $m_e = zeropad($m_e); + $m_f = zeropad($m_f); + $md_a = hexdec($m_a); + $md_b = hexdec($m_b); + $md_c = hexdec($m_c); + $md_d = hexdec($m_d); + $md_e = hexdec($m_e); + $md_f = hexdec($m_f); + $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; + + $mac_table[$if][$mac]['ip'] = $ip; + $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; + $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; + $mac_table[$if][$mac]['cleanmac'] = $clean_mac; + $port_id = $interface['port_id']; + $mac_table[$port_id][$clean_mac] = 1; + + if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']))) { + // Commented below, no longer needed but leaving for reference. + // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; + $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=? AND `context_name`= ?', array($ip, $interface['port_id']), $device['context_name']); + + if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { + d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); + + log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); + } + + dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name'])); + echo '.'; + } + else if (isset($interface['port_id'])) { + echo '+'; + // echo("Add MAC $mac\n"); + $insert_data = array( + 'port_id' => $interface['port_id'], + 'mac_address' => $clean_mac, + 'ipv4_address' => $ip, + 'context_name' => $device['context_name'], + ); + + dbInsert($insert_data, 'ipv4_mac'); + }//end if + }//end if + }//end foreach + + $sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = ' AND `context_name`= ?".$device['device_id']." AND M.context_name='". $device['context_name'] ."'"; + foreach (dbFetchRows($sql) as $entry) { + $entry_mac = $entry['mac_address']; + $entry_if = $entry['port_id']; + if (!$mac_table[$entry_if][$entry_mac]) { + dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ? AND `context_name`= ?', array($entry_if, $entry_mac, $device['context_name'])); + d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); + + echo '-'; + } + } + echo "\n"; + unset($mac); + unset($device['context_name']); +} +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf..dd341715d 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -3,232 +3,246 @@ if ($config['enable_bgp']) { // Discover BGP peers echo 'BGP Sessions : '; - + + if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; + } + else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); + } + $bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB', $config['mibdir'])); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + if (is_numeric($bgpLocalAs)) { + echo "AS$bgpLocalAs "; - if (is_numeric($bgpLocalAs)) { - echo "AS$bgpLocalAs "; - - if ($bgpLocalAs != $device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); - echo 'Updated AS '; - } - - $peer2 = false; - $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); - if (empty($peers_data)) { - $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); - } - else { - $peer2 = true; - } - - d_echo("Peers : $peers_data \n"); - - $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); - $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - - foreach (explode("\n", $peers) as $peer) { - if ($peer2 === true) { - list($ver, $peer) = explode('.', $peer, 2); + if ($bgpLocalAs != $device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); + echo 'Updated AS '; } - list($peer_ip, $peer_as) = explode(' ', $peer); - if (strstr($peer_ip, ':')) { - $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); - $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); - $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + $peer2 = false; + $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); + if (empty($peers_data)) { + $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); + } + else { + $peer2 = true; } - if ($peer && $peer_ip != '0.0.0.0') { - d_echo("Found peer $peer_ip (AS$peer_as)\n"); + d_echo("Peers : $peers_data \n"); - $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, - 'ver' => $ver, - ); - } - } + $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); + $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - if ($device['os'] == 'junos') { - // Juniper BGP4-V2 MIB - // FIXME: needs a big cleanup! also see below. - // FIXME: is .0.ipv6 the only possible value here? - $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); foreach (explode("\n", $peers) as $peer) { - list($peer_ip_snmp, $peer_as) = explode(' ', $peer); + if ($peer2 === true) { + list($ver, $peer) = explode('.', $peer, 2); + } - // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. - $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + list($peer_ip, $peer_as) = explode(' ', $peer); + if (strstr($peer_ip, ':')) { + $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); + $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); + $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + } - if ($peer) { + if ($peer && $peer_ip != '0.0.0.0') { d_echo("Found peer $peer_ip (AS$peer_as)\n"); $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, + 'ip' => $peer_ip, + 'as' => $peer_as, + 'ver' => $ver, ); } } - } - } - else { - echo 'No BGP on host'; - if ($device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); - echo ' (Removed ASN) '; - } - } - // Process disovered peers - if (isset($peerlist)) { - foreach ($peerlist as $peer) { - $astext = get_astext($peer['as']); + if ($device['os'] == 'junos') { + // Juniper BGP4-V2 MIB + // FIXME: needs a big cleanup! also see below. + // FIXME: is .0.ipv6 the only possible value here? + $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); + foreach (explode("\n", $peers) as $peer) { + list($peer_ip_snmp, $peer_as) = explode(' ', $peer); - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') { - $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as']), 'bgpPeers'); - if ($config['autodiscovery']['bgp'] === true) { - $name = gethostbyaddr($peer['ip']); - $remote_device_id = discover_new_device($name, $device, 'BGP'); + // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. + $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + + if ($peer) { + d_echo("Found peer $peer_ip (AS$peer_as)\n"); + + $peerlist[] = array( + 'ip' => $peer_ip, + 'as' => $peer_as, + ); + } + } + } + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; + } + } + + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); + + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $device['context_name'])) < '1') { + $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'],'context_name' => $device['context_name']), 'bgpPeers'); + if ($config['autodiscovery']['bgp'] === true) { + $name = gethostbyaddr($peer['ip']); + $remote_device_id = discover_new_device($name, $device, 'BGP'); + } + + echo '+'; + } + else { + $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); + echo '.'; } - echo '+'; - } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; - } + if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { + if ($device['os_group'] == 'cisco') { + // Get afi/safi and populate cbgp on cisco ios (xe/xr) + unset($af_list); - if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { - if ($device['os_group'] == 'cisco') { - // Get afi/safi and populate cbgp on cisco ios (xe/xr) - unset($af_list); - - if ($peer2 === true) { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - else { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - - d_echo('afi data :: '); - d_echo($af_data); - - foreach ($af_data as $k => $v) { if ($peer2 === true) { - list(,$k) = explode('.', $k, 2); + $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); + } + else { + $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); } - d_echo("AFISAFI = $k\n"); + d_echo('afi data :: '); + d_echo($af_data); - $afisafi_tmp = explode('.', $k); - $safi = array_pop($afisafi_tmp); - $afi = array_pop($afisafi_tmp); - $bgp_ip = str_replace(".$afi.$safi", '', $k); - $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); - $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); - $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); - if ($afi && $safi && $bgp_ip == $peer['ip']) { - $af_list[$bgp_ip][$afi][$safi] = 1; + foreach ($af_data as $k => $v) { + if ($peer2 === true) { + list(,$k) = explode('.', $k, 2); + } + + d_echo("AFISAFI = $k\n"); + + $afisafi_tmp = explode('.', $k); + $safi = array_pop($afisafi_tmp); + $afi = array_pop($afisafi_tmp); + $bgp_ip = str_replace(".$afi.$safi", '', $k); + $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); + $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); + $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); + if ($afi && $safi && $bgp_ip == $peer['ip']) { + $af_list[$bgp_ip][$afi][$safi] = 1; + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=? AND `context_name`=?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])) == 0) { + dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); + } + } + } + } + + if ($device['os'] == 'junos') { + $safis[1] = 'unicast'; + $safis[2] = 'multicast'; + + if (!isset($j_peerIndexes)) { + $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + + foreach ($j_bgp as $index => $entry) { + switch ($entry['jnxBgpM2PeerRemoteAddrType']) { + case 'ipv4': + $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); + d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; + break; + + case 'ipv6': + $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); + $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); + $ip6 = Net_IPv6::compress($ip6); + d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; + + default: + echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; + break; + } + } + } + + if (!isset($j_afisafi)) { + $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + foreach (array_keys($j_prefixes) as $key) { + list($index,$afisafi) = explode('.', $key, 2); + $j_afisafi[$index][] = $afisafi; + } + } + + foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { + list ($afi,$safi) = explode('.', $afisafi); + $safi = $safis[$safi]; + $af_list[$afi][$safi] = 1; if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); } } } - } - if ($device['os'] == 'junos') { - $safis[1] = 'unicast'; - $safis[2] = 'multicast'; - - if (!isset($j_peerIndexes)) { - $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - - foreach ($j_bgp as $index => $entry) { - switch ($entry['jnxBgpM2PeerRemoteAddrType']) { - case 'ipv4': - $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); - d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; - break; - - case 'ipv6': - $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); - $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); - $ip6 = Net_IPv6::compress($ip6); - d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; - break; - - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - break; - } + $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND `context_name` = '" . $device['context_name'] . "'"; + foreach (dbFetchRows($af_query) as $entry) { + $afi = $entry['afi']; + $safi = $entry['safi']; + if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { + dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])); } } - - if (!isset($j_afisafi)) { - $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - foreach (array_keys($j_prefixes) as $key) { - list($index,$afisafi) = explode('.', $key, 2); - $j_afisafi[$index][] = $afisafi; - } - } - - foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { - list ($afi,$safi) = explode('.', $afisafi); - $safi = $safis[$safi]; - $af_list[$afi][$safi] = 1; - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { - dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); - } - } - } - - $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"; - foreach (dbFetchRows($af_query) as $entry) { - $afi = $entry['afi']; - $safi = $entry['safi']; - if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { - dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); - } } } + + unset($j_afisafi); + unset($j_prefixes); + unset($j_bgp); + unset($j_peerIndexes); } - unset($j_afisafi); - unset($j_prefixes); - unset($j_bgp); - unset($j_peerIndexes); - } + // Delete removed peers + $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."' AND `context_name` = '" . $device['context_name'] . "'"; - // Delete removed peers - $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; + foreach (dbFetchRows($sql) as $entry) { + unset($exists); + $i = 0; - foreach (dbFetchRows($sql) as $entry) { - unset($exists); - $i = 0; + while ($i < count($peerlist) && !isset($exists)) { + if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { + $exists = 1; + } - while ($i < count($peerlist) && !isset($exists)) { - if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { - $exists = 1; + $i++; } - $i++; + if (!isset($exists)) { + dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + echo '-'; + } } - if (!isset($exists)) { - dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - echo '-'; - } + unset($peerlist); + + echo "\n"; + unset($device['context_name']); } - - unset($peerlist); - - echo "\n"; + unset($device['context_name']); + unset($vrfs_c); } diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php new file mode 100644 index 000000000..ae2aff0e4 --- /dev/null +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -0,0 +1,142 @@ + and Mathieu Millet +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . */ + + +global $debug; + +// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco +if ($config['enable_vrf_lite_cisco']) { + + $ids = array(); + + // For the moment only will be cisco and the version 3 + if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') { + + echo ("VRF lite cisco : \n"); + $mib = "SNMP-COMMUNITY-MIB"; + + $mib = "CISCO-CONTEXT-MAPPING-MIB"; + //-Osq because if i put the n the oid from the first command is not the same of this one + $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); + $listVrf = str_replace("cContextMappingVrfName.", "", $listVrf); + $listVrf = str_replace('"', "", $listVrf); + $listVrf = trim($listVrf); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); + } + + $tableVrf; + foreach (explode("\n", $listVrf) as $lineVrf) { + $tmpVrf = explode(" ", $lineVrf, 2); + //the $tmpVrf[0] will be the context + if (count($tmpVrf) == 2 && !empty($tmpVrf[1])) { + $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1]; + } + } + + unset($listVrf); + + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); + $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); + $listIntance = str_replace('"', "", $listIntance); + $listIntance = trim($listIntance); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + } + + + foreach (explode("\n", $listIntance) as $lineIntance) { + $tmpIntance = explode(" ", $lineIntance, 2); + //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance + if (count($tmpIntance) == 2 && !empty($tmpIntance[1])) { + $tableVrf[$tmpIntance[0]]['intance_name'] = $tmpIntance[1]; + } + } + unset($listIntance); + + + foreach ($tableVrf as $context => $vrf) { + + + + if ($debug) { + + echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n"); + } + + $tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", array( + $device ['device_id'], + $context + )); + if (!empty($tmpVrf)) { + + $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id']; + + $vrfUpdate=array(); + + foreach ($vrfUpdate as $key => $value) { + if($vrf[$key]!=$value){ + $vrfUpdate[$key]=$value; + } + } + if (!empty($vrfUpdate)) { + dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array( + $tmp['vrf_lite_cisco_id'] + )); + } + } else { + + $id = dbInsert(array( + 'device_id' => $device ['device_id'], + 'context_name' => $context, + 'intance_name' => $vrf['intance_name'], + 'vrf_name' => $vrf['vrf_name'] + ), 'vrf_lite_cisco'); + + $ids[$id] = $id; + } + } + + unset($tableVrf); + } + + //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work + $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( + $device ['device_id'])); + + $device['vrf_lite_cisco'] = $tmpVrfC; + + //Delete all vrf that chaged + foreach ($tmpVrfC as $vrfC) { + unset($ids[$vrfC['vrf_lite_cisco_id']]); + } + if (!empty($ids)) { + foreach ($ids as $id) { + + dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array( + $id)); + } + } + + + unset($ids); + unset($tmpVrfC); +} // enable_vrf_lite_cisco +?> diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index b03ac9048..e8055e63c 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -669,8 +669,8 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity }//end discover_toner() - -function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin) { + +function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name='') { global $device,$config; $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen").'/'.$ipv6_prefixlen; @@ -683,21 +683,21 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') { $port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } // Below looks like a duplicate of the above FIXME - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } - $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)); + $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { - dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id), 'ipv6_addresses'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ? AND `context_name` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { + dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses'); echo '+'; } else { diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 53cf3ad57..26fc9ba28 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ network.'/'.$addr->bitmask; - $cidr = $addr->bitmask; - - if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { - $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') { - dbInsert(array('ipv4_network' => $network), 'ipv4_networks'); - // echo("Create Subnet $network\n"); - echo 'S'; - } - - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)) == '0') { - dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id), 'ipv4_addresses'); - // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); - echo '+'; - } - else { - echo '.'; - } - - $full_address = "$oid/$cidr|$ifIndex"; - $valid_v4[$full_address] = 1; - } - else { - echo '!'; - }//end if -}//end foreach - -$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; - - if (!$valid_v4[$full_address]) { - echo '-'; - $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { - $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); - } - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -echo "\n"; + $oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB')); + $oids = str_replace('ipAdEntIfIndex.', '', $oids); + foreach (explode("\n", $oids) as $data) { + $data = trim($data); + list($oid,$ifIndex) = explode(' ', $data); + $mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB')); + $addr = Net_IPv4::parseAddress("$oid/$mask"); + $network = $addr->network.'/'.$addr->bitmask; + $cidr = $addr->bitmask; -unset($valid_v4); + if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { + $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name` = ?', array($network, $device['context_name'])) < '1') { + dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks'); + // echo("Create Subnet $network\n"); + echo 'S'; + } + + $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name`= ?', array($network, $device['context_name'])); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? and `context_name`=?', array($oid, $cidr, $port_id, $device['context_name'])) == '0') { + dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id,'context_name' => $device['context_name']), 'ipv4_addresses'); + // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); + echo '+'; + } + else { + echo '.'; + } + + $full_address = "$oid/$cidr|$ifIndex"; + $valid_v4[$full_address] = 1; + } + else { + echo '!'; + }//end if + }//end foreach + + $sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND a.context_name= '" . $device['context_name'] . "'"; + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; + + if (!$valid_v4[$full_address]) { + echo '-'; + $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { + $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); + } + } + } + + echo "\n"; + unset($device['context_name']); + unset($valid_v4); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index 562428b6b..f7762ee98 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -1,78 +1,89 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); -$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); -$oids = str_replace('"', '', $oids); -$oids = str_replace('IP-MIB::', '', $oids); -$oids = trim($oids); - -foreach (explode("\n", $oids) as $data) { - if ($data) { - $data = trim($data); - list($ipv6addr,$ifIndex) = explode(' ', $data); - $oid = ''; - $sep = ''; - $adsep = ''; - unset($ipv6_address); - $do = '0'; - foreach (explode(':', $ipv6addr) as $part) { - $n = hexdec($part); - $oid = "$oid"."$sep"."$n"; - $sep = '.'; - $ipv6_address = $ipv6_address."$adsep".$part; - $do++; - if ($do == 2) { - $adsep = ':'; - $do = '0'; - } - else { - $adsep = ''; - } - } - - $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); - $ipv6_prefixlen = explode('.', $ipv6_prefixlen); - $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); - - $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); - - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); - } //end if -} //end foreach - -if (!$oids) { - $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); - $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); + $oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); $oids = str_replace('"', '', $oids); + $oids = str_replace('IP-MIB::', '', $oids); $oids = trim($oids); foreach (explode("\n", $oids) as $data) { if ($data) { - $data = trim($data); - list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); - list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); - $ipv6_address = snmp2ipv6($ipv6addr); - $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); + $data = trim($data); + list($ipv6addr,$ifIndex) = explode(' ', $data); + $oid = ''; + $sep = ''; + $adsep = ''; + unset($ipv6_address); + $do = '0'; + foreach (explode(':', $ipv6addr) as $part) { + $n = hexdec($part); + $oid = "$oid"."$sep"."$n"; + $sep = '.'; + $ipv6_address = $ipv6_address."$adsep".$part; + $do++; + if ($do == 2) { + $adsep = ':'; + $do = '0'; + } + else { + $adsep = ''; + } + } + + $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); + $ipv6_prefixlen = explode('.', $ipv6_prefixlen); + $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); + + $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); + + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); } //end if } //end foreach -} //end if -$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; + if (!$oids) { + $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); + $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = str_replace('"', '', $oids); + $oids = trim($oids); -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; - $port_id = $row['port_id']; - $valid_address = $full_address.'-'.$port_id; - if (!$valid['ipv6'][$valid_address]) { - echo '-'; - $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { - $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + foreach (explode("\n", $oids) as $data) { + if ($data) { + $data = trim($data); + list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); + list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); + $ipv6_address = snmp2ipv6($ipv6addr); + $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); + } //end if + } //end foreach + } //end if + + $sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND A.context_name= '" . $device['context_name'] . "'"; + + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; + $port_id = $row['port_id']; + $valid_address = $full_address.'-'.$port_id; + if (!$valid['ipv6'][$valid_address]) { + echo '-'; + $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { + $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + } } } -} -echo "\n"; + echo "\n"; + unset($device['context_name']); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index 56863ec10..40ff425a0 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -2,6 +2,9 @@ if ($config['enable_bgp']) { foreach (dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])) as $peer) { + //add context if exist + $device['context_name']= $peer['context_name']; + // Poll BGP Peer $peer2 = false; echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' '; @@ -62,14 +65,28 @@ if ($config['enable_bgp']) { } } else { - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; - $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; - $peer_data = trim(`$peer_cmd`); + // $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; + $oids = "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . ""; + $peer_data=snmp_get_multi($device,$oids,'-OUQs','BGP4-MIB'); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } }//end if - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + //list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + unset($peer_data); } else if ($device['os'] == 'junos') { // v6 for JunOS via Juniper MIB @@ -78,9 +95,9 @@ if ($config['enable_bgp']) { if (!isset($junos_v6)) { echo "\nCaching Oids..."; // FIXME - needs moved to function - $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; - foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { + //$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + + foreach (explode("\n",snmp_get($device,'jnxBgpM2PeerStatus.0.ipv6"','-OUnq','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos")) as $oid){ list($peer_oid) = explode(' ', $oid); $peer_id = explode('.', $peer_oid); $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); @@ -88,25 +105,34 @@ if ($config['enable_bgp']) { } // FIXME - move to function (and clean up, wtf?) - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); - $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; - $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; - // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? - $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= '|grep -v "No Such Instance"'; - d_echo("\n$peer_cmd\n"); - - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + + $oids = " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip]; # Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? + $oids .= " jnxBgpM2PeerInUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerFsmEstablishedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip]; + //$peer_cmd .= '|grep -v "No Such Instance"'; WHAT TO DO WITH THIS??,USE TO SEE -Ln?? + $peer_data=snmp_get_multi($device,$oids,'-OUQs -Ln','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos"); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + unset($peer_data); + d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); @@ -235,23 +261,37 @@ if ($config['enable_bgp']) { } else { // FIXME - move to function - $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - - d_echo("$cbgp_cmd\n"); - - $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); - $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); + + + $oids = " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + + d_echo("$oids\n"); + + $cbgp_data= snmp_get_multi($device,$oids,'-OUQs ','CISCO-BGP4-MIB'); + $cbgp_data= array_pop($cbgp_data); + d_echo("$cbgp_data\n"); + + }//end if - list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + + $cbgpPeerAcceptedPrefixes= !empty($cbgp_data['cbgpPeerAcceptedPrefixes'])?$cbgp_data['cbgpPeerAcceptedPrefixes']:''; + $cbgpPeerDeniedPrefixes= !empty($cbgp_data['cbgpPeerDeniedPrefixes'])?$cbgp_data['cbgpPeerDeniedPrefixes']:''; + $cbgpPeerPrefixAdminLimit= !empty($cbgp_data['cbgpPeerPrefixAdminLimit'])?$cbgp_data['cbgpPeerPrefixAdminLimit']:''; + $cbgpPeerPrefixThreshold= !empty($cbgp_data['cbgpPeerPrefixThreshold'])?$cbgp_data['cbgpPeerPrefixThreshold']:''; + $cbgpPeerPrefixClearThreshold= !empty($cbgp_data['cbgpPeerPrefixClearThreshold'])?$cbgp_data['cbgpPeerPrefixClearThreshold']:''; + $cbgpPeerAdvertisedPrefixes= !empty($cbgp_data['cbgpPeerAdvertisedPrefixes'])?$cbgp_data['cbgpPeerAdvertisedPrefixes']:''; + $cbgpPeerSuppressedPrefixes= !empty($cbgp_data['cbgpPeerSuppressedPrefixes'])?$cbgp_data['cbgpPeerSuppressedPrefixes']:''; + $cbgpPeerWithdrawnPrefixes= !empty($cbgp_data['cbgpPeerWithdrawnPrefixes'])?$cbgp_data['cbgpPeerWithdrawnPrefixes']:''; + + unset($cbgp_data); }//end if if ($device['os'] == 'junos') { @@ -331,5 +371,6 @@ if ($config['enable_bgp']) { } //end foreach } //end if echo "\n"; + unset($device['context_name']); } //end foreach } //end if diff --git a/includes/polling/ospf.inc.php b/includes/polling/ospf.inc.php index 8fec222a2..602255258 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_port_count = 0; $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ $ospf_oids_db = array( 'ospfDemandExtensions', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; -} - -// Pull data from device -$ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); -foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_instances_db[$ospf_instance_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id), 'ospf_instances'); - echo '+'; - $ospf_instances_db[$entry['ospf_instance_id']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_instances_poll); - echo 'Database: '; - print_r($ospf_instances_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_instances_db)) { - foreach ($ospf_instances_db as $ospf_instance_db) { - $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_db['ospf_instance_id']]; - foreach ($ospf_oids_db as $oid) { - // Loop the OIDs - if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid]) { - // If data has changed, build a query - $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_instance_update) { - dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - echo 'U'; - unset($ospf_instance_update); - } - else { - echo '.'; - } - - unset($ospf_instance_poll); - unset($ospf_instance_db); - $ospf_instance_count++; - }//end foreach -}//end if - -unset($ospf_instances_poll); -unset($ospf_instances_db); - -echo ' Areas: '; - $ospf_area_oids = array( 'ospfAuthType', 'ospfImportAsExtern', @@ -95,72 +38,6 @@ $ospf_area_oids = array( 'ospfAreaStatus', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_areas_db[$entry['ospfAreaId']] = $entry; -} - -// Pull data from device -$ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_areas_db[$ospf_area_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id), 'ospf_areas'); - echo '+'; - $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - $ospf_areas_db[$entry['ospf_area_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_areas_poll); - echo 'Database: '; - print_r($ospf_areas_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_areas_db)) { - foreach ($ospf_areas_db as $ospf_area_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_area_poll = $ospf_areas_poll[$ospf_area_db['ospfAreaId']]; - foreach ($ospf_area_oids as $oid) { - // Loop the OIDs - if ($ospf_area_db[$oid] != $ospf_area_poll[$oid]) { - // If data has changed, build a query - $ospf_area_update[$oid] = $ospf_area_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME - } - } - - if ($ospf_area_update) { - dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - echo 'U'; - unset($ospf_area_update); - } - else { - echo '.'; - } - - unset($ospf_area_poll); - unset($ospf_area_db); - $ospf_area_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'])); - }//end if - }//end foreach -}//end if - -unset($ospf_areas_db); -unset($ospf_areas_poll); - -// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); -// print_r($ospf_ports); -echo ' Ports: '; - $ospf_port_oids = array( 'ospfIfIpAddress', 'port_id', @@ -171,7 +48,7 @@ $ospf_port_oids = array( 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,87 +62,6 @@ $ospf_port_oids = array( 'ospfIfAuthType', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_ports_db[$entry['ospf_port_id']] = $entry; -} - -// Pull data from device -$ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_ports_db[$ospf_port_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id), 'ospf_ports'); - echo '+'; - $ospf_ports_db[$entry['ospf_port_id']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_ports_poll); - echo 'Database: '; - print_r($ospf_ports_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_ports_db)) { - foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_port_poll = $ospf_ports_poll[$ospf_port_db['ospf_port_id']]; - - if ($ospf_port_poll['ospfAddressLessIf']) { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); - } - else { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'])); - } - - foreach ($ospf_port_oids as $oid) { - // Loop the OIDs - if ($ospf_port_db[$oid] != $ospf_port_poll[$oid]) { - // If data has changed, build a query - $ospf_port_update[$oid] = $ospf_port_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_port_update) { - dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - echo 'U'; - unset($ospf_port_update); - } - else { - echo '.'; - } - - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'])); - // "DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); - echo '-'; - }//end if - }//end foreach -}//end if - -// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 -// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 -// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 -// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrState.172.22.203.98.0 full -// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 -// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 -// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active -// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic -// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false -echo ' Neighbours: '; - $ospf_nbr_oids_db = array( 'ospfNbrIpAddr', 'ospfNbrAddressLessIndex', @@ -279,83 +75,313 @@ $ospf_nbr_oids_db = array( 'ospfNbmaNbrPermanence', 'ospfNbrHelloSuppressed', ); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])) as $nbr_entry) { - $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry; + + +if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) { + $vrfs_lite_cisco = $device['vrf_lite_cisco']; +} else { + $vrfs_lite_cisco = array(array('context_name' => null)); } -// Pull data from device -$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_nbrs_db[$ospf_nbr_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id), 'ospf_nbrs'); - echo '+'; - $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - $ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry; + $device['context_name'] = $vrf_lite['context_name']; + + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; } -} -if ($debug) { - echo "\nPolled: "; - print_r($ospf_nbrs_poll); - echo 'Database: '; - print_r($ospf_nbrs_db); - echo "\n"; -} + // Pull data from device + $ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); + foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (empty($ospf_instances_db[$ospf_instance_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id, 'context_name' => $device['context_name']), 'ospf_instances'); + echo '+'; + $ospf_instances_db[$entry['ospf_instance_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; + } + } -// Loop array of entries and update -if (is_array($ospf_nbrs_db)) { - foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { - if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { - $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + if ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'])); + // Loop array of entries and update + if (is_array($ospf_instances_db)) { + foreach ($ospf_instances_db as $ospf_instance_id => $ospf_instance_db) { + if (is_array($ospf_instances_poll[$ospf_instance_id])) { + $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_id]; + foreach ($ospf_oids_db as $oid) { + // Loop the OIDs + if ($ospf_instance_db[$device['context_name']][$oid] != $ospf_instance_poll[$oid]) { + // If data has changed, build a query + $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } - if ($ospf_nbr_db['port_id'] != $ospf_nbr_poll['port_id']) { - if ($ospf_nbr_poll['port_id']) { - $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + if ($ospf_instance_update) { + dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + echo 'U'; + unset($ospf_instance_update); } else { - $ospf_nbr_update = array('port_id' => array('NULL')); + echo '.'; } + + unset($ospf_instance_poll); + unset($ospf_instance_db); + $ospf_instance_count++; + } else { + dbDelete('ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=? ', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); } + }//end foreach + }//end if + unset($ospf_instances_poll); + unset($ospf_instances_db); - foreach ($ospf_nbr_oids as $oid) { - // Loop the OIDs - d_echo($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n"); - if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid]) { - // If data has changed, build a query - $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; - // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + + echo ' Areas: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `context_name`=?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_areas_db[$entry['ospfAreaId']][$entry['context_name']] = $entry; + } + + // Pull data from device + $ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_areas_db[$ospf_area_id][$entry['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id, 'context_name' => $device['context_name']), 'ospf_areas'); + echo '+'; + $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + $ospf_areas_db[$ospf_area_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_areas_poll); + echo 'Database: '; + print_r($ospf_areas_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_areas_db)) { + foreach ($ospf_areas_db as $$ospf_area_id => $ospf_area_db) { + if (is_array($ospf_areas_poll[$ospf_area_id])) { + $ospf_area_poll = $ospf_areas_poll[$ospf_area_id]; + foreach ($ospf_area_oids as $oid) { + // Loop the OIDs + if ($ospf_area_db[$entry['context_name']][$oid] != $ospf_area_poll[$oid]) { + // If data has changed, build a query + $ospf_area_update[$oid] = $ospf_area_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME + } } - } - if ($ospf_nbr_update) { - dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - echo 'U'; - unset($ospf_nbr_update); + if ($ospf_area_update) { + dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + echo 'U'; + unset($ospf_area_update); + } + else { + echo '.'; + } + + unset($ospf_area_poll); + unset($ospf_area_db); + $ospf_area_count++; } else { - echo '.'; - } + dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); + }//end if + }//end foreach + }//end if - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; + unset($ospf_areas_db); + unset($ospf_areas_poll); + + +// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); +// print_r($ospf_ports); + echo ' Ports: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = $entry; + } + + // Pull data from device + $ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_ports_db[$ospf_port_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id, 'context_name' => $device['context_name']), 'ospf_ports'); + echo '+'; + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); } - else { - dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'])); - echo '-'; - }//end if - }//end foreach -}//end if + } + if ($debug) { + echo "\nPolled: "; + print_r($ospf_ports_poll); + echo 'Database: '; + print_r($ospf_ports_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_ports_db)) { + foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { + if (is_array($ospf_ports_poll[$ospf_port_id])) { + $ospf_port_poll = $ospf_ports_poll[$ospf_port_id]; + + if ($ospf_port_poll['ospfAddressLessIf']) { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); + } + else { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'], $device['context_name'])); + } + + foreach ($ospf_port_oids as $oid) { + // Loop the OIDs + if ($ospf_port_db[$device['context_name']][$oid] != $ospf_port_poll[$oid]) { + // If data has changed, build a query + $ospf_port_update[$oid] = $ospf_port_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } + + if ($ospf_port_update) { + dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); + echo 'U'; + unset($ospf_port_update); + } + else { + echo '.'; + } + + unset($ospf_port_poll); + unset($ospf_port_db); + $ospf_port_count++; + } + else { + dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'], $device['context_name'])); + // ("DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); + echo '-'; + }//end if + }//end foreach + }//end if + + +// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 +// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 +// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 +// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrState.172.22.203.98.0 full +// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 +// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 +// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active +// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic +// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false + echo ' Neighbours: '; + + $ospf_nbr_oids_rrd = array(); + $ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $nbr_entry) { + $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']][$device['context_name']] = $nbr_entry; + } + + // Pull data from device + $ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_nbrs_db[$ospf_nbr_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id, 'context_name' => $device['context_name']), 'ospf_nbrs'); + echo '+'; + $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id,$device['context_name'])); + $ospf_nbrs_db[$ospf_nbr_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_nbrs_poll); + echo 'Database: '; + print_r($ospf_nbrs_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_nbrs_db)) { + foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { + if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { + $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + + $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'], $device['context_name'])); + + if ($ospf_nbr_db[$device['context_name']]['port_id'] != $ospf_nbr_poll['port_id']) { + if (!empty($ospf_nbr_poll['port_id'])) { + $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + } + else { + $ospf_nbr_update = array('port_id' => array('NULL')); + } + } + + foreach ($ospf_nbr_oids as $oid) { + // Loop the OIDs + d_echo($ospf_nbr_db[$device['context_name']][$oid].'|'.$ospf_nbr_poll[$oid]."\n"); + + if ($ospf_nbr_db[$device['context_name']][$oid] != $ospf_nbr_poll[$oid]) { + // If data has changed, build a query + $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; + // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + } + } + + if ($ospf_nbr_update) { + dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id, $device['context_name'])); + echo 'U'; + unset($ospf_nbr_update); + } + else { + echo '.'; + } + + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; + } + else { + dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'], $device['context_name'])); + echo '-'; + }//end if + }//end foreach + }//end if + unset($ospf_nbrs_db); + unset($ospf_nbrs_poll); +} +unset($device['context_name']); +unset($vrfs_lite_cisco); // Create device-wide statistics RRD $filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('ospf-statistics.rrd'); diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 6d1c32238..72e3b17a5 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -750,8 +750,14 @@ function snmp_gen_auth(&$device) { $cmd = ''; if ($device['snmpver'] === 'v3') { + $cmd = " -v3 -n '' -l '".$device['authlevel']."'"; - + + //add context if exist context + if(key_exists('context_name', $device)){ + $cmd = " -v3 -n '".$device['context_name']."' -l '".$device['authlevel']."'"; + } + if ($device['authlevel'] === 'noAuthNoPriv') { // We have to provide a username anyway (see Net-SNMP doc) // FIXME: There are two other places this is set - why are they ignored here? From 2820689383f1e6a2648265122118a6a1acbe1712 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 004/104] Adding sql-schema --- sql-schema/093.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sql-schema/093.sql diff --git a/sql-schema/093.sql b/sql-schema/093.sql new file mode 100644 index 000000000..5dfced746 --- /dev/null +++ b/sql-schema/093.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); +ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_mac ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers_cbgp ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas DROP INDEX device_area, ADD UNIQUE KEY `device_area` (`device_id`,`ospfAreaId`,`context_name`); +ALTER TABLE ospf_instances ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_instances DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_instance_id`,`context_name`); +ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); +ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; \ No newline at end of file From 11097f6315fcde3fca4fa9cad67dfd84a2ed4194 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:05:14 +0100 Subject: [PATCH 005/104] Adding mibs --- mibs/CISCO-BRIDGE-DOMAIN-MIB | 450 +++++++++++++++++ mibs/CISCO-CONTEXT-MAPPING-MIB | 853 +++++++++++++++++++++++++++++++++ 2 files changed, 1303 insertions(+) create mode 100644 mibs/CISCO-BRIDGE-DOMAIN-MIB create mode 100644 mibs/CISCO-CONTEXT-MAPPING-MIB diff --git a/mibs/CISCO-BRIDGE-DOMAIN-MIB b/mibs/CISCO-BRIDGE-DOMAIN-MIB new file mode 100644 index 000000000..68e9ddb9c --- /dev/null +++ b/mibs/CISCO-BRIDGE-DOMAIN-MIB @@ -0,0 +1,450 @@ +-- ***************************************************************** +-- CISCO-BRIDGE-DOMAIN-MIB.my : Cisco Bridge Domain MIB +-- +-- Oct 2007, Madhavi Dokku +-- +-- Copyright (c) 2007 by Cisco Systems, Inc. +-- +-- All rights reserved. +-- ***************************************************************** + +CISCO-BRIDGE-DOMAIN-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE, + Unsigned32 + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + TEXTUAL-CONVENTION, + TruthValue, + RowStatus, + StorageType + FROM SNMPv2-TC + ifIndex + FROM IF-MIB + ciscoMgmt + FROM CISCO-SMI; + + +ciscoBridgeDomainMIB MODULE-IDENTITY + LAST-UPDATED "200712290000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + Tel: +1 800 553-NETS + + E-mail: cs-ethermibs@cisco.com" + DESCRIPTION + "A bridge domain is one of the means by which it is possible + to define a broadcast domain on a bridging device. It is an + alternative to 802.1D bridge-groups and to 802.1Q VLAN + bridging. + + Bridge domain is the service specification, and specifies the + broadcast domain number on which this frame of this particular + service instance must be made available on. The physical and + virtual interfaces that can comprise a bridge domain are + heterogeneous in nature comprising Ethernet service instances, + WAN Virtual Circuit for ATM or Frame Relay and VFIs. However, + the frame encapsulations for all interface types are + essentially Ethernet. + + Without bridge-domains, VLANs would have to be globally unique + per device and one would only be restricted to the theoretical + maximum of 4095 VLANs for single tagged traffic. However + with the introduction of bridge-domains, one can + associate a service instance with a bridge-domain and all + service instances in the same bridge-domain form a + broadcast domain. Bridge-domain ID determines the + broadcast domain and the VLAN id is merely used to match + and map traffic. With bridge domain feature configured + VLAN IDs would be unique per interface only and not globally. + Thus bridge domains make VLAN ids have only local + significance per port + + + Differences between Bridge Domains and 802.1AD Bridges: + ======================================================= + 1. Scope of the VLAN technology which uses 802.1 AD is global to + the box. + But in case of Bridge domain, the scope of vlan is local to + interface + + 2. Switchport 802.1AD restricts the number of broadcast domain + on a box to 4095. + However, with Bridge domains, we can have up to 16k broadcast + domain. + + 3. Under a single Bridge domain service instance, there can be + flexible service mapping criterion.(i.e match based on + outer vlan, outer cos, inner vlan, inner cos and payload + ethertype). + Whereas in case of switch port 802.1AD/dot1q this is not + supported. + + Similarities between Bridge Domains and 802.1AD Bridges: + ======================================================= + + 1. Both use the same MAC address lookup for forwarding. + + 2. Both work with protocols like STP, DTP etc. + + 3. Both of them classify 'ports' in a system into Bridges/Bridge + Domains. + + Ethernet service instance is the instantiation of an Ethernet + virtual circuit on a given port on a given router. In other + words, an Ethernet service instance is an object that holds + information about the layer 2 service that is being offered + on a given port of a given router as part of a given Ethernet + virtual circuit. Bridge domains feature is currently supported + on ethernet service instances only and can be later extented + to other interfaces like ATM and Frame Relay. + + This MIB helps the network management personnel to find out the + details of various broadcast domains configured in the network. + + Definition of terms and acronyms: + + ATM: Asynchronous Transfer mode + + BD: Bridge Domain + + C-mac: Customer MAC + + EVC: Ethernet Virtual Circuit + + FR: Frame Relay + + SH: Split Horizon + + VFI: Virtual Forwarding Instance + + VLAN: Virtual Local Area Network + + WAN: Wide Area Network" + REVISION "200712290000Z" + DESCRIPTION + "Modified the MIB description with details on similarities and + differences between Bridge Domains and 802.1AD Bridges." + REVISION "200712040000Z" + DESCRIPTION + "Initial version of this MIB module." + ::= { ciscoMgmt 642 } + + +ciscoBdMIBNotifications OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 0 } + +ciscoBdMIBObjects OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 1 } + +ciscoBdMIBConformance OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 2 } + +cbdSystemInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 1 } + +cbdMemberInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 2 } + + +-- Textual Conventions + +CbdType ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "Defines the different types of bridge domain members: + + 'other': none of the following + + 'ether': Ethernet Service Instance + + 'atmVc': ATM Virtual connection + + 'frVc': Frame Relay Virtual Connection" + SYNTAX INTEGER { + other(1), + ether(2), + atmVc(3), + frVc(4) + } + +cbdMembersConfigured OBJECT-TYPE + SYNTAX Unsigned32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the number of bridge domain + members configured on this bridge domain." + ::= { cbdSystemInfo 1 } +-- Member Info Table + +cbdMemberInfoTable OBJECT-TYPE + SYNTAX SEQUENCE OF CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table provides the bridge domain member attributes + of the members currently configured for each bridge + domain." + ::= { cbdMemberInfo 1 } + +cbdMemberInfoEntry OBJECT-TYPE + SYNTAX CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A conceptual row in cbdMemberInfoTable. This is indexed + by ifIndex and cbdSIIndex. Each row is created when a bridge + domain member is configured under a service instance." + INDEX { + ifIndex, + cbdSIIndex + } + ::= { cbdMemberInfoTable 1 } + +CbdMemberInfoEntry ::= SEQUENCE { + cbdSIIndex Unsigned32, + cbdMemberType CbdType, + cbdMemberOperState INTEGER , + cbdMemberAdminState INTEGER , + cbdMemberSplitHorizon TruthValue, + cbdMemberSplitHorizonNum Unsigned32, + cbdMemberStorageType StorageType, + cbdMemberStatus RowStatus, + cbdMembercMac TruthValue +} + +cbdSIIndex OBJECT-TYPE + SYNTAX Unsigned32 (1..4294967295 ) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This object indicates an arbitary index that uniquely + identifies the Service Instance to which this bridge domain + member belongs to." + ::= { cbdMemberInfoEntry 1 } + +cbdMemberType OBJECT-TYPE + SYNTAX CbdType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the type of the bridge domain member + like ATM VC, Frame Relay VC, or Ethernet service." + DEFVAL { other } + ::= { cbdMemberInfoEntry 2 } + +cbdMemberOperState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the operational state of the bridge + domain Member. Operational state of the Bridge domain member + is same as the operational state of the underlying service + instance. Bridge domain members are configured under service + instances and multiple service instances can be attached to a + single physical interface defining various kinds of services. + Bridge domain members have many to one relationship with + interface + Indexes. When ifOperStatus of the underlying interface is down, + the state of cbdMemberOperState should be down. When + ifOperStatus + of the underlying interface is up, cbdMemberOperState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is an unknown state. + + 'up': the bridge domain member is fully operational and + able to bridge the traffic. This means that both the + physical interface and the underlying service instance + are administratively up. + + 'down': the Bridge Domain member is down and not + capable of bridging. This state means either the underlying + service instance is down or the interface is down." + ::= { cbdMemberInfoEntry 3 } + +cbdMemberAdminState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the administrative state of the + bridge domain Member. Admin state of the Bridge domain member + is same as the admin state of the underlying service instance. + Bridge domain members are configured under service instances + and multiple service instances can be attached to a single + physical interface defining various kinds of services. Bridge + Domain members have many to one relationship with interface + Indexes. When ifAdminStatus of the unerlying interface is down + the state of cbdMemberAdminState should be down. When ifOperStatus + of the underlying interface is up cbdMemberAdminState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is in unknown + administrative state. + + 'up': the Bridge Domain member is administratively up. This + means that both the physical interface and the underlying service + instance are administratively up. + + 'admindown': the Bridge Domain member is down as it is + administratively configured to be down and is not + capable of bridging. This means that either the underlying + service instance is configured as administratively down or + the physical interface is configured as administratively + down." + ::= { cbdMemberInfoEntry 4 } + +cbdMemberSplitHorizon OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates whether split horizon is + configured on this bridge domain member." + ::= { cbdMemberInfoEntry 5 } + +cbdMemberSplitHorizonNum OBJECT-TYPE + SYNTAX Unsigned32 (0..65535 ) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the split horizon number if + configured on the bridge domain member. Split horizon + is used to avoid sending traffic between interfaces. + Frames are not forwarded to the members belonging to the + same split horizon group." + DEFVAL { 0 } + ::= { cbdMemberInfoEntry 6 } + +cbdMemberStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object specifies the storage type of this conceptual + row. This object can only have a value 'nonVolatile'. Other + values are not applicable for this conceptual row and are + not supported." + DEFVAL { nonVolatile } + ::= { cbdMemberInfoEntry 7 } + +cbdMemberStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object enables the SNMP agent to create, modify, + and delete rows in the cbdMemberInfoTable." + DEFVAL { active } + ::= { cbdMemberInfoEntry 8 } + +cbdMembercMac OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates if cmac is configured on this + bridge domain member. Cmac denotes if this bridge domain is + configured as a customer domain." + ::= { cbdMemberInfoEntry 9 } + + +-- Notifications + +ciscoBdNotificationPrefix OBJECT IDENTIFIER + ::= { ciscoBdMIBNotifications 0 } + +-- Conformance + +ciscoBdMIBCompliances OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 1 } + +ciscoBdMIBGroups OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 2 } + + +ciscoBdMIBComplianceRev1 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-BRIDGE-DOMAIN-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cbdSystemInfoGroup, + cbdMemberInfoGroup + } + ::= { ciscoBdMIBCompliances 1 } + +-- Units of Conformance + +cbdSystemInfoGroup OBJECT-GROUP + OBJECTS { cbdMembersConfigured } + STATUS current + DESCRIPTION + "This group contain information about bridge domain." + ::= { ciscoBdMIBGroups 1 } + +cbdMemberInfoGroup OBJECT-GROUP + OBJECTS { + cbdMemberType, + cbdMemberOperState, + cbdMemberAdminState, + cbdMemberSplitHorizon, + cbdMemberSplitHorizonNum, + cbdMemberStorageType, + cbdMemberStatus, + cbdMembercMac + } + STATUS current + DESCRIPTION + "This group contain information related to bridge domain + members." + ::= { ciscoBdMIBGroups 2 } + +END + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mibs/CISCO-CONTEXT-MAPPING-MIB b/mibs/CISCO-CONTEXT-MAPPING-MIB new file mode 100644 index 000000000..94451564d --- /dev/null +++ b/mibs/CISCO-CONTEXT-MAPPING-MIB @@ -0,0 +1,853 @@ +-- ***************************************************************** +-- CISCO-CONTEXT-MAPPING-MIB.my: Cisco Context Mapping MIB +-- +-- January 2005, Chinna Pellacuru. +-- +-- May 2008, Sheethal Gunjal. +-- +-- Copyright (c) 2004-2005, 2008 by cisco Systems Inc. +-- All rights reserved. +-- +-- **************************************************************** + +CISCO-CONTEXT-MAPPING-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + SnmpAdminString + FROM SNMP-FRAMEWORK-MIB + RowStatus, + StorageType + FROM SNMPv2-TC + CiscoBridgeDomain + FROM CISCO-TC + ciscoMgmt + FROM CISCO-SMI; + + +ciscoContextMappingMIB MODULE-IDENTITY + LAST-UPDATED "200811220000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + + Tel: +1 800 553-NETS + + E-mail: cs-snmp@cisco.com" + DESCRIPTION + "A single SNMP agent sometimes needs to support multiple + instances of the same MIB module, and does so through the + use of multiple SNMP contexts. This typically occurs because + the technology has evolved to have extra dimension(s), i.e., + one or more extra data and/or identifier values which are + different in the different contexts, but were not defined in + INDEX clause(s) of the original MIB module. In such cases, + network management applications need to know the specific + data/identifier values in each context, and this MIB module + provides mapping tables which contain that information. + + Within a network there can be multiple Virtual Private + Networks (VPNs) configured using Virtual Routing and + Forwarding Instances (VRFs). Within a VPN there can be + multiple topologies when Multi-topology Routing (MTR) is + used. Also, Interior Gateway Protocols (IGPs) can have + multiple protocol instances running on the device. + A network can have multiple broadcast domains configured + using Bridge Domain Identifiers. + + With MTR routing, VRFs, and Bridge domains, a router now + needs to support multiple instances of several existing + MIB modules, and this can be achieved if the router's SNMP + agent provides access to each instance of the same MIB module + via a different SNMP context (see Section 3.1.1 of RFC 3411). + For MTR routing, VRFs, and Bridge domains, a different SNMP + context is needed depending on one or more of the following: + the VRF, the topology-identifier, the routing protocol instance, + and the bridge domain identifier. + In other words, the router's management information can be + accessed through multiple SNMP contexts where each such + context represents a specific VRF, a specific + topology-identifier, a specific routing protocol instance + and/or a bridge domain identifier. This MIB module provides + a mapping of each such SNMP context to the corresponding VRF, + the corresponding topology, the corresponding routing protocol + instance, and the corresponding bridge domain identifier. + Some SNMP contexts are independent of VRFs, independent of + a topology, independent of a routing protocol instance, or + independent of a bridge domain and in such a case, the mapping + is to the zero length string. + + With the Cisco package licensing strategy, the features + available in the image are grouped into multiple packages + and each packages can be managed to operate at different + feature levels based on the available license. This MIB + module provides option to associate an SNMP context to a + feature package group. This will allow manageability of + license MIB objects specific to a feature package group. + + As technology evolves more we may need additional + identifiers to identify the context. Then we would need + to add those additional identifiers into the mapping." + REVISION "200811220000Z" + DESCRIPTION + "Added New Table cContextMappingLicenseGroupTable + to provide SNMP Context support for license package groups. + + Added cContextMappingLicenseGroupDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev2 in MODULE-COMPLIANCE + + Updated the MIB description to indicate the use of + the above additions" + REVISION "200805300000Z" + DESCRIPTION + "Add cContextMappingBridgeInstanceTable. + + Added cContextMappingBridgeInstanceDataGroup. + Deprecated cContextMappingMIBComplianceRev1 and added + cContextMappingMIBComplianceRev2 compliance statement." + REVISION "200802010000Z" + DESCRIPTION + "Added New Table cContextMappingBridgeDomainTable + to provide SNMP context support to the Bridge Domain. + + Added cContextMappingBridgeDomainDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev1 in MODULE-COMPLIANCE" + REVISION "200503170000Z" + DESCRIPTION + "Initial version of the MIB module." + ::= { ciscoMgmt 468 } + + +cContextMappingMIBObjects OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 1 } + +cContextMappingMIBConformance OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 2 } + + +cContextMappingTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which VRF, topology, and routing protocol instance. + + This table is indexed by SNMP VACM context. + + Configuring a row in this table for an SNMP context + does not require that the context be already defined, + i.e., a row can be created in this table for a context + before the corresponding row is created in RFC 3415's + vacmContextTable. + + To create a row in this table, a manager must set + cContextMappingRowStatus to either 'createAndGo' or + 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingRowStatus to 'destroy'." + ::= { cContextMappingMIBObjects 1 } + +cContextMappingEntry OBJECT-TYPE + SYNTAX CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the corresponding VRF, + the corresponding topology, and the corresponding routing + protocol instance." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingTable 1 } + +CContextMappingEntry ::= SEQUENCE { + cContextMappingVacmContextName SnmpAdminString, + cContextMappingVrfName SnmpAdminString, + cContextMappingTopologyName SnmpAdminString, + cContextMappingProtoInstName SnmpAdminString, + cContextMappingStorageType StorageType, + cContextMappingRowStatus RowStatus +} + +cContextMappingVacmContextName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The vacmContextName given to the SNMP context. + + This is a human readable name identifying a particular + SNMP VACM context at a particular SNMP entity. + The empty contextName (zero length) represents the + default context." + ::= { cContextMappingEntry 1 } + +cContextMappingVrfName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the VRF to which the SNMP context + is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this VRF. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any VRF." + DEFVAL { ''H } + ::= { cContextMappingEntry 2 } + +cContextMappingTopologyName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the topology to which the SNMP + context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this topology. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any topology." + DEFVAL { ''H } + ::= { cContextMappingEntry 3 } + +cContextMappingProtoInstName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the protocol instance to which the + SNMP context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this protocol instance. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any protocol instance." + DEFVAL { ''H } + ::= { cContextMappingEntry 4 } + +cContextMappingStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingEntry 5 } + +cContextMappingRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingEntry 6 } + + + +cContextMappingBridgeDomainTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which bridge domain. + + A Bridge Domain is one of the means by which it is possible + to define an Ethernet broadcast domain on a bridging device. + A network can have multiple broadcast domains configured. + This table helps the network management personnel to find + out the details of various broadcast domains configured + in the network. + + An entry need to exist in cContextMappingTable, to create + an entry in this table." + ::= { cContextMappingMIBObjects 2 } + +cContextMappingBridgeDomainEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge domain. + + To create a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeDomainTable 1 } + +CContextMappingBridgeDomainEntry ::= SEQUENCE { + cContextMappingBridgeDomainIdentifier CiscoBridgeDomain, + cContextMappingBridgeDomainStorageType StorageType, + cContextMappingBridgeDomainRowStatus RowStatus +} + +cContextMappingBridgeDomainIdentifier OBJECT-TYPE + SYNTAX CiscoBridgeDomain + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the bridge domain to which the SNMP context is + mapped to." + REFERENCE "CISCO-BRIDGE-DOMAIN-MIB" + ::= { cContextMappingBridgeDomainEntry 1 } + +cContextMappingBridgeDomainStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeDomainEntry 2 } + +cContextMappingBridgeDomainRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeDomainEntry 3 } + + + +cContextMappingBridgeInstanceTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on mapping between + cContextMappingVacmContextName and bridge instance. + + Bridge instance is an instance of a physical or logical + bridge which has unique bridge-id. + + If an entry is deleted from cContextMappingTable, the + corresponding entry in this table will also get deleted. + + If an entry needs to be created in this table, the + corresponding entry must exist in cContextMappingTable." + REFERENCE "BRIDGE-MIB" + ::= { cContextMappingMIBObjects 3 } + +cContextMappingBridgeInstanceEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge instance. + + To create a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeInstanceTable 1 } + +CContextMappingBridgeInstanceEntry ::= SEQUENCE { + cContextMappingBridgeInstName SnmpAdminString, + cContextMappingBridgeInstStorageType StorageType, + cContextMappingBridgeInstRowStatus RowStatus +} + +cContextMappingBridgeInstName OBJECT-TYPE + SYNTAX SnmpAdminString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The object identifies the name given to bridge + instance to which the SNMP context is mapped to. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this bridge instance. + + When the value of this object is a zero length + string, it indicates that the SNMP context is + independent of any bridge instances." + ::= { cContextMappingBridgeInstanceEntry 1 } + +cContextMappingBridgeInstStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeInstanceEntry 2 } + +cContextMappingBridgeInstRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeInstanceEntry 3 } + + + +cContextMappingLicenseGroupTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which License Group. + Group level licensing is used where each + Technology Package is enabled via a License." + ::= { cContextMappingMIBObjects 4 } + +cContextMappingLicenseGroupEntry OBJECT-TYPE + SYNTAX CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + CContextMappingVacmContextName to the + corresponding License Group." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingLicenseGroupTable 1 } + +CContextMappingLicenseGroupEntry ::= SEQUENCE { + cContextMappingLicenseGroupName SnmpAdminString, + cContextMappingLicenseGroupStorageType StorageType, + cContextMappingLicenseGroupRowStatus RowStatus +} + +cContextMappingLicenseGroupName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the Group to which the SNMP context + is mapped. + + Feature sets from all groups will be combined to form + universal image. User can configure multiple groups as needed. + + For example: In Next generation ISRs will use + the universal image package level licensing model + for its licensing need. Each group has + the feature set needed for that specific technology. + Feature sets from different groups are combined to + form universal image and each feature set for a group + can be enabled using a valid license key. There will + be a base level ipbase package in which the router + boots with out any license key. + + The following are the different Technology Groups. + 1.crypto + 2.data + 3.ip + 4.legacy + 5.novpn-security + 6.security + 7.uc" + ::= { cContextMappingLicenseGroupEntry 1 } + +cContextMappingLicenseGroupStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingLicenseGroupEntry 2 } + +cContextMappingLicenseGroupRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingLicenseGroupEntry 3 } + + +-- Conformance + +cContextMappingMIBCompliances OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 1 } + +cContextMappingMIBGroups OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 2 } + + +-- Compliance + +cContextMappingMIBCompliance MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { cContextMappingDataGroup } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 1 } + +cContextMappingMIBComplianceRev1 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB. This compliance statement + is superceded by cContextMappingMIBComplianceRev2." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 2 } + +cContextMappingMIBComplianceRev2 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + ::= { cContextMappingMIBCompliances 3 } + +cContextMappingMIBComplianceRev3 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup, + cContextMappingLicenseGroupDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + + OBJECT cContextMappingLicenseGroupName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 4 } + +-- Units of Conformance + +cContextMappingDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingVrfName, + cContextMappingTopologyName, + cContextMappingProtoInstName, + cContextMappingStorageType, + cContextMappingRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding VRF, the corresponding topology, + and the corresponding routing protocol instance." + ::= { cContextMappingMIBGroups 1 } + +cContextMappingBridgeDomainDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeDomainIdentifier, + cContextMappingBridgeDomainStorageType, + cContextMappingBridgeDomainRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge domain." + ::= { cContextMappingMIBGroups 2 } + +cContextMappingBridgeInstanceDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeInstName, + cContextMappingBridgeInstStorageType, + cContextMappingBridgeInstRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge instance." + ::= { cContextMappingMIBGroups 3 } + +cContextMappingLicenseGroupDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingLicenseGroupName, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding LicenseGroupName." + ::= { cContextMappingMIBGroups 4 } + +END + + + + + + + + From b637ce63e0699f67234a4cc2d3993b67dc59d98b Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:13:53 +0100 Subject: [PATCH 006/104] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 158 ++++--- includes/discovery/bgp-peers.inc.php | 378 ++++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 114 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 125 +++-- includes/polling/ospf.inc.php | 548 +++++++++++----------- includes/snmp.inc.php | 8 +- 11 files changed, 957 insertions(+), 682 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index 79fd3ee07..be78f254f 100644 --- a/includes/common.php +++ b/includes/common.php @@ -290,6 +290,16 @@ function device_by_id_cache($device_id, $refresh = '0') { } else { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id)); + + //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time + $vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id)); + $device['vrf_lite_cisco'] = array(); + if(!empty($vrfs_lite_cisco)){ + foreach ($vrfs_lite_cisco as $vrf){ + $device['vrf_lite_cisco'][$vrf['context_name']] = $vrf; + } + } + $cache['devices']['id'][$device_id] = $device; } return $device; diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 2e9282b35..f91369c4a 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ $config['enable_pseudowires'] = 1; // Enable Pseudowires $config['enable_vrfs'] = 1; // Enable VRFs +$config['enable_vrf_lite_cisco'] = 1; +// Enable VRF lite cisco $config['enable_printers'] = 0; // Enable Printer support $config['enable_sla'] = 0; @@ -732,6 +734,7 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; // $config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index 69b0d9b75..c60d4ca95 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ unset($mac_table); echo 'ARP Table : '; -$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); -$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); -$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); - -foreach (explode("\n", $ipNetToMedia_data) as $data) { - list($oid, $mac) = explode(' ', $data); - list($if, $first, $second, $third, $fourth) = explode('.', $oid); - $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; - if ($ip != '...') { - $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); - - list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); - $m_a = zeropad($m_a); - $m_b = zeropad($m_b); - $m_c = zeropad($m_c); - $m_d = zeropad($m_d); - $m_e = zeropad($m_e); - $m_f = zeropad($m_f); - $md_a = hexdec($m_a); - $md_b = hexdec($m_b); - $md_c = hexdec($m_c); - $md_d = hexdec($m_d); - $md_e = hexdec($m_e); - $md_f = hexdec($m_f); - $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; - - $mac_table[$if][$mac]['ip'] = $ip; - $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; - $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; - $mac_table[$if][$mac]['cleanmac'] = $clean_mac; - $port_id = $interface['port_id']; - $mac_table[$port_id][$clean_mac] = 1; - - if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) { - // Commented below, no longer needed but leaving for reference. - // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; - $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id'])); - - if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { - d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); - - log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); - } - - dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); - echo '.'; - } - else if (isset($interface['port_id'])) { - echo '+'; - // echo("Add MAC $mac\n"); - $insert_data = array( - 'port_id' => $interface['port_id'], - 'mac_address' => $clean_mac, - 'ipv4_address' => $ip, - ); - - dbInsert($insert_data, 'ipv4_mac'); - }//end if - }//end if -}//end foreach - -$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'"; -foreach (dbFetchRows($sql) as $entry) { - $entry_mac = $entry['mac_address']; - $entry_if = $entry['port_id']; - if (!$mac_table[$entry_if][$entry_mac]) { - dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); - d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); - - echo '-'; - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; + + $ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); + $ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); + $ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); -echo "\n"; -unset($mac); + foreach (explode("\n", $ipNetToMedia_data) as $data) { + list($oid, $mac) = explode(' ', $data); + list($if, $first, $second, $third, $fourth) = explode('.', $oid); + $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; + if ($ip != '...') { + $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); + + list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); + $m_a = zeropad($m_a); + $m_b = zeropad($m_b); + $m_c = zeropad($m_c); + $m_d = zeropad($m_d); + $m_e = zeropad($m_e); + $m_f = zeropad($m_f); + $md_a = hexdec($m_a); + $md_b = hexdec($m_b); + $md_c = hexdec($m_c); + $md_d = hexdec($m_d); + $md_e = hexdec($m_e); + $md_f = hexdec($m_f); + $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; + + $mac_table[$if][$mac]['ip'] = $ip; + $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; + $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; + $mac_table[$if][$mac]['cleanmac'] = $clean_mac; + $port_id = $interface['port_id']; + $mac_table[$port_id][$clean_mac] = 1; + + if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']))) { + // Commented below, no longer needed but leaving for reference. + // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; + $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=? AND `context_name`= ?', array($ip, $interface['port_id']), $device['context_name']); + + if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { + d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); + + log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); + } + + dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name'])); + echo '.'; + } + else if (isset($interface['port_id'])) { + echo '+'; + // echo("Add MAC $mac\n"); + $insert_data = array( + 'port_id' => $interface['port_id'], + 'mac_address' => $clean_mac, + 'ipv4_address' => $ip, + 'context_name' => $device['context_name'], + ); + + dbInsert($insert_data, 'ipv4_mac'); + }//end if + }//end if + }//end foreach + + $sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = ' AND `context_name`= ?".$device['device_id']." AND M.context_name='". $device['context_name'] ."'"; + foreach (dbFetchRows($sql) as $entry) { + $entry_mac = $entry['mac_address']; + $entry_if = $entry['port_id']; + if (!$mac_table[$entry_if][$entry_mac]) { + dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ? AND `context_name`= ?', array($entry_if, $entry_mac, $device['context_name'])); + d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); + + echo '-'; + } + } + echo "\n"; + unset($mac); + unset($device['context_name']); +} +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf..dd341715d 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -3,232 +3,246 @@ if ($config['enable_bgp']) { // Discover BGP peers echo 'BGP Sessions : '; - + + if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; + } + else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); + } + $bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB', $config['mibdir'])); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + if (is_numeric($bgpLocalAs)) { + echo "AS$bgpLocalAs "; - if (is_numeric($bgpLocalAs)) { - echo "AS$bgpLocalAs "; - - if ($bgpLocalAs != $device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); - echo 'Updated AS '; - } - - $peer2 = false; - $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); - if (empty($peers_data)) { - $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); - } - else { - $peer2 = true; - } - - d_echo("Peers : $peers_data \n"); - - $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); - $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - - foreach (explode("\n", $peers) as $peer) { - if ($peer2 === true) { - list($ver, $peer) = explode('.', $peer, 2); + if ($bgpLocalAs != $device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); + echo 'Updated AS '; } - list($peer_ip, $peer_as) = explode(' ', $peer); - if (strstr($peer_ip, ':')) { - $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); - $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); - $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + $peer2 = false; + $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); + if (empty($peers_data)) { + $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); + } + else { + $peer2 = true; } - if ($peer && $peer_ip != '0.0.0.0') { - d_echo("Found peer $peer_ip (AS$peer_as)\n"); + d_echo("Peers : $peers_data \n"); - $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, - 'ver' => $ver, - ); - } - } + $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); + $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - if ($device['os'] == 'junos') { - // Juniper BGP4-V2 MIB - // FIXME: needs a big cleanup! also see below. - // FIXME: is .0.ipv6 the only possible value here? - $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); foreach (explode("\n", $peers) as $peer) { - list($peer_ip_snmp, $peer_as) = explode(' ', $peer); + if ($peer2 === true) { + list($ver, $peer) = explode('.', $peer, 2); + } - // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. - $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + list($peer_ip, $peer_as) = explode(' ', $peer); + if (strstr($peer_ip, ':')) { + $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); + $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); + $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + } - if ($peer) { + if ($peer && $peer_ip != '0.0.0.0') { d_echo("Found peer $peer_ip (AS$peer_as)\n"); $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, + 'ip' => $peer_ip, + 'as' => $peer_as, + 'ver' => $ver, ); } } - } - } - else { - echo 'No BGP on host'; - if ($device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); - echo ' (Removed ASN) '; - } - } - // Process disovered peers - if (isset($peerlist)) { - foreach ($peerlist as $peer) { - $astext = get_astext($peer['as']); + if ($device['os'] == 'junos') { + // Juniper BGP4-V2 MIB + // FIXME: needs a big cleanup! also see below. + // FIXME: is .0.ipv6 the only possible value here? + $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); + foreach (explode("\n", $peers) as $peer) { + list($peer_ip_snmp, $peer_as) = explode(' ', $peer); - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') { - $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as']), 'bgpPeers'); - if ($config['autodiscovery']['bgp'] === true) { - $name = gethostbyaddr($peer['ip']); - $remote_device_id = discover_new_device($name, $device, 'BGP'); + // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. + $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + + if ($peer) { + d_echo("Found peer $peer_ip (AS$peer_as)\n"); + + $peerlist[] = array( + 'ip' => $peer_ip, + 'as' => $peer_as, + ); + } + } + } + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; + } + } + + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); + + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $device['context_name'])) < '1') { + $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'],'context_name' => $device['context_name']), 'bgpPeers'); + if ($config['autodiscovery']['bgp'] === true) { + $name = gethostbyaddr($peer['ip']); + $remote_device_id = discover_new_device($name, $device, 'BGP'); + } + + echo '+'; + } + else { + $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); + echo '.'; } - echo '+'; - } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; - } + if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { + if ($device['os_group'] == 'cisco') { + // Get afi/safi and populate cbgp on cisco ios (xe/xr) + unset($af_list); - if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { - if ($device['os_group'] == 'cisco') { - // Get afi/safi and populate cbgp on cisco ios (xe/xr) - unset($af_list); - - if ($peer2 === true) { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - else { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - - d_echo('afi data :: '); - d_echo($af_data); - - foreach ($af_data as $k => $v) { if ($peer2 === true) { - list(,$k) = explode('.', $k, 2); + $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); + } + else { + $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); } - d_echo("AFISAFI = $k\n"); + d_echo('afi data :: '); + d_echo($af_data); - $afisafi_tmp = explode('.', $k); - $safi = array_pop($afisafi_tmp); - $afi = array_pop($afisafi_tmp); - $bgp_ip = str_replace(".$afi.$safi", '', $k); - $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); - $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); - $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); - if ($afi && $safi && $bgp_ip == $peer['ip']) { - $af_list[$bgp_ip][$afi][$safi] = 1; + foreach ($af_data as $k => $v) { + if ($peer2 === true) { + list(,$k) = explode('.', $k, 2); + } + + d_echo("AFISAFI = $k\n"); + + $afisafi_tmp = explode('.', $k); + $safi = array_pop($afisafi_tmp); + $afi = array_pop($afisafi_tmp); + $bgp_ip = str_replace(".$afi.$safi", '', $k); + $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); + $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); + $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); + if ($afi && $safi && $bgp_ip == $peer['ip']) { + $af_list[$bgp_ip][$afi][$safi] = 1; + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=? AND `context_name`=?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])) == 0) { + dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); + } + } + } + } + + if ($device['os'] == 'junos') { + $safis[1] = 'unicast'; + $safis[2] = 'multicast'; + + if (!isset($j_peerIndexes)) { + $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + + foreach ($j_bgp as $index => $entry) { + switch ($entry['jnxBgpM2PeerRemoteAddrType']) { + case 'ipv4': + $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); + d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; + break; + + case 'ipv6': + $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); + $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); + $ip6 = Net_IPv6::compress($ip6); + d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; + + default: + echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; + break; + } + } + } + + if (!isset($j_afisafi)) { + $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + foreach (array_keys($j_prefixes) as $key) { + list($index,$afisafi) = explode('.', $key, 2); + $j_afisafi[$index][] = $afisafi; + } + } + + foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { + list ($afi,$safi) = explode('.', $afisafi); + $safi = $safis[$safi]; + $af_list[$afi][$safi] = 1; if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); } } } - } - if ($device['os'] == 'junos') { - $safis[1] = 'unicast'; - $safis[2] = 'multicast'; - - if (!isset($j_peerIndexes)) { - $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - - foreach ($j_bgp as $index => $entry) { - switch ($entry['jnxBgpM2PeerRemoteAddrType']) { - case 'ipv4': - $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); - d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; - break; - - case 'ipv6': - $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); - $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); - $ip6 = Net_IPv6::compress($ip6); - d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; - break; - - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - break; - } + $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND `context_name` = '" . $device['context_name'] . "'"; + foreach (dbFetchRows($af_query) as $entry) { + $afi = $entry['afi']; + $safi = $entry['safi']; + if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { + dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])); } } - - if (!isset($j_afisafi)) { - $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - foreach (array_keys($j_prefixes) as $key) { - list($index,$afisafi) = explode('.', $key, 2); - $j_afisafi[$index][] = $afisafi; - } - } - - foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { - list ($afi,$safi) = explode('.', $afisafi); - $safi = $safis[$safi]; - $af_list[$afi][$safi] = 1; - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { - dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); - } - } - } - - $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"; - foreach (dbFetchRows($af_query) as $entry) { - $afi = $entry['afi']; - $safi = $entry['safi']; - if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { - dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); - } } } + + unset($j_afisafi); + unset($j_prefixes); + unset($j_bgp); + unset($j_peerIndexes); } - unset($j_afisafi); - unset($j_prefixes); - unset($j_bgp); - unset($j_peerIndexes); - } + // Delete removed peers + $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."' AND `context_name` = '" . $device['context_name'] . "'"; - // Delete removed peers - $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; + foreach (dbFetchRows($sql) as $entry) { + unset($exists); + $i = 0; - foreach (dbFetchRows($sql) as $entry) { - unset($exists); - $i = 0; + while ($i < count($peerlist) && !isset($exists)) { + if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { + $exists = 1; + } - while ($i < count($peerlist) && !isset($exists)) { - if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { - $exists = 1; + $i++; } - $i++; + if (!isset($exists)) { + dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + echo '-'; + } } - if (!isset($exists)) { - dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - echo '-'; - } + unset($peerlist); + + echo "\n"; + unset($device['context_name']); } - - unset($peerlist); - - echo "\n"; + unset($device['context_name']); + unset($vrfs_c); } diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php new file mode 100644 index 000000000..ae2aff0e4 --- /dev/null +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -0,0 +1,142 @@ + and Mathieu Millet +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . */ + + +global $debug; + +// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco +if ($config['enable_vrf_lite_cisco']) { + + $ids = array(); + + // For the moment only will be cisco and the version 3 + if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') { + + echo ("VRF lite cisco : \n"); + $mib = "SNMP-COMMUNITY-MIB"; + + $mib = "CISCO-CONTEXT-MAPPING-MIB"; + //-Osq because if i put the n the oid from the first command is not the same of this one + $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); + $listVrf = str_replace("cContextMappingVrfName.", "", $listVrf); + $listVrf = str_replace('"', "", $listVrf); + $listVrf = trim($listVrf); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); + } + + $tableVrf; + foreach (explode("\n", $listVrf) as $lineVrf) { + $tmpVrf = explode(" ", $lineVrf, 2); + //the $tmpVrf[0] will be the context + if (count($tmpVrf) == 2 && !empty($tmpVrf[1])) { + $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1]; + } + } + + unset($listVrf); + + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); + $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); + $listIntance = str_replace('"', "", $listIntance); + $listIntance = trim($listIntance); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + } + + + foreach (explode("\n", $listIntance) as $lineIntance) { + $tmpIntance = explode(" ", $lineIntance, 2); + //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance + if (count($tmpIntance) == 2 && !empty($tmpIntance[1])) { + $tableVrf[$tmpIntance[0]]['intance_name'] = $tmpIntance[1]; + } + } + unset($listIntance); + + + foreach ($tableVrf as $context => $vrf) { + + + + if ($debug) { + + echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n"); + } + + $tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", array( + $device ['device_id'], + $context + )); + if (!empty($tmpVrf)) { + + $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id']; + + $vrfUpdate=array(); + + foreach ($vrfUpdate as $key => $value) { + if($vrf[$key]!=$value){ + $vrfUpdate[$key]=$value; + } + } + if (!empty($vrfUpdate)) { + dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array( + $tmp['vrf_lite_cisco_id'] + )); + } + } else { + + $id = dbInsert(array( + 'device_id' => $device ['device_id'], + 'context_name' => $context, + 'intance_name' => $vrf['intance_name'], + 'vrf_name' => $vrf['vrf_name'] + ), 'vrf_lite_cisco'); + + $ids[$id] = $id; + } + } + + unset($tableVrf); + } + + //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work + $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( + $device ['device_id'])); + + $device['vrf_lite_cisco'] = $tmpVrfC; + + //Delete all vrf that chaged + foreach ($tmpVrfC as $vrfC) { + unset($ids[$vrfC['vrf_lite_cisco_id']]); + } + if (!empty($ids)) { + foreach ($ids as $id) { + + dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array( + $id)); + } + } + + + unset($ids); + unset($tmpVrfC); +} // enable_vrf_lite_cisco +?> diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index b03ac9048..e8055e63c 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -669,8 +669,8 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity }//end discover_toner() - -function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin) { + +function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name='') { global $device,$config; $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen").'/'.$ipv6_prefixlen; @@ -683,21 +683,21 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') { $port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } // Below looks like a duplicate of the above FIXME - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } - $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)); + $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { - dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id), 'ipv6_addresses'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ? AND `context_name` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { + dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses'); echo '+'; } else { diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 53cf3ad57..26fc9ba28 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ network.'/'.$addr->bitmask; - $cidr = $addr->bitmask; - - if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { - $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') { - dbInsert(array('ipv4_network' => $network), 'ipv4_networks'); - // echo("Create Subnet $network\n"); - echo 'S'; - } - - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)) == '0') { - dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id), 'ipv4_addresses'); - // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); - echo '+'; - } - else { - echo '.'; - } - - $full_address = "$oid/$cidr|$ifIndex"; - $valid_v4[$full_address] = 1; - } - else { - echo '!'; - }//end if -}//end foreach - -$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; - - if (!$valid_v4[$full_address]) { - echo '-'; - $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { - $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); - } - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -echo "\n"; + $oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB')); + $oids = str_replace('ipAdEntIfIndex.', '', $oids); + foreach (explode("\n", $oids) as $data) { + $data = trim($data); + list($oid,$ifIndex) = explode(' ', $data); + $mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB')); + $addr = Net_IPv4::parseAddress("$oid/$mask"); + $network = $addr->network.'/'.$addr->bitmask; + $cidr = $addr->bitmask; -unset($valid_v4); + if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { + $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name` = ?', array($network, $device['context_name'])) < '1') { + dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks'); + // echo("Create Subnet $network\n"); + echo 'S'; + } + + $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name`= ?', array($network, $device['context_name'])); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? and `context_name`=?', array($oid, $cidr, $port_id, $device['context_name'])) == '0') { + dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id,'context_name' => $device['context_name']), 'ipv4_addresses'); + // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); + echo '+'; + } + else { + echo '.'; + } + + $full_address = "$oid/$cidr|$ifIndex"; + $valid_v4[$full_address] = 1; + } + else { + echo '!'; + }//end if + }//end foreach + + $sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND a.context_name= '" . $device['context_name'] . "'"; + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; + + if (!$valid_v4[$full_address]) { + echo '-'; + $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { + $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); + } + } + } + + echo "\n"; + unset($device['context_name']); + unset($valid_v4); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index 562428b6b..f7762ee98 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -1,78 +1,89 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); -$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); -$oids = str_replace('"', '', $oids); -$oids = str_replace('IP-MIB::', '', $oids); -$oids = trim($oids); - -foreach (explode("\n", $oids) as $data) { - if ($data) { - $data = trim($data); - list($ipv6addr,$ifIndex) = explode(' ', $data); - $oid = ''; - $sep = ''; - $adsep = ''; - unset($ipv6_address); - $do = '0'; - foreach (explode(':', $ipv6addr) as $part) { - $n = hexdec($part); - $oid = "$oid"."$sep"."$n"; - $sep = '.'; - $ipv6_address = $ipv6_address."$adsep".$part; - $do++; - if ($do == 2) { - $adsep = ':'; - $do = '0'; - } - else { - $adsep = ''; - } - } - - $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); - $ipv6_prefixlen = explode('.', $ipv6_prefixlen); - $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); - - $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); - - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); - } //end if -} //end foreach - -if (!$oids) { - $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); - $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); + $oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); $oids = str_replace('"', '', $oids); + $oids = str_replace('IP-MIB::', '', $oids); $oids = trim($oids); foreach (explode("\n", $oids) as $data) { if ($data) { - $data = trim($data); - list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); - list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); - $ipv6_address = snmp2ipv6($ipv6addr); - $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); + $data = trim($data); + list($ipv6addr,$ifIndex) = explode(' ', $data); + $oid = ''; + $sep = ''; + $adsep = ''; + unset($ipv6_address); + $do = '0'; + foreach (explode(':', $ipv6addr) as $part) { + $n = hexdec($part); + $oid = "$oid"."$sep"."$n"; + $sep = '.'; + $ipv6_address = $ipv6_address."$adsep".$part; + $do++; + if ($do == 2) { + $adsep = ':'; + $do = '0'; + } + else { + $adsep = ''; + } + } + + $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); + $ipv6_prefixlen = explode('.', $ipv6_prefixlen); + $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); + + $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); + + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); } //end if } //end foreach -} //end if -$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; + if (!$oids) { + $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); + $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = str_replace('"', '', $oids); + $oids = trim($oids); -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; - $port_id = $row['port_id']; - $valid_address = $full_address.'-'.$port_id; - if (!$valid['ipv6'][$valid_address]) { - echo '-'; - $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { - $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + foreach (explode("\n", $oids) as $data) { + if ($data) { + $data = trim($data); + list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); + list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); + $ipv6_address = snmp2ipv6($ipv6addr); + $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); + } //end if + } //end foreach + } //end if + + $sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND A.context_name= '" . $device['context_name'] . "'"; + + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; + $port_id = $row['port_id']; + $valid_address = $full_address.'-'.$port_id; + if (!$valid['ipv6'][$valid_address]) { + echo '-'; + $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { + $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + } } } -} -echo "\n"; + echo "\n"; + unset($device['context_name']); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index 56863ec10..40ff425a0 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -2,6 +2,9 @@ if ($config['enable_bgp']) { foreach (dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])) as $peer) { + //add context if exist + $device['context_name']= $peer['context_name']; + // Poll BGP Peer $peer2 = false; echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' '; @@ -62,14 +65,28 @@ if ($config['enable_bgp']) { } } else { - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; - $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; - $peer_data = trim(`$peer_cmd`); + // $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; + $oids = "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . ""; + $peer_data=snmp_get_multi($device,$oids,'-OUQs','BGP4-MIB'); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } }//end if - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + //list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + unset($peer_data); } else if ($device['os'] == 'junos') { // v6 for JunOS via Juniper MIB @@ -78,9 +95,9 @@ if ($config['enable_bgp']) { if (!isset($junos_v6)) { echo "\nCaching Oids..."; // FIXME - needs moved to function - $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; - foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { + //$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + + foreach (explode("\n",snmp_get($device,'jnxBgpM2PeerStatus.0.ipv6"','-OUnq','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos")) as $oid){ list($peer_oid) = explode(' ', $oid); $peer_id = explode('.', $peer_oid); $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); @@ -88,25 +105,34 @@ if ($config['enable_bgp']) { } // FIXME - move to function (and clean up, wtf?) - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); - $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; - $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; - // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? - $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= '|grep -v "No Such Instance"'; - d_echo("\n$peer_cmd\n"); - - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + + $oids = " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip]; # Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? + $oids .= " jnxBgpM2PeerInUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerFsmEstablishedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip]; + //$peer_cmd .= '|grep -v "No Such Instance"'; WHAT TO DO WITH THIS??,USE TO SEE -Ln?? + $peer_data=snmp_get_multi($device,$oids,'-OUQs -Ln','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos"); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + unset($peer_data); + d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); @@ -235,23 +261,37 @@ if ($config['enable_bgp']) { } else { // FIXME - move to function - $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - - d_echo("$cbgp_cmd\n"); - - $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); - $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); + + + $oids = " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + + d_echo("$oids\n"); + + $cbgp_data= snmp_get_multi($device,$oids,'-OUQs ','CISCO-BGP4-MIB'); + $cbgp_data= array_pop($cbgp_data); + d_echo("$cbgp_data\n"); + + }//end if - list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + + $cbgpPeerAcceptedPrefixes= !empty($cbgp_data['cbgpPeerAcceptedPrefixes'])?$cbgp_data['cbgpPeerAcceptedPrefixes']:''; + $cbgpPeerDeniedPrefixes= !empty($cbgp_data['cbgpPeerDeniedPrefixes'])?$cbgp_data['cbgpPeerDeniedPrefixes']:''; + $cbgpPeerPrefixAdminLimit= !empty($cbgp_data['cbgpPeerPrefixAdminLimit'])?$cbgp_data['cbgpPeerPrefixAdminLimit']:''; + $cbgpPeerPrefixThreshold= !empty($cbgp_data['cbgpPeerPrefixThreshold'])?$cbgp_data['cbgpPeerPrefixThreshold']:''; + $cbgpPeerPrefixClearThreshold= !empty($cbgp_data['cbgpPeerPrefixClearThreshold'])?$cbgp_data['cbgpPeerPrefixClearThreshold']:''; + $cbgpPeerAdvertisedPrefixes= !empty($cbgp_data['cbgpPeerAdvertisedPrefixes'])?$cbgp_data['cbgpPeerAdvertisedPrefixes']:''; + $cbgpPeerSuppressedPrefixes= !empty($cbgp_data['cbgpPeerSuppressedPrefixes'])?$cbgp_data['cbgpPeerSuppressedPrefixes']:''; + $cbgpPeerWithdrawnPrefixes= !empty($cbgp_data['cbgpPeerWithdrawnPrefixes'])?$cbgp_data['cbgpPeerWithdrawnPrefixes']:''; + + unset($cbgp_data); }//end if if ($device['os'] == 'junos') { @@ -331,5 +371,6 @@ if ($config['enable_bgp']) { } //end foreach } //end if echo "\n"; + unset($device['context_name']); } //end foreach } //end if diff --git a/includes/polling/ospf.inc.php b/includes/polling/ospf.inc.php index 8fec222a2..602255258 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_port_count = 0; $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ $ospf_oids_db = array( 'ospfDemandExtensions', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; -} - -// Pull data from device -$ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); -foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_instances_db[$ospf_instance_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id), 'ospf_instances'); - echo '+'; - $ospf_instances_db[$entry['ospf_instance_id']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_instances_poll); - echo 'Database: '; - print_r($ospf_instances_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_instances_db)) { - foreach ($ospf_instances_db as $ospf_instance_db) { - $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_db['ospf_instance_id']]; - foreach ($ospf_oids_db as $oid) { - // Loop the OIDs - if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid]) { - // If data has changed, build a query - $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_instance_update) { - dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - echo 'U'; - unset($ospf_instance_update); - } - else { - echo '.'; - } - - unset($ospf_instance_poll); - unset($ospf_instance_db); - $ospf_instance_count++; - }//end foreach -}//end if - -unset($ospf_instances_poll); -unset($ospf_instances_db); - -echo ' Areas: '; - $ospf_area_oids = array( 'ospfAuthType', 'ospfImportAsExtern', @@ -95,72 +38,6 @@ $ospf_area_oids = array( 'ospfAreaStatus', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_areas_db[$entry['ospfAreaId']] = $entry; -} - -// Pull data from device -$ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_areas_db[$ospf_area_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id), 'ospf_areas'); - echo '+'; - $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - $ospf_areas_db[$entry['ospf_area_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_areas_poll); - echo 'Database: '; - print_r($ospf_areas_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_areas_db)) { - foreach ($ospf_areas_db as $ospf_area_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_area_poll = $ospf_areas_poll[$ospf_area_db['ospfAreaId']]; - foreach ($ospf_area_oids as $oid) { - // Loop the OIDs - if ($ospf_area_db[$oid] != $ospf_area_poll[$oid]) { - // If data has changed, build a query - $ospf_area_update[$oid] = $ospf_area_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME - } - } - - if ($ospf_area_update) { - dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - echo 'U'; - unset($ospf_area_update); - } - else { - echo '.'; - } - - unset($ospf_area_poll); - unset($ospf_area_db); - $ospf_area_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'])); - }//end if - }//end foreach -}//end if - -unset($ospf_areas_db); -unset($ospf_areas_poll); - -// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); -// print_r($ospf_ports); -echo ' Ports: '; - $ospf_port_oids = array( 'ospfIfIpAddress', 'port_id', @@ -171,7 +48,7 @@ $ospf_port_oids = array( 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,87 +62,6 @@ $ospf_port_oids = array( 'ospfIfAuthType', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_ports_db[$entry['ospf_port_id']] = $entry; -} - -// Pull data from device -$ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_ports_db[$ospf_port_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id), 'ospf_ports'); - echo '+'; - $ospf_ports_db[$entry['ospf_port_id']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_ports_poll); - echo 'Database: '; - print_r($ospf_ports_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_ports_db)) { - foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_port_poll = $ospf_ports_poll[$ospf_port_db['ospf_port_id']]; - - if ($ospf_port_poll['ospfAddressLessIf']) { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); - } - else { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'])); - } - - foreach ($ospf_port_oids as $oid) { - // Loop the OIDs - if ($ospf_port_db[$oid] != $ospf_port_poll[$oid]) { - // If data has changed, build a query - $ospf_port_update[$oid] = $ospf_port_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_port_update) { - dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - echo 'U'; - unset($ospf_port_update); - } - else { - echo '.'; - } - - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'])); - // "DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); - echo '-'; - }//end if - }//end foreach -}//end if - -// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 -// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 -// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 -// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrState.172.22.203.98.0 full -// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 -// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 -// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active -// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic -// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false -echo ' Neighbours: '; - $ospf_nbr_oids_db = array( 'ospfNbrIpAddr', 'ospfNbrAddressLessIndex', @@ -279,83 +75,313 @@ $ospf_nbr_oids_db = array( 'ospfNbmaNbrPermanence', 'ospfNbrHelloSuppressed', ); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])) as $nbr_entry) { - $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry; + + +if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) { + $vrfs_lite_cisco = $device['vrf_lite_cisco']; +} else { + $vrfs_lite_cisco = array(array('context_name' => null)); } -// Pull data from device -$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_nbrs_db[$ospf_nbr_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id), 'ospf_nbrs'); - echo '+'; - $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - $ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry; + $device['context_name'] = $vrf_lite['context_name']; + + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; } -} -if ($debug) { - echo "\nPolled: "; - print_r($ospf_nbrs_poll); - echo 'Database: '; - print_r($ospf_nbrs_db); - echo "\n"; -} + // Pull data from device + $ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); + foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (empty($ospf_instances_db[$ospf_instance_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id, 'context_name' => $device['context_name']), 'ospf_instances'); + echo '+'; + $ospf_instances_db[$entry['ospf_instance_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; + } + } -// Loop array of entries and update -if (is_array($ospf_nbrs_db)) { - foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { - if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { - $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + if ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'])); + // Loop array of entries and update + if (is_array($ospf_instances_db)) { + foreach ($ospf_instances_db as $ospf_instance_id => $ospf_instance_db) { + if (is_array($ospf_instances_poll[$ospf_instance_id])) { + $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_id]; + foreach ($ospf_oids_db as $oid) { + // Loop the OIDs + if ($ospf_instance_db[$device['context_name']][$oid] != $ospf_instance_poll[$oid]) { + // If data has changed, build a query + $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } - if ($ospf_nbr_db['port_id'] != $ospf_nbr_poll['port_id']) { - if ($ospf_nbr_poll['port_id']) { - $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + if ($ospf_instance_update) { + dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + echo 'U'; + unset($ospf_instance_update); } else { - $ospf_nbr_update = array('port_id' => array('NULL')); + echo '.'; } + + unset($ospf_instance_poll); + unset($ospf_instance_db); + $ospf_instance_count++; + } else { + dbDelete('ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=? ', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); } + }//end foreach + }//end if + unset($ospf_instances_poll); + unset($ospf_instances_db); - foreach ($ospf_nbr_oids as $oid) { - // Loop the OIDs - d_echo($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n"); - if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid]) { - // If data has changed, build a query - $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; - // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + + echo ' Areas: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `context_name`=?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_areas_db[$entry['ospfAreaId']][$entry['context_name']] = $entry; + } + + // Pull data from device + $ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_areas_db[$ospf_area_id][$entry['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id, 'context_name' => $device['context_name']), 'ospf_areas'); + echo '+'; + $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + $ospf_areas_db[$ospf_area_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_areas_poll); + echo 'Database: '; + print_r($ospf_areas_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_areas_db)) { + foreach ($ospf_areas_db as $$ospf_area_id => $ospf_area_db) { + if (is_array($ospf_areas_poll[$ospf_area_id])) { + $ospf_area_poll = $ospf_areas_poll[$ospf_area_id]; + foreach ($ospf_area_oids as $oid) { + // Loop the OIDs + if ($ospf_area_db[$entry['context_name']][$oid] != $ospf_area_poll[$oid]) { + // If data has changed, build a query + $ospf_area_update[$oid] = $ospf_area_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME + } } - } - if ($ospf_nbr_update) { - dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - echo 'U'; - unset($ospf_nbr_update); + if ($ospf_area_update) { + dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + echo 'U'; + unset($ospf_area_update); + } + else { + echo '.'; + } + + unset($ospf_area_poll); + unset($ospf_area_db); + $ospf_area_count++; } else { - echo '.'; - } + dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); + }//end if + }//end foreach + }//end if - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; + unset($ospf_areas_db); + unset($ospf_areas_poll); + + +// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); +// print_r($ospf_ports); + echo ' Ports: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = $entry; + } + + // Pull data from device + $ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_ports_db[$ospf_port_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id, 'context_name' => $device['context_name']), 'ospf_ports'); + echo '+'; + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); } - else { - dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'])); - echo '-'; - }//end if - }//end foreach -}//end if + } + if ($debug) { + echo "\nPolled: "; + print_r($ospf_ports_poll); + echo 'Database: '; + print_r($ospf_ports_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_ports_db)) { + foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { + if (is_array($ospf_ports_poll[$ospf_port_id])) { + $ospf_port_poll = $ospf_ports_poll[$ospf_port_id]; + + if ($ospf_port_poll['ospfAddressLessIf']) { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); + } + else { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'], $device['context_name'])); + } + + foreach ($ospf_port_oids as $oid) { + // Loop the OIDs + if ($ospf_port_db[$device['context_name']][$oid] != $ospf_port_poll[$oid]) { + // If data has changed, build a query + $ospf_port_update[$oid] = $ospf_port_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } + + if ($ospf_port_update) { + dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); + echo 'U'; + unset($ospf_port_update); + } + else { + echo '.'; + } + + unset($ospf_port_poll); + unset($ospf_port_db); + $ospf_port_count++; + } + else { + dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'], $device['context_name'])); + // ("DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); + echo '-'; + }//end if + }//end foreach + }//end if + + +// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 +// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 +// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 +// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrState.172.22.203.98.0 full +// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 +// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 +// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active +// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic +// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false + echo ' Neighbours: '; + + $ospf_nbr_oids_rrd = array(); + $ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $nbr_entry) { + $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']][$device['context_name']] = $nbr_entry; + } + + // Pull data from device + $ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_nbrs_db[$ospf_nbr_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id, 'context_name' => $device['context_name']), 'ospf_nbrs'); + echo '+'; + $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id,$device['context_name'])); + $ospf_nbrs_db[$ospf_nbr_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_nbrs_poll); + echo 'Database: '; + print_r($ospf_nbrs_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_nbrs_db)) { + foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { + if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { + $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + + $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'], $device['context_name'])); + + if ($ospf_nbr_db[$device['context_name']]['port_id'] != $ospf_nbr_poll['port_id']) { + if (!empty($ospf_nbr_poll['port_id'])) { + $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + } + else { + $ospf_nbr_update = array('port_id' => array('NULL')); + } + } + + foreach ($ospf_nbr_oids as $oid) { + // Loop the OIDs + d_echo($ospf_nbr_db[$device['context_name']][$oid].'|'.$ospf_nbr_poll[$oid]."\n"); + + if ($ospf_nbr_db[$device['context_name']][$oid] != $ospf_nbr_poll[$oid]) { + // If data has changed, build a query + $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; + // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + } + } + + if ($ospf_nbr_update) { + dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id, $device['context_name'])); + echo 'U'; + unset($ospf_nbr_update); + } + else { + echo '.'; + } + + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; + } + else { + dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'], $device['context_name'])); + echo '-'; + }//end if + }//end foreach + }//end if + unset($ospf_nbrs_db); + unset($ospf_nbrs_poll); +} +unset($device['context_name']); +unset($vrfs_lite_cisco); // Create device-wide statistics RRD $filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('ospf-statistics.rrd'); diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 4f15260aa..a9ad78226 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -750,8 +750,14 @@ function snmp_gen_auth(&$device) { $cmd = ''; if ($device['snmpver'] === 'v3') { + $cmd = " -v3 -n '' -l '".$device['authlevel']."'"; - + + //add context if exist context + if(key_exists('context_name', $device)){ + $cmd = " -v3 -n '".$device['context_name']."' -l '".$device['authlevel']."'"; + } + if ($device['authlevel'] === 'noAuthNoPriv') { // We have to provide a username anyway (see Net-SNMP doc) // FIXME: There are two other places this is set - why are they ignored here? From 8f4dbb533801a00f2e781cd057ddbd4dd3041ce3 Mon Sep 17 00:00:00 2001 From: Aaron Daniels Date: Thu, 21 Jan 2016 22:04:20 +1000 Subject: [PATCH 007/104] Cisco OTV Implements the CISCO-OTV-MIB to retrieve OTV counters from Cisco devices. This collects information on the configured Overlays and Adjacencies Statistics are collected for the amount of VLAN's on each overlay and the amount of MAC addresses available over each OTV endpoint. OTV alerts are collected and generated if the appropriate alerting rules exist. Data is displayed under routing at both the global and device level. Includes function snmpwalk_array_num, which performs a numeric SNMPWalk and returns an array containing $count indexes One Index: From: 1.3.6.1.4.1.9.9.166.1.15.1.1.27.18.655360 = 0 To: $array['1.3.6.1.4.1.9.9.166.1.15.1.1.27.18']['655360'] = 0 Two Indexes: From: 1.3.6.1.4.1.9.9.166.1.15.1.1.27.18.655360 = 0 To: $array['1.3.6.1.4.1.9.9.166.1.15.1.1.27']['18']['655360'] = 0 And so on... --- doc/Extensions/Component.md | 6 +- .../graphs/device/cisco-otv-mac.inc.php | 62 +++++ .../graphs/device/cisco-otv-vlan.inc.php | 62 +++++ html/includes/print-menubar.php | 18 +- html/pages/device.inc.php | 10 + html/pages/device/routing.inc.php | 1 + html/pages/device/routing/cisco-otv.inc.php | 94 +++++++ html/pages/routing.inc.php | 2 + html/pages/routing/cisco-otv.inc.php | 58 +++++ includes/defaults.inc.php | 2 + includes/discovery/cisco-otv.inc.php | 235 ++++++++++++++++++ includes/polling/cisco-otv.inc.php | 181 ++++++++++++++ includes/snmp.inc.php | 66 +++++ 13 files changed, 793 insertions(+), 4 deletions(-) create mode 100644 html/includes/graphs/device/cisco-otv-mac.inc.php create mode 100644 html/includes/graphs/device/cisco-otv-vlan.inc.php create mode 100644 html/pages/device/routing/cisco-otv.inc.php create mode 100644 html/pages/routing/cisco-otv.inc.php create mode 100644 includes/discovery/cisco-otv.inc.php create mode 100644 includes/polling/cisco-otv.inc.php diff --git a/doc/Extensions/Component.md b/doc/Extensions/Component.md index 235335380..13bef6b4e 100644 --- a/doc/Extensions/Component.md +++ b/doc/Extensions/Component.md @@ -307,11 +307,11 @@ To see an example of how the component module can used, please see the following - Cisco CBQoS - includes/discovery/cisco-cbqos.inc.php - - includes/poller/cisco-cbqos.inc.php + - includes/polling/cisco-cbqos.inc.php - html/includes/graphs/device/cbqos_traffic.inc.php - Cisco OTV - includes/discovery/cisco-otv.inc.php - - includes/poller/applications/cisco-otv.inc.php + - includes/polling/cisco-otv.inc.php - html/includes/graphs/device/cisco-otv-mac.inc.php - - html/pages/device/apps/cisco-otv.inc.php + - html/pages/routing/cisco-otv.inc.php diff --git a/html/includes/graphs/device/cisco-otv-mac.inc.php b/html/includes/graphs/device/cisco-otv-mac.inc.php new file mode 100644 index 000000000..5c616869e --- /dev/null +++ b/html/includes/graphs/device/cisco-otv-mac.inc.php @@ -0,0 +1,62 @@ + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +require_once "../includes/component.php"; +$COMPONENT = new component(); +$options['filter']['type'] = array('=','Cisco-OTV'); +$COMPONENTS = $COMPONENT->getComponents($device['device_id'],$options); + +// We only care about our device id. +$COMPONENTS = $COMPONENTS[$device['device_id']]; + +include "includes/graphs/common.inc.php"; +$rrd_options .= " -l 0 -E "; +$rrd_options .= " COMMENT:'MAC Addresses Now Min Max\\n'"; +$rrd_additions = ""; + +$COUNT = 0; +foreach ($COMPONENTS as $ID => $ARRAY) { + if ($ARRAY['otvtype'] == 'endpoint') { + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("cisco-otv-".$ARRAY['endpoint']."-mac.rrd"); + + if (file_exists($rrd_filename)) { + // Stack the area on the second and subsequent DS's + $STACK = ""; + if ($COUNT != 0) { + $STACK = ":STACK "; + } + + // Grab a color from the array. + if ( isset($config['graph_colours']['mixed'][$COUNT]) ) { + $COLOR = $config['graph_colours']['mixed'][$COUNT]; + } + else { + $COLOR = $config['graph_colours']['oranges'][$COUNT-7]; + } + + $rrd_additions .= " DEF:DS" . $COUNT . "=" . $rrd_filename . ":count:AVERAGE "; + $rrd_additions .= " AREA:DS" . $COUNT . "#" . $COLOR . ":'" . str_pad(substr($COMPONENTS[$ID]['endpoint'],0,15),15) . "'" . $STACK; + $rrd_additions .= " GPRINT:DS" . $COUNT . ":LAST:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $COUNT . ":MIN:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $COUNT . ":MAX:%4.0lf%s\\\l "; + $COUNT++; + } + } +} + +if ($rrd_additions == "") { + // We didn't add any data points. +} +else { + $rrd_options .= $rrd_additions; +} diff --git a/html/includes/graphs/device/cisco-otv-vlan.inc.php b/html/includes/graphs/device/cisco-otv-vlan.inc.php new file mode 100644 index 000000000..8ee50acf4 --- /dev/null +++ b/html/includes/graphs/device/cisco-otv-vlan.inc.php @@ -0,0 +1,62 @@ + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +require_once "../includes/component.php"; +$COMPONENT = new component(); +$options['filter']['type'] = array('=','Cisco-OTV'); +$COMPONENTS = $COMPONENT->getComponents($device['device_id'],$options); + +// We only care about our device id. +$COMPONENTS = $COMPONENTS[$device['device_id']]; + +include "includes/graphs/common.inc.php"; +$rrd_options .= " -l 0 -E "; +$rrd_options .= " COMMENT:'VLANs Now Min Max\\n'"; +$rrd_additions = ""; + +$COUNT = 0; +foreach ($COMPONENTS as $ID => $ARRAY) { + if ($ARRAY['otvtype'] == 'overlay') { + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("cisco-otv-".$ARRAY['label']."-vlan.rrd"); + + if (file_exists($rrd_filename)) { + // Stack the area on the second and subsequent DS's + $STACK = ""; + if ($COUNT != 0) { + $STACK = ":STACK "; + } + + // Grab a color from the array. + if ( isset($config['graph_colours']['mixed'][$COUNT]) ) { + $COLOR = $config['graph_colours']['mixed'][$COUNT]; + } + else { + $COLOR = $config['graph_colours']['oranges'][$COUNT-7]; + } + + $rrd_additions .= " DEF:DS" . $COUNT . "=" . $rrd_filename . ":count:AVERAGE "; + $rrd_additions .= " AREA:DS" . $COUNT . "#" . $COLOR . ":'" . str_pad(substr($COMPONENTS[$ID]['label'],0,15),15) . "'" . $STACK; + $rrd_additions .= " GPRINT:DS" . $COUNT . ":LAST:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $COUNT . ":MIN:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $COUNT . ":MAX:%4.0lf%s\\\l "; + $COUNT++; + } + } +} + +if ($rrd_additions == "") { + // We didn't add any data points. +} +else { + $rrd_options .= $rrd_additions; +} diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 74ae6f7a1..859af924f 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -420,7 +420,13 @@ $routing_count['ospf'] = dbFetchCell("SELECT COUNT(ospf_instance_id) FROM `ospf_ $routing_count['cef'] = dbFetchCell("SELECT COUNT(cef_switching_id) from `cef_switching`"); $routing_count['vrf'] = dbFetchCell("SELECT COUNT(vrf_id) from `vrfs`"); -if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']) > "0") { +require_once "../includes/component.php"; +$COMPONENT = new component(); +$options['type'] = 'Cisco-OTV'; +$OTV = $COMPONENT->getComponents(null,$options); +$routing_count['cisco-otv'] = count($OTV); + +if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']+$routing_count['cisco-otv']) > "0") { ?> '); + $separator = 0; + } + echo('
  • Cisco OTV
  • '); + $separator++; + } + // BGP Sessions if ($_SESSION['userlevel'] >= '5' && $routing_count['bgp']) { if ($separator) { diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 94a296822..3de92da54 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -210,6 +210,16 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) { $routing_tabs[] = 'vrf'; } + require_once "../includes/component.php"; + $COMPONENT = new component(); + $options['type'] = 'Cisco-OTV'; + $options['filter']['device_id'] = array('=',$device['device_id']); + $OTV = $COMPONENT->getComponents(null,$options); + $device_routing_count['cisco-otv'] = count($OTV); + if ($device_routing_count['cisco-otv'] > 0) { + $routing_tabs[] = 'cisco-otv'; + } + if (is_array($routing_tabs)) { echo '
  • diff --git a/html/pages/device/routing.inc.php b/html/pages/device/routing.inc.php index e4be54617..c58fe17a8 100644 --- a/html/pages/device/routing.inc.php +++ b/html/pages/device/routing.inc.php @@ -20,6 +20,7 @@ $type_text['bgp'] = 'BGP'; $type_text['cef'] = 'CEF'; $type_text['ospf'] = 'OSPF'; $type_text['vrf'] = 'VRFs'; +$type_text['cisco-otv'] = 'OTV'; print_optionbar_start(); diff --git a/html/pages/device/routing/cisco-otv.inc.php b/html/pages/device/routing/cisco-otv.inc.php new file mode 100644 index 000000000..f29a9c9ae --- /dev/null +++ b/html/pages/device/routing/cisco-otv.inc.php @@ -0,0 +1,94 @@ +getComponents($device['device_id'],$options); +$COMPONENTS = $COMPONENTS[$device['device_id']]; + +global $config; +?> +
    +
    +

    Overlay's & Adjacencies

    +
    +
    + $OVERLAY) { + if ($OVERLAY['otvtype'] == 'overlay') { + if ($OVERLAY['status'] == 1) { + $OVERLAY_STATUS = "Normal"; + $GLI = ""; + } + else { + $OVERLAY_STATUS = "".$OVERLAY['error']." - Alert"; + $GLI = "list-group-item-danger"; + } +?> + - + + +
    +
    + +
    +
    +

    AED Enabled VLAN's

    +
    +
    + +
    +
    + +
    +
    +

    MAC Addresses

    +
    +
    + +
    +
    diff --git a/html/pages/routing.inc.php b/html/pages/routing.inc.php index 0a7fcb335..848c655e2 100644 --- a/html/pages/routing.inc.php +++ b/html/pages/routing.inc.php @@ -16,6 +16,7 @@ $type_text['bgp'] = 'BGP'; $type_text['cef'] = 'CEF'; $type_text['ospf'] = 'OSPF'; $type_text['vrf'] = 'VRFs'; +$type_text['cisco-otv'] = 'OTV'; print_optionbar_start(); @@ -53,6 +54,7 @@ switch ($vars['protocol']) { case 'vrf': case 'cef': case 'ospf': + case 'cisco-otv': include 'pages/routing/'.$vars['protocol'].'.inc.php'; break; diff --git a/html/pages/routing/cisco-otv.inc.php b/html/pages/routing/cisco-otv.inc.php new file mode 100644 index 000000000..00ca33bdd --- /dev/null +++ b/html/pages/routing/cisco-otv.inc.php @@ -0,0 +1,58 @@ +getComponents(null,$options); + +foreach ($COMPONENTS as $DEVICE_ID => $COMP) { + $LINK = generate_url(array('page' => 'device', 'device' => $DEVICE_ID, 'tab' => 'routing', 'proto' => 'cisco-otv')); +?> +
    + +
    + $OVERLAY) { + if ($OVERLAY['otvtype'] == 'overlay') { + if ($OVERLAY['status'] == 1) { + $OVERLAY_STATUS = "Normal"; + $GLI = ""; + } + else { + $OVERLAY_STATUS = "".$OVERLAY['error']." - Alert"; + $GLI = "list-group-item-danger"; + } + ?> + - + + +
    +
    + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if ($device['os_group'] == 'cisco') { + + // Define some error messages + $ERROR_VPN[0] = "Other"; + $ERROR_VPN[1] = "Configuration changed"; + $ERROR_VPN[2] = "Control Group information is unavailable"; + $ERROR_VPN[3] = "Data Group range information is unavailable"; + $ERROR_VPN[4] = "Join or Source interface information is unavailable"; + $ERROR_VPN[5] = "VPN name is unavailable"; + $ERROR_VPN[6] = "IP address is missing for Join Interface"; + $ERROR_VPN[7] = "Join Interface is down"; + $ERROR_VPN[8] = "Overlay is administratively shutdown"; + $ERROR_VPN[9] = "Overlay is in delete hold down phase"; + $ERROR_VPN[10] = "VPN is reinitializing"; + $ERROR_VPN[11] = "Site ID information is unavailable"; + $ERROR_VPN[12] = "Site ID mismatch has occurred"; + $ERROR_VPN[13] = "IP address is missing for Source Interface"; + $ERROR_VPN[14] = "Source interface is down"; + $ERROR_VPN[15] = "Changing site identifier"; + $ERROR_VPN[16] = "Changing control group"; + $ERROR_VPN[17] = "Device ID information is unavailable"; + $ERROR_VPN[18] = "Changing device ID"; + $ERROR_VPN[19] = "Cleanup in progress"; + + $ERROR_AED[0] = "Other"; + $ERROR_AED[1] = "Overlay is Down"; + $ERROR_AED[2] = "Site ID is not configured"; + $ERROR_AED[3] = "Site ID mismatch"; + $ERROR_AED[4] = "Version mismatch"; + $ERROR_AED[5] = "Site VLAN is Down"; + $ERROR_AED[6] = "No extended VLAN is operationally up"; + $ERROR_AED[7] = "No Overlay Adjacency is up"; + $ERROR_AED[8] = "LSPDB sync incomplete"; + $ERROR_AED[9] = "Overlay state down event in progress"; + $ERROR_AED[10] = "ISIS control group sync pending"; + + $ERROR_OVERLAY[1] = "active"; + $ERROR_OVERLAY[2] = "notInService"; + $ERROR_OVERLAY[3] = "notReady"; + $ERROR_OVERLAY[4] = "createAndGo"; + $ERROR_OVERLAY[5] = "createAndWait"; + $ERROR_OVERLAY[6] = "destroy"; + + $MODULE = 'Cisco-OTV'; + echo $MODULE.': '; + + require_once 'includes/component.php'; + $COMPONENT = new component(); + $COMPONENTS = $COMPONENT->getComponents($device['device_id'],array('type'=>$MODULE)); + + // We only care about our device id. + $COMPONENTS = $COMPONENTS[$device['device_id']]; + + // Begin our master array, all other values will be processed into this array. + $tblOTV = array(); + $tblEndpoints = array(); + + // Let's gather some data.. + $tblOverlayEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.2.1.1'); + $tblAdjacencyDatabaseEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.3.1.1', 0); + $tblAdjacentDevName = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.3.1.1.4', 0); + + /* + * False == no object found - this is not an error, there is no QOS configured + * null == timeout or something else that caused an error, there may be QOS configured but we couldn't get it. + */ + if ( is_null($tblOverlayEntry) || is_null($tblAdjacencyDatabaseEntry) || is_null($tblAdjacentDevName) ) { + // We have to error here or we will end up deleting all our components. + echo "Error\n"; + } + else { + // No Error, lets process things. + + // Add each overlay to the array. + foreach ($tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.2'] as $index => $name) { + $RESULT = array(); + $message = false; + $RESULT['index'] = $index; + $RESULT['label'] = $name; + if ($tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.15'][$index] == 1) { + $RESULT['transport'] = 'Multicast'; + } + else { + $RESULT['transport'] = 'Unicast'; + } + $RESULT['otvtype'] = 'overlay'; + $RESULT['UID'] = $RESULT['otvtype']."-".$RESULT['index']; + $RESULT['vpn_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.3'][$index]; + if ($RESULT['vpn_state'] != 2) { + $message .= "VPN Down: ".$ERROR_VPN[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.4'][$index]]."\n"; + } + $RESULT['aed_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.13'][$index]; + if ($RESULT['aed_state'] == 2) { + $message .= "AED Down: ".$ERROR_AED[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.14'][$index]]."\n"; + } + $RESULT['overlay_state'] = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.23'][$index]; + if ($RESULT['overlay_state'] == 2) { + $message .= "Overlay Down: ".$ERROR_OVERLAY[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.24'][$index]]."\n"; + } + + // If we have set a message, we have an error, activate alert. + if ($message !== false) { + $RESULT['error'] = $message; + $RESULT['status'] = 0; + } + else { + $RESULT['error'] = ""; + $RESULT['status'] = 1; + } + + // Add the result to the parent array. + $tblOTV[] = $RESULT; + } + + // Add each adjacency to the array. + foreach ($tblAdjacentDevName as $key => $value) { + preg_match('/^1.3.6.1.4.1.9.9.810.1.3.1.1.4.(\d+).1.4.(\d+.\d+.\d+.\d+)$/', $key, $MATCHES); + $RESULT = array(); + $RESULT['index'] = $MATCHES[1]; + $RESULT['endpoint'] = $MATCHES[2]; + $tblEndpoints[$value] = true; + $RESULT['otvtype'] = 'adjacency'; + $RESULT['UID'] = $RESULT['otvtype']."-".$RESULT['index']."-".str_replace(' ', '', $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.3.'.$RESULT['index'].'.1.4.'.$RESULT['endpoint']]); + $RESULT['uptime'] = $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.'.$RESULT['index'].'.1.4.'.$RESULT['endpoint']]; + $message = false; + if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.5.'.$RESULT['index'].'.1.4.'.$RESULT['endpoint']] != 1) { + $message .= "Adjacency is Down\n"; + } + + // If we have set a message, we have an error, activate alert. + if ($message !== false) { + $RESULT['error'] = $message; + $RESULT['status'] = 0; + } + else { + $RESULT['error'] = ""; + $RESULT['status'] = 1; + } + + // Set a default name, if for some unknown reason we cant find the parent VPN. + $RESULT['label'] = "Unknown (".$RESULT['index'].") - ".$value; + // We need to search the existing array to build the name + foreach ($tblOTV as $ITEM) { + if (($ITEM['otvtype'] == 'overlay') && ($ITEM['index'] == $RESULT['index'])) { + $RESULT['label'] = $ITEM['label']." - ".$value; + } + } + + // Add the result to the parent array. + $tblOTV[] = $RESULT; + } + + // We retain a list of all endpoints to tie the RRD to. + foreach ($tblEndpoints as $K => $V) { + $RESULT['label'] = "Endpoint: ".$K; + $RESULT['otvtype'] = 'endpoint'; + $RESULT['endpoint'] = $K; + $RESULT['UID'] = $RESULT['otvtype']."-".$K; + + // Add the result to the parent array. + $tblOTV[] = $RESULT; + } + + /* + * Ok, we have our 2 array's (Components and SNMP) now we need + * to compare and see what needs to be added/updated. + * + * Let's loop over the SNMP data to see if we need to ADD or UPDATE any components. + */ + foreach ($tblOTV as $key => $array) { + $COMPONENT_KEY = false; + + // Loop over our components to determine if the component exists, or we need to add it. + foreach ($COMPONENTS as $COMPID => $CHILD) { + if ($CHILD['UID'] === $array['UID']) { + $COMPONENT_KEY = $COMPID; + } + } + + if (!$COMPONENT_KEY) { + // The component doesn't exist, we need to ADD it - ADD. + $NEW_COMPONENT = $COMPONENT->createComponent($device['device_id'],$MODULE); + $COMPONENT_KEY = key($NEW_COMPONENT); + $COMPONENTS[$COMPONENT_KEY] = array_merge($NEW_COMPONENT[$COMPONENT_KEY], $array); + echo "+"; + } + else { + // The component does exist, merge the details in - UPDATE. + $COMPONENTS[$COMPONENT_KEY] = array_merge($COMPONENTS[$COMPONENT_KEY], $array); + echo "."; + } + + } + + /* + * Loop over the Component data to see if we need to DELETE any components. + */ + foreach ($COMPONENTS as $key => $array) { + // Guilty until proven innocent + $FOUND = false; + + foreach ($tblOTV as $k => $v) { + if ($array['UID'] == $v['UID']) { + // Yay, we found it... + $FOUND = true; + } + } + + if ($FOUND === false) { + // The component has not been found. we should delete it. + echo "-"; + $COMPONENT->deleteComponent($key); + } + } + + // Write the Components back to the DB. + $COMPONENT->setComponentPrefs($device['device_id'],$COMPONENTS); + echo "\n"; + + } // End if not error + +} diff --git a/includes/polling/cisco-otv.inc.php b/includes/polling/cisco-otv.inc.php new file mode 100644 index 000000000..47839fa31 --- /dev/null +++ b/includes/polling/cisco-otv.inc.php @@ -0,0 +1,181 @@ + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if ($device['os_group'] == "cisco") { + + // Define some error messages + $ERROR_VPN[0] = "Other"; + $ERROR_VPN[1] = "Configuration changed"; + $ERROR_VPN[2] = "Control Group information is unavailable"; + $ERROR_VPN[3] = "Data Group range information is unavailable"; + $ERROR_VPN[4] = "Join or Source interface information is unavailable"; + $ERROR_VPN[5] = "VPN name is unavailable"; + $ERROR_VPN[6] = "IP address is missing for Join Interface"; + $ERROR_VPN[7] = "Join Interface is down"; + $ERROR_VPN[8] = "Overlay is administratively shutdown"; + $ERROR_VPN[9] = "Overlay is in delete hold down phase"; + $ERROR_VPN[10] = "VPN is reinitializing"; + $ERROR_VPN[11] = "Site ID information is unavailable"; + $ERROR_VPN[12] = "Site ID mismatch has occurred"; + $ERROR_VPN[13] = "IP address is missing for Source Interface"; + $ERROR_VPN[14] = "Source interface is down"; + $ERROR_VPN[15] = "Changing site identifier"; + $ERROR_VPN[16] = "Changing control group"; + $ERROR_VPN[17] = "Device ID information is unavailable"; + $ERROR_VPN[18] = "Changing device ID"; + $ERROR_VPN[19] = "Cleanup in progress"; + + $ERROR_AED[0] = "Other"; + $ERROR_AED[1] = "Overlay is Down"; + $ERROR_AED[2] = "Site ID is not configured"; + $ERROR_AED[3] = "Site ID mismatch"; + $ERROR_AED[4] = "Version mismatch"; + $ERROR_AED[5] = "Site VLAN is Down"; + $ERROR_AED[6] = "No extended VLAN is operationally up"; + $ERROR_AED[7] = "No Overlay Adjacency is up"; + $ERROR_AED[8] = "LSPDB sync incomplete"; + $ERROR_AED[9] = "Overlay state down event in progress"; + $ERROR_AED[10] = "ISIS control group sync pending"; + + $ERROR_OVERLAY[1] = "active"; + $ERROR_OVERLAY[2] = "notInService"; + $ERROR_OVERLAY[3] = "notReady"; + $ERROR_OVERLAY[4] = "createAndGo"; + $ERROR_OVERLAY[5] = "createAndWait"; + $ERROR_OVERLAY[6] = "destroy"; + + $MODULE = 'Cisco-OTV'; + + require_once 'includes/component.php'; + $COMPONENT = new component(); + $options['filter']['type'] = array('=',$MODULE); + $options['filter']['disabled'] = array('=',0); + $COMPONENTS = $COMPONENT->getComponents($device['device_id'],$options); + + // We only care about our device id. + $COMPONENTS = $COMPONENTS[$device['device_id']]; + + // Only collect SNMP data if we have enabled components + if (count($COMPONENTS > 0)) { + // Let's gather the stats.. + $tblOverlayEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.2.1.1'); + $tblAdjacencyDatabaseEntry = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.3.1.1', 0); + $tblRouteNextHopAddr = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.5.1.1.8', 0); + $tblVlanEdgeDevIsAed = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.810.1.2.2.1.6', 2); + + // Let's create an array of each remote OTV endpoint and the count of MAC addresses that are reachable via. + $COUNT_MAC = array(); + foreach ($tblRouteNextHopAddr as $k => $v) { + $COUNT_MAC[$v]++; + } + + // Loop through the components and extract the data. + foreach ($COMPONENTS as $KEY => &$ARRAY) { + + if ($ARRAY['otvtype'] == 'overlay') { + // Let's check the varius status' of the overlay + $message = false; + $vpn_state = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.3'][$ARRAY['index']]; + if ($vpn_state != 2) { + $message .= "VPN Down: ".$ERROR_VPN[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.4'][$ARRAY['index']]]; + } + $aed_state = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.13'][$ARRAY['index']]; + if ($aed_state == 2) { + $message .= "AED Down: ".$ERROR_AED[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.14'][$ARRAY['index']]]; + } + $overlay_state = $tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.23'][$ARRAY['index']]; + if ($overlay_state == 2) { + $message .= "Overlay Down: ".$ERROR_OVERLAY[$tblOverlayEntry['1.3.6.1.4.1.9.9.810.1.2.1.1.24'][$ARRAY['index']]]; + } + + // If we have set a message, we have an error, activate alert. + if ($message !== false) { + $ARRAY['error'] = $message; + $ARRAY['status'] = 0; + } + else { + $ARRAY['error'] = ""; + $ARRAY['status'] = 1; + } + + // Time to graph the count of the active VLAN's on this overlay. + $COUNT_VLAN = 0; + foreach ($tblVlanEdgeDevIsAed['1.3.6.1.4.1.9.9.810.1.2.2.1.6'][$ARRAY['index']] as $v) { + if ($v == 1) { + $COUNT_VLAN++; + } + } + + $filename = "cisco-otv-".$ARRAY['label']."-vlan.rrd"; + $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename); + + if (!file_exists ($rrd_filename)) { + rrdtool_create ($rrd_filename, " DS:count:GAUGE:600:0:U" . $config['rrd_rra']); + } + $RRD['count'] = $COUNT_VLAN; + + // Update RRD + rrdtool_update ($rrd_filename, $RRD); + + } + elseif ($ARRAY['otvtype'] == 'adjacency') { + $ARRAY['uptime'] = $tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.'.$ARRAY['index'].'.1.4.'.$ARRAY['endpoint']]; + $message = false; + if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.5.'.$ARRAY['index'].'.1.4.'.$ARRAY['endpoint']] != 1) { + $message .= "Adjacency is Down\n"; + } + if ($tblAdjacencyDatabaseEntry['1.3.6.1.4.1.9.9.810.1.3.1.1.6.'.$ARRAY['index'].'.1.4.'.$ARRAY['endpoint']] < $ARRAY['uptime']) { + $message .= "Adjacency has been reset\n"; + } + + // If we have set a message, we have an error, activate alert. + if ($message !== false) { + $ARRAY['error'] = $message; + $ARRAY['status'] = 0; + } + else { + $ARRAY['error'] = ""; + $ARRAY['status'] = 1; + } + } + elseif ($ARRAY['otvtype'] == 'endpoint') { + if (isset($COUNT_MAC[$ARRAY['endpoint']])) { + $RRD['count'] = $COUNT_MAC[$ARRAY['endpoint']]; + } + else { + $RRD['count'] = "0"; + } + + $filename = "cisco-otv-".$ARRAY['endpoint']."-mac.rrd"; + $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename); + + if (!file_exists ($rrd_filename)) { + rrdtool_create ($rrd_filename, " DS:count:GAUGE:600:0:U" . $config['rrd_rra']); + } + + // Update RRD + rrdtool_update ($rrd_filename, $RRD); + + } // End If + + } // End foreach components + + // Write the Components back to the DB. + $COMPONENT->setComponentPrefs($device['device_id'],$COMPONENTS); + + echo $MODULE." "; + } // end if count components + + // Clean-up after yourself! + unset($COMPONENTS, $COMPONENT, $MODULE); +} \ No newline at end of file diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index e2d4bac01..cee0032cc 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -1268,4 +1268,70 @@ function register_mibs($device, $mibs, $included_by) } echo "\n"; + } // register_mibs + +/** + * SNMPWalk_array_num - performs a numeric SNMPWalk and returns an array containing $count indexes + * One Index: + * From: 1.3.6.1.4.1.9.9.166.1.15.1.1.27.18.655360 = 0 + * To: $array['1.3.6.1.4.1.9.9.166.1.15.1.1.27.18']['655360'] = 0 + * Two Indexes: + * From: 1.3.6.1.4.1.9.9.166.1.15.1.1.27.18.655360 = 0 + * To: $array['1.3.6.1.4.1.9.9.166.1.15.1.1.27']['18']['655360'] = 0 + * And so on... + * Think snmpwalk_cache_*_oid but for numeric data. + * + * Why is this useful? + * Some SNMP data contains a single index (eg. ifIndex in IF-MIB) and some is dual indexed + * (eg. PolicyIndex/ObjectsIndex in CISCO-CLASS-BASED-QOS-MIB). + * The resulting array allows us to easily access the top level index we want and iterate over the data from there. + * + * @param $device + * @param $OID + * @param int $indexes + * @internal param $string + * @return array + */ +function snmpwalk_array_num($device,$OID,$indexes=1) { + $array = array(); + $string = snmp_walk($device, $OID, '-Osqn'); + + if ( $string === false) { + // False means: No Such Object. + return false; + } + if ($string == "") { + // Empty means SNMP timeout or some such. + return null; + } + + // Let's turn the string into something we can work with. + foreach (explode("\n", $string) as $line) { + if ($line[0] == '.') { + // strip the leading . if it exists. + $line = substr($line,1); + } + list($key, $value) = explode(' ', $line, 2); + $prop_id = explode('.', $key); + $value = trim($value); + + // if we have requested more levels that exist, set to the max. + if ($indexes > count($prop_id)) { + $indexes = count($prop_id)-1; + } + + for ($i=0;$i<$indexes;$i++) { + // Pop the index off. + $index = array_pop($prop_id); + $value = array($index => $value); + } + + // Rebuild our key + $key = implode('.',$prop_id); + + // Add the entry to the master array + $array = array_replace_recursive($array,array($key => $value)); + } + return $array; +} From 255eb9c0cefa30d3c07ed819bfa6bc10b5b63320 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 008/104] Adding sql-schema --- sql-schema/094.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sql-schema/094.sql diff --git a/sql-schema/094.sql b/sql-schema/094.sql new file mode 100644 index 000000000..5dfced746 --- /dev/null +++ b/sql-schema/094.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); +ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_mac ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers_cbgp ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas DROP INDEX device_area, ADD UNIQUE KEY `device_area` (`device_id`,`ospfAreaId`,`context_name`); +ALTER TABLE ospf_instances ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_instances DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_instance_id`,`context_name`); +ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); +ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; \ No newline at end of file From a7c88be808e3bf35ad142935656ce8cc4a23ea34 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:05:14 +0100 Subject: [PATCH 009/104] Adding mibs --- mibs/CISCO-BRIDGE-DOMAIN-MIB | 450 +++++++++++++++++ mibs/CISCO-CONTEXT-MAPPING-MIB | 853 +++++++++++++++++++++++++++++++++ 2 files changed, 1303 insertions(+) create mode 100644 mibs/CISCO-BRIDGE-DOMAIN-MIB create mode 100644 mibs/CISCO-CONTEXT-MAPPING-MIB diff --git a/mibs/CISCO-BRIDGE-DOMAIN-MIB b/mibs/CISCO-BRIDGE-DOMAIN-MIB new file mode 100644 index 000000000..68e9ddb9c --- /dev/null +++ b/mibs/CISCO-BRIDGE-DOMAIN-MIB @@ -0,0 +1,450 @@ +-- ***************************************************************** +-- CISCO-BRIDGE-DOMAIN-MIB.my : Cisco Bridge Domain MIB +-- +-- Oct 2007, Madhavi Dokku +-- +-- Copyright (c) 2007 by Cisco Systems, Inc. +-- +-- All rights reserved. +-- ***************************************************************** + +CISCO-BRIDGE-DOMAIN-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE, + Unsigned32 + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + TEXTUAL-CONVENTION, + TruthValue, + RowStatus, + StorageType + FROM SNMPv2-TC + ifIndex + FROM IF-MIB + ciscoMgmt + FROM CISCO-SMI; + + +ciscoBridgeDomainMIB MODULE-IDENTITY + LAST-UPDATED "200712290000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + Tel: +1 800 553-NETS + + E-mail: cs-ethermibs@cisco.com" + DESCRIPTION + "A bridge domain is one of the means by which it is possible + to define a broadcast domain on a bridging device. It is an + alternative to 802.1D bridge-groups and to 802.1Q VLAN + bridging. + + Bridge domain is the service specification, and specifies the + broadcast domain number on which this frame of this particular + service instance must be made available on. The physical and + virtual interfaces that can comprise a bridge domain are + heterogeneous in nature comprising Ethernet service instances, + WAN Virtual Circuit for ATM or Frame Relay and VFIs. However, + the frame encapsulations for all interface types are + essentially Ethernet. + + Without bridge-domains, VLANs would have to be globally unique + per device and one would only be restricted to the theoretical + maximum of 4095 VLANs for single tagged traffic. However + with the introduction of bridge-domains, one can + associate a service instance with a bridge-domain and all + service instances in the same bridge-domain form a + broadcast domain. Bridge-domain ID determines the + broadcast domain and the VLAN id is merely used to match + and map traffic. With bridge domain feature configured + VLAN IDs would be unique per interface only and not globally. + Thus bridge domains make VLAN ids have only local + significance per port + + + Differences between Bridge Domains and 802.1AD Bridges: + ======================================================= + 1. Scope of the VLAN technology which uses 802.1 AD is global to + the box. + But in case of Bridge domain, the scope of vlan is local to + interface + + 2. Switchport 802.1AD restricts the number of broadcast domain + on a box to 4095. + However, with Bridge domains, we can have up to 16k broadcast + domain. + + 3. Under a single Bridge domain service instance, there can be + flexible service mapping criterion.(i.e match based on + outer vlan, outer cos, inner vlan, inner cos and payload + ethertype). + Whereas in case of switch port 802.1AD/dot1q this is not + supported. + + Similarities between Bridge Domains and 802.1AD Bridges: + ======================================================= + + 1. Both use the same MAC address lookup for forwarding. + + 2. Both work with protocols like STP, DTP etc. + + 3. Both of them classify 'ports' in a system into Bridges/Bridge + Domains. + + Ethernet service instance is the instantiation of an Ethernet + virtual circuit on a given port on a given router. In other + words, an Ethernet service instance is an object that holds + information about the layer 2 service that is being offered + on a given port of a given router as part of a given Ethernet + virtual circuit. Bridge domains feature is currently supported + on ethernet service instances only and can be later extented + to other interfaces like ATM and Frame Relay. + + This MIB helps the network management personnel to find out the + details of various broadcast domains configured in the network. + + Definition of terms and acronyms: + + ATM: Asynchronous Transfer mode + + BD: Bridge Domain + + C-mac: Customer MAC + + EVC: Ethernet Virtual Circuit + + FR: Frame Relay + + SH: Split Horizon + + VFI: Virtual Forwarding Instance + + VLAN: Virtual Local Area Network + + WAN: Wide Area Network" + REVISION "200712290000Z" + DESCRIPTION + "Modified the MIB description with details on similarities and + differences between Bridge Domains and 802.1AD Bridges." + REVISION "200712040000Z" + DESCRIPTION + "Initial version of this MIB module." + ::= { ciscoMgmt 642 } + + +ciscoBdMIBNotifications OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 0 } + +ciscoBdMIBObjects OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 1 } + +ciscoBdMIBConformance OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 2 } + +cbdSystemInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 1 } + +cbdMemberInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 2 } + + +-- Textual Conventions + +CbdType ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "Defines the different types of bridge domain members: + + 'other': none of the following + + 'ether': Ethernet Service Instance + + 'atmVc': ATM Virtual connection + + 'frVc': Frame Relay Virtual Connection" + SYNTAX INTEGER { + other(1), + ether(2), + atmVc(3), + frVc(4) + } + +cbdMembersConfigured OBJECT-TYPE + SYNTAX Unsigned32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the number of bridge domain + members configured on this bridge domain." + ::= { cbdSystemInfo 1 } +-- Member Info Table + +cbdMemberInfoTable OBJECT-TYPE + SYNTAX SEQUENCE OF CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table provides the bridge domain member attributes + of the members currently configured for each bridge + domain." + ::= { cbdMemberInfo 1 } + +cbdMemberInfoEntry OBJECT-TYPE + SYNTAX CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A conceptual row in cbdMemberInfoTable. This is indexed + by ifIndex and cbdSIIndex. Each row is created when a bridge + domain member is configured under a service instance." + INDEX { + ifIndex, + cbdSIIndex + } + ::= { cbdMemberInfoTable 1 } + +CbdMemberInfoEntry ::= SEQUENCE { + cbdSIIndex Unsigned32, + cbdMemberType CbdType, + cbdMemberOperState INTEGER , + cbdMemberAdminState INTEGER , + cbdMemberSplitHorizon TruthValue, + cbdMemberSplitHorizonNum Unsigned32, + cbdMemberStorageType StorageType, + cbdMemberStatus RowStatus, + cbdMembercMac TruthValue +} + +cbdSIIndex OBJECT-TYPE + SYNTAX Unsigned32 (1..4294967295 ) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This object indicates an arbitary index that uniquely + identifies the Service Instance to which this bridge domain + member belongs to." + ::= { cbdMemberInfoEntry 1 } + +cbdMemberType OBJECT-TYPE + SYNTAX CbdType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the type of the bridge domain member + like ATM VC, Frame Relay VC, or Ethernet service." + DEFVAL { other } + ::= { cbdMemberInfoEntry 2 } + +cbdMemberOperState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the operational state of the bridge + domain Member. Operational state of the Bridge domain member + is same as the operational state of the underlying service + instance. Bridge domain members are configured under service + instances and multiple service instances can be attached to a + single physical interface defining various kinds of services. + Bridge domain members have many to one relationship with + interface + Indexes. When ifOperStatus of the underlying interface is down, + the state of cbdMemberOperState should be down. When + ifOperStatus + of the underlying interface is up, cbdMemberOperState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is an unknown state. + + 'up': the bridge domain member is fully operational and + able to bridge the traffic. This means that both the + physical interface and the underlying service instance + are administratively up. + + 'down': the Bridge Domain member is down and not + capable of bridging. This state means either the underlying + service instance is down or the interface is down." + ::= { cbdMemberInfoEntry 3 } + +cbdMemberAdminState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the administrative state of the + bridge domain Member. Admin state of the Bridge domain member + is same as the admin state of the underlying service instance. + Bridge domain members are configured under service instances + and multiple service instances can be attached to a single + physical interface defining various kinds of services. Bridge + Domain members have many to one relationship with interface + Indexes. When ifAdminStatus of the unerlying interface is down + the state of cbdMemberAdminState should be down. When ifOperStatus + of the underlying interface is up cbdMemberAdminState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is in unknown + administrative state. + + 'up': the Bridge Domain member is administratively up. This + means that both the physical interface and the underlying service + instance are administratively up. + + 'admindown': the Bridge Domain member is down as it is + administratively configured to be down and is not + capable of bridging. This means that either the underlying + service instance is configured as administratively down or + the physical interface is configured as administratively + down." + ::= { cbdMemberInfoEntry 4 } + +cbdMemberSplitHorizon OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates whether split horizon is + configured on this bridge domain member." + ::= { cbdMemberInfoEntry 5 } + +cbdMemberSplitHorizonNum OBJECT-TYPE + SYNTAX Unsigned32 (0..65535 ) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the split horizon number if + configured on the bridge domain member. Split horizon + is used to avoid sending traffic between interfaces. + Frames are not forwarded to the members belonging to the + same split horizon group." + DEFVAL { 0 } + ::= { cbdMemberInfoEntry 6 } + +cbdMemberStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object specifies the storage type of this conceptual + row. This object can only have a value 'nonVolatile'. Other + values are not applicable for this conceptual row and are + not supported." + DEFVAL { nonVolatile } + ::= { cbdMemberInfoEntry 7 } + +cbdMemberStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object enables the SNMP agent to create, modify, + and delete rows in the cbdMemberInfoTable." + DEFVAL { active } + ::= { cbdMemberInfoEntry 8 } + +cbdMembercMac OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates if cmac is configured on this + bridge domain member. Cmac denotes if this bridge domain is + configured as a customer domain." + ::= { cbdMemberInfoEntry 9 } + + +-- Notifications + +ciscoBdNotificationPrefix OBJECT IDENTIFIER + ::= { ciscoBdMIBNotifications 0 } + +-- Conformance + +ciscoBdMIBCompliances OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 1 } + +ciscoBdMIBGroups OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 2 } + + +ciscoBdMIBComplianceRev1 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-BRIDGE-DOMAIN-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cbdSystemInfoGroup, + cbdMemberInfoGroup + } + ::= { ciscoBdMIBCompliances 1 } + +-- Units of Conformance + +cbdSystemInfoGroup OBJECT-GROUP + OBJECTS { cbdMembersConfigured } + STATUS current + DESCRIPTION + "This group contain information about bridge domain." + ::= { ciscoBdMIBGroups 1 } + +cbdMemberInfoGroup OBJECT-GROUP + OBJECTS { + cbdMemberType, + cbdMemberOperState, + cbdMemberAdminState, + cbdMemberSplitHorizon, + cbdMemberSplitHorizonNum, + cbdMemberStorageType, + cbdMemberStatus, + cbdMembercMac + } + STATUS current + DESCRIPTION + "This group contain information related to bridge domain + members." + ::= { ciscoBdMIBGroups 2 } + +END + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mibs/CISCO-CONTEXT-MAPPING-MIB b/mibs/CISCO-CONTEXT-MAPPING-MIB new file mode 100644 index 000000000..94451564d --- /dev/null +++ b/mibs/CISCO-CONTEXT-MAPPING-MIB @@ -0,0 +1,853 @@ +-- ***************************************************************** +-- CISCO-CONTEXT-MAPPING-MIB.my: Cisco Context Mapping MIB +-- +-- January 2005, Chinna Pellacuru. +-- +-- May 2008, Sheethal Gunjal. +-- +-- Copyright (c) 2004-2005, 2008 by cisco Systems Inc. +-- All rights reserved. +-- +-- **************************************************************** + +CISCO-CONTEXT-MAPPING-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + SnmpAdminString + FROM SNMP-FRAMEWORK-MIB + RowStatus, + StorageType + FROM SNMPv2-TC + CiscoBridgeDomain + FROM CISCO-TC + ciscoMgmt + FROM CISCO-SMI; + + +ciscoContextMappingMIB MODULE-IDENTITY + LAST-UPDATED "200811220000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + + Tel: +1 800 553-NETS + + E-mail: cs-snmp@cisco.com" + DESCRIPTION + "A single SNMP agent sometimes needs to support multiple + instances of the same MIB module, and does so through the + use of multiple SNMP contexts. This typically occurs because + the technology has evolved to have extra dimension(s), i.e., + one or more extra data and/or identifier values which are + different in the different contexts, but were not defined in + INDEX clause(s) of the original MIB module. In such cases, + network management applications need to know the specific + data/identifier values in each context, and this MIB module + provides mapping tables which contain that information. + + Within a network there can be multiple Virtual Private + Networks (VPNs) configured using Virtual Routing and + Forwarding Instances (VRFs). Within a VPN there can be + multiple topologies when Multi-topology Routing (MTR) is + used. Also, Interior Gateway Protocols (IGPs) can have + multiple protocol instances running on the device. + A network can have multiple broadcast domains configured + using Bridge Domain Identifiers. + + With MTR routing, VRFs, and Bridge domains, a router now + needs to support multiple instances of several existing + MIB modules, and this can be achieved if the router's SNMP + agent provides access to each instance of the same MIB module + via a different SNMP context (see Section 3.1.1 of RFC 3411). + For MTR routing, VRFs, and Bridge domains, a different SNMP + context is needed depending on one or more of the following: + the VRF, the topology-identifier, the routing protocol instance, + and the bridge domain identifier. + In other words, the router's management information can be + accessed through multiple SNMP contexts where each such + context represents a specific VRF, a specific + topology-identifier, a specific routing protocol instance + and/or a bridge domain identifier. This MIB module provides + a mapping of each such SNMP context to the corresponding VRF, + the corresponding topology, the corresponding routing protocol + instance, and the corresponding bridge domain identifier. + Some SNMP contexts are independent of VRFs, independent of + a topology, independent of a routing protocol instance, or + independent of a bridge domain and in such a case, the mapping + is to the zero length string. + + With the Cisco package licensing strategy, the features + available in the image are grouped into multiple packages + and each packages can be managed to operate at different + feature levels based on the available license. This MIB + module provides option to associate an SNMP context to a + feature package group. This will allow manageability of + license MIB objects specific to a feature package group. + + As technology evolves more we may need additional + identifiers to identify the context. Then we would need + to add those additional identifiers into the mapping." + REVISION "200811220000Z" + DESCRIPTION + "Added New Table cContextMappingLicenseGroupTable + to provide SNMP Context support for license package groups. + + Added cContextMappingLicenseGroupDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev2 in MODULE-COMPLIANCE + + Updated the MIB description to indicate the use of + the above additions" + REVISION "200805300000Z" + DESCRIPTION + "Add cContextMappingBridgeInstanceTable. + + Added cContextMappingBridgeInstanceDataGroup. + Deprecated cContextMappingMIBComplianceRev1 and added + cContextMappingMIBComplianceRev2 compliance statement." + REVISION "200802010000Z" + DESCRIPTION + "Added New Table cContextMappingBridgeDomainTable + to provide SNMP context support to the Bridge Domain. + + Added cContextMappingBridgeDomainDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev1 in MODULE-COMPLIANCE" + REVISION "200503170000Z" + DESCRIPTION + "Initial version of the MIB module." + ::= { ciscoMgmt 468 } + + +cContextMappingMIBObjects OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 1 } + +cContextMappingMIBConformance OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 2 } + + +cContextMappingTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which VRF, topology, and routing protocol instance. + + This table is indexed by SNMP VACM context. + + Configuring a row in this table for an SNMP context + does not require that the context be already defined, + i.e., a row can be created in this table for a context + before the corresponding row is created in RFC 3415's + vacmContextTable. + + To create a row in this table, a manager must set + cContextMappingRowStatus to either 'createAndGo' or + 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingRowStatus to 'destroy'." + ::= { cContextMappingMIBObjects 1 } + +cContextMappingEntry OBJECT-TYPE + SYNTAX CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the corresponding VRF, + the corresponding topology, and the corresponding routing + protocol instance." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingTable 1 } + +CContextMappingEntry ::= SEQUENCE { + cContextMappingVacmContextName SnmpAdminString, + cContextMappingVrfName SnmpAdminString, + cContextMappingTopologyName SnmpAdminString, + cContextMappingProtoInstName SnmpAdminString, + cContextMappingStorageType StorageType, + cContextMappingRowStatus RowStatus +} + +cContextMappingVacmContextName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The vacmContextName given to the SNMP context. + + This is a human readable name identifying a particular + SNMP VACM context at a particular SNMP entity. + The empty contextName (zero length) represents the + default context." + ::= { cContextMappingEntry 1 } + +cContextMappingVrfName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the VRF to which the SNMP context + is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this VRF. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any VRF." + DEFVAL { ''H } + ::= { cContextMappingEntry 2 } + +cContextMappingTopologyName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the topology to which the SNMP + context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this topology. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any topology." + DEFVAL { ''H } + ::= { cContextMappingEntry 3 } + +cContextMappingProtoInstName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the protocol instance to which the + SNMP context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this protocol instance. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any protocol instance." + DEFVAL { ''H } + ::= { cContextMappingEntry 4 } + +cContextMappingStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingEntry 5 } + +cContextMappingRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingEntry 6 } + + + +cContextMappingBridgeDomainTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which bridge domain. + + A Bridge Domain is one of the means by which it is possible + to define an Ethernet broadcast domain on a bridging device. + A network can have multiple broadcast domains configured. + This table helps the network management personnel to find + out the details of various broadcast domains configured + in the network. + + An entry need to exist in cContextMappingTable, to create + an entry in this table." + ::= { cContextMappingMIBObjects 2 } + +cContextMappingBridgeDomainEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge domain. + + To create a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeDomainTable 1 } + +CContextMappingBridgeDomainEntry ::= SEQUENCE { + cContextMappingBridgeDomainIdentifier CiscoBridgeDomain, + cContextMappingBridgeDomainStorageType StorageType, + cContextMappingBridgeDomainRowStatus RowStatus +} + +cContextMappingBridgeDomainIdentifier OBJECT-TYPE + SYNTAX CiscoBridgeDomain + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the bridge domain to which the SNMP context is + mapped to." + REFERENCE "CISCO-BRIDGE-DOMAIN-MIB" + ::= { cContextMappingBridgeDomainEntry 1 } + +cContextMappingBridgeDomainStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeDomainEntry 2 } + +cContextMappingBridgeDomainRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeDomainEntry 3 } + + + +cContextMappingBridgeInstanceTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on mapping between + cContextMappingVacmContextName and bridge instance. + + Bridge instance is an instance of a physical or logical + bridge which has unique bridge-id. + + If an entry is deleted from cContextMappingTable, the + corresponding entry in this table will also get deleted. + + If an entry needs to be created in this table, the + corresponding entry must exist in cContextMappingTable." + REFERENCE "BRIDGE-MIB" + ::= { cContextMappingMIBObjects 3 } + +cContextMappingBridgeInstanceEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge instance. + + To create a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeInstanceTable 1 } + +CContextMappingBridgeInstanceEntry ::= SEQUENCE { + cContextMappingBridgeInstName SnmpAdminString, + cContextMappingBridgeInstStorageType StorageType, + cContextMappingBridgeInstRowStatus RowStatus +} + +cContextMappingBridgeInstName OBJECT-TYPE + SYNTAX SnmpAdminString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The object identifies the name given to bridge + instance to which the SNMP context is mapped to. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this bridge instance. + + When the value of this object is a zero length + string, it indicates that the SNMP context is + independent of any bridge instances." + ::= { cContextMappingBridgeInstanceEntry 1 } + +cContextMappingBridgeInstStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeInstanceEntry 2 } + +cContextMappingBridgeInstRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeInstanceEntry 3 } + + + +cContextMappingLicenseGroupTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which License Group. + Group level licensing is used where each + Technology Package is enabled via a License." + ::= { cContextMappingMIBObjects 4 } + +cContextMappingLicenseGroupEntry OBJECT-TYPE + SYNTAX CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + CContextMappingVacmContextName to the + corresponding License Group." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingLicenseGroupTable 1 } + +CContextMappingLicenseGroupEntry ::= SEQUENCE { + cContextMappingLicenseGroupName SnmpAdminString, + cContextMappingLicenseGroupStorageType StorageType, + cContextMappingLicenseGroupRowStatus RowStatus +} + +cContextMappingLicenseGroupName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the Group to which the SNMP context + is mapped. + + Feature sets from all groups will be combined to form + universal image. User can configure multiple groups as needed. + + For example: In Next generation ISRs will use + the universal image package level licensing model + for its licensing need. Each group has + the feature set needed for that specific technology. + Feature sets from different groups are combined to + form universal image and each feature set for a group + can be enabled using a valid license key. There will + be a base level ipbase package in which the router + boots with out any license key. + + The following are the different Technology Groups. + 1.crypto + 2.data + 3.ip + 4.legacy + 5.novpn-security + 6.security + 7.uc" + ::= { cContextMappingLicenseGroupEntry 1 } + +cContextMappingLicenseGroupStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingLicenseGroupEntry 2 } + +cContextMappingLicenseGroupRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingLicenseGroupEntry 3 } + + +-- Conformance + +cContextMappingMIBCompliances OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 1 } + +cContextMappingMIBGroups OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 2 } + + +-- Compliance + +cContextMappingMIBCompliance MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { cContextMappingDataGroup } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 1 } + +cContextMappingMIBComplianceRev1 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB. This compliance statement + is superceded by cContextMappingMIBComplianceRev2." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 2 } + +cContextMappingMIBComplianceRev2 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + ::= { cContextMappingMIBCompliances 3 } + +cContextMappingMIBComplianceRev3 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup, + cContextMappingLicenseGroupDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + + OBJECT cContextMappingLicenseGroupName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 4 } + +-- Units of Conformance + +cContextMappingDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingVrfName, + cContextMappingTopologyName, + cContextMappingProtoInstName, + cContextMappingStorageType, + cContextMappingRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding VRF, the corresponding topology, + and the corresponding routing protocol instance." + ::= { cContextMappingMIBGroups 1 } + +cContextMappingBridgeDomainDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeDomainIdentifier, + cContextMappingBridgeDomainStorageType, + cContextMappingBridgeDomainRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge domain." + ::= { cContextMappingMIBGroups 2 } + +cContextMappingBridgeInstanceDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeInstName, + cContextMappingBridgeInstStorageType, + cContextMappingBridgeInstRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge instance." + ::= { cContextMappingMIBGroups 3 } + +cContextMappingLicenseGroupDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingLicenseGroupName, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding LicenseGroupName." + ::= { cContextMappingMIBGroups 4 } + +END + + + + + + + + From 831940c0a18771f66896f3ae137c14748f7e147a Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:13:53 +0100 Subject: [PATCH 010/104] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 158 ++++--- includes/discovery/bgp-peers.inc.php | 378 ++++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 114 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 125 +++-- includes/polling/ospf.inc.php | 548 +++++++++++----------- includes/snmp.inc.php | 8 +- 11 files changed, 957 insertions(+), 682 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index 63e167899..5b2c3f71c 100644 --- a/includes/common.php +++ b/includes/common.php @@ -290,6 +290,16 @@ function device_by_id_cache($device_id, $refresh = '0') { } else { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id)); + + //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time + $vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id)); + $device['vrf_lite_cisco'] = array(); + if(!empty($vrfs_lite_cisco)){ + foreach ($vrfs_lite_cisco as $vrf){ + $device['vrf_lite_cisco'][$vrf['context_name']] = $vrf; + } + } + $cache['devices']['id'][$device_id] = $device; } return $device; diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 328ae2ce0..a418f7477 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ $config['enable_pseudowires'] = 1; // Enable Pseudowires $config['enable_vrfs'] = 1; // Enable VRFs +$config['enable_vrf_lite_cisco'] = 1; +// Enable VRF lite cisco $config['enable_printers'] = 0; // Enable Printer support $config['enable_sla'] = 0; @@ -734,6 +736,7 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; // $config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index 69b0d9b75..c60d4ca95 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ unset($mac_table); echo 'ARP Table : '; -$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); -$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); -$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); - -foreach (explode("\n", $ipNetToMedia_data) as $data) { - list($oid, $mac) = explode(' ', $data); - list($if, $first, $second, $third, $fourth) = explode('.', $oid); - $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; - if ($ip != '...') { - $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); - - list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); - $m_a = zeropad($m_a); - $m_b = zeropad($m_b); - $m_c = zeropad($m_c); - $m_d = zeropad($m_d); - $m_e = zeropad($m_e); - $m_f = zeropad($m_f); - $md_a = hexdec($m_a); - $md_b = hexdec($m_b); - $md_c = hexdec($m_c); - $md_d = hexdec($m_d); - $md_e = hexdec($m_e); - $md_f = hexdec($m_f); - $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; - - $mac_table[$if][$mac]['ip'] = $ip; - $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; - $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; - $mac_table[$if][$mac]['cleanmac'] = $clean_mac; - $port_id = $interface['port_id']; - $mac_table[$port_id][$clean_mac] = 1; - - if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) { - // Commented below, no longer needed but leaving for reference. - // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; - $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id'])); - - if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { - d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); - - log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); - } - - dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); - echo '.'; - } - else if (isset($interface['port_id'])) { - echo '+'; - // echo("Add MAC $mac\n"); - $insert_data = array( - 'port_id' => $interface['port_id'], - 'mac_address' => $clean_mac, - 'ipv4_address' => $ip, - ); - - dbInsert($insert_data, 'ipv4_mac'); - }//end if - }//end if -}//end foreach - -$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'"; -foreach (dbFetchRows($sql) as $entry) { - $entry_mac = $entry['mac_address']; - $entry_if = $entry['port_id']; - if (!$mac_table[$entry_if][$entry_mac]) { - dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); - d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); - - echo '-'; - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; + + $ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); + $ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); + $ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); -echo "\n"; -unset($mac); + foreach (explode("\n", $ipNetToMedia_data) as $data) { + list($oid, $mac) = explode(' ', $data); + list($if, $first, $second, $third, $fourth) = explode('.', $oid); + $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; + if ($ip != '...') { + $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); + + list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); + $m_a = zeropad($m_a); + $m_b = zeropad($m_b); + $m_c = zeropad($m_c); + $m_d = zeropad($m_d); + $m_e = zeropad($m_e); + $m_f = zeropad($m_f); + $md_a = hexdec($m_a); + $md_b = hexdec($m_b); + $md_c = hexdec($m_c); + $md_d = hexdec($m_d); + $md_e = hexdec($m_e); + $md_f = hexdec($m_f); + $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; + + $mac_table[$if][$mac]['ip'] = $ip; + $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; + $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; + $mac_table[$if][$mac]['cleanmac'] = $clean_mac; + $port_id = $interface['port_id']; + $mac_table[$port_id][$clean_mac] = 1; + + if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']))) { + // Commented below, no longer needed but leaving for reference. + // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; + $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=? AND `context_name`= ?', array($ip, $interface['port_id']), $device['context_name']); + + if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { + d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); + + log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); + } + + dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name'])); + echo '.'; + } + else if (isset($interface['port_id'])) { + echo '+'; + // echo("Add MAC $mac\n"); + $insert_data = array( + 'port_id' => $interface['port_id'], + 'mac_address' => $clean_mac, + 'ipv4_address' => $ip, + 'context_name' => $device['context_name'], + ); + + dbInsert($insert_data, 'ipv4_mac'); + }//end if + }//end if + }//end foreach + + $sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = ' AND `context_name`= ?".$device['device_id']." AND M.context_name='". $device['context_name'] ."'"; + foreach (dbFetchRows($sql) as $entry) { + $entry_mac = $entry['mac_address']; + $entry_if = $entry['port_id']; + if (!$mac_table[$entry_if][$entry_mac]) { + dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ? AND `context_name`= ?', array($entry_if, $entry_mac, $device['context_name'])); + d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); + + echo '-'; + } + } + echo "\n"; + unset($mac); + unset($device['context_name']); +} +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf..dd341715d 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -3,232 +3,246 @@ if ($config['enable_bgp']) { // Discover BGP peers echo 'BGP Sessions : '; - + + if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; + } + else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); + } + $bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB', $config['mibdir'])); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + if (is_numeric($bgpLocalAs)) { + echo "AS$bgpLocalAs "; - if (is_numeric($bgpLocalAs)) { - echo "AS$bgpLocalAs "; - - if ($bgpLocalAs != $device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); - echo 'Updated AS '; - } - - $peer2 = false; - $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); - if (empty($peers_data)) { - $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); - } - else { - $peer2 = true; - } - - d_echo("Peers : $peers_data \n"); - - $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); - $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - - foreach (explode("\n", $peers) as $peer) { - if ($peer2 === true) { - list($ver, $peer) = explode('.', $peer, 2); + if ($bgpLocalAs != $device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); + echo 'Updated AS '; } - list($peer_ip, $peer_as) = explode(' ', $peer); - if (strstr($peer_ip, ':')) { - $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); - $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); - $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + $peer2 = false; + $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); + if (empty($peers_data)) { + $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); + } + else { + $peer2 = true; } - if ($peer && $peer_ip != '0.0.0.0') { - d_echo("Found peer $peer_ip (AS$peer_as)\n"); + d_echo("Peers : $peers_data \n"); - $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, - 'ver' => $ver, - ); - } - } + $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); + $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - if ($device['os'] == 'junos') { - // Juniper BGP4-V2 MIB - // FIXME: needs a big cleanup! also see below. - // FIXME: is .0.ipv6 the only possible value here? - $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); foreach (explode("\n", $peers) as $peer) { - list($peer_ip_snmp, $peer_as) = explode(' ', $peer); + if ($peer2 === true) { + list($ver, $peer) = explode('.', $peer, 2); + } - // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. - $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + list($peer_ip, $peer_as) = explode(' ', $peer); + if (strstr($peer_ip, ':')) { + $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); + $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); + $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + } - if ($peer) { + if ($peer && $peer_ip != '0.0.0.0') { d_echo("Found peer $peer_ip (AS$peer_as)\n"); $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, + 'ip' => $peer_ip, + 'as' => $peer_as, + 'ver' => $ver, ); } } - } - } - else { - echo 'No BGP on host'; - if ($device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); - echo ' (Removed ASN) '; - } - } - // Process disovered peers - if (isset($peerlist)) { - foreach ($peerlist as $peer) { - $astext = get_astext($peer['as']); + if ($device['os'] == 'junos') { + // Juniper BGP4-V2 MIB + // FIXME: needs a big cleanup! also see below. + // FIXME: is .0.ipv6 the only possible value here? + $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); + foreach (explode("\n", $peers) as $peer) { + list($peer_ip_snmp, $peer_as) = explode(' ', $peer); - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') { - $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as']), 'bgpPeers'); - if ($config['autodiscovery']['bgp'] === true) { - $name = gethostbyaddr($peer['ip']); - $remote_device_id = discover_new_device($name, $device, 'BGP'); + // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. + $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + + if ($peer) { + d_echo("Found peer $peer_ip (AS$peer_as)\n"); + + $peerlist[] = array( + 'ip' => $peer_ip, + 'as' => $peer_as, + ); + } + } + } + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; + } + } + + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); + + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $device['context_name'])) < '1') { + $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'],'context_name' => $device['context_name']), 'bgpPeers'); + if ($config['autodiscovery']['bgp'] === true) { + $name = gethostbyaddr($peer['ip']); + $remote_device_id = discover_new_device($name, $device, 'BGP'); + } + + echo '+'; + } + else { + $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); + echo '.'; } - echo '+'; - } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; - } + if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { + if ($device['os_group'] == 'cisco') { + // Get afi/safi and populate cbgp on cisco ios (xe/xr) + unset($af_list); - if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { - if ($device['os_group'] == 'cisco') { - // Get afi/safi and populate cbgp on cisco ios (xe/xr) - unset($af_list); - - if ($peer2 === true) { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - else { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - - d_echo('afi data :: '); - d_echo($af_data); - - foreach ($af_data as $k => $v) { if ($peer2 === true) { - list(,$k) = explode('.', $k, 2); + $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); + } + else { + $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); } - d_echo("AFISAFI = $k\n"); + d_echo('afi data :: '); + d_echo($af_data); - $afisafi_tmp = explode('.', $k); - $safi = array_pop($afisafi_tmp); - $afi = array_pop($afisafi_tmp); - $bgp_ip = str_replace(".$afi.$safi", '', $k); - $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); - $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); - $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); - if ($afi && $safi && $bgp_ip == $peer['ip']) { - $af_list[$bgp_ip][$afi][$safi] = 1; + foreach ($af_data as $k => $v) { + if ($peer2 === true) { + list(,$k) = explode('.', $k, 2); + } + + d_echo("AFISAFI = $k\n"); + + $afisafi_tmp = explode('.', $k); + $safi = array_pop($afisafi_tmp); + $afi = array_pop($afisafi_tmp); + $bgp_ip = str_replace(".$afi.$safi", '', $k); + $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); + $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); + $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); + if ($afi && $safi && $bgp_ip == $peer['ip']) { + $af_list[$bgp_ip][$afi][$safi] = 1; + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=? AND `context_name`=?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])) == 0) { + dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); + } + } + } + } + + if ($device['os'] == 'junos') { + $safis[1] = 'unicast'; + $safis[2] = 'multicast'; + + if (!isset($j_peerIndexes)) { + $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + + foreach ($j_bgp as $index => $entry) { + switch ($entry['jnxBgpM2PeerRemoteAddrType']) { + case 'ipv4': + $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); + d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; + break; + + case 'ipv6': + $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); + $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); + $ip6 = Net_IPv6::compress($ip6); + d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; + + default: + echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; + break; + } + } + } + + if (!isset($j_afisafi)) { + $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + foreach (array_keys($j_prefixes) as $key) { + list($index,$afisafi) = explode('.', $key, 2); + $j_afisafi[$index][] = $afisafi; + } + } + + foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { + list ($afi,$safi) = explode('.', $afisafi); + $safi = $safis[$safi]; + $af_list[$afi][$safi] = 1; if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); } } } - } - if ($device['os'] == 'junos') { - $safis[1] = 'unicast'; - $safis[2] = 'multicast'; - - if (!isset($j_peerIndexes)) { - $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - - foreach ($j_bgp as $index => $entry) { - switch ($entry['jnxBgpM2PeerRemoteAddrType']) { - case 'ipv4': - $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); - d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; - break; - - case 'ipv6': - $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); - $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); - $ip6 = Net_IPv6::compress($ip6); - d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; - break; - - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - break; - } + $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND `context_name` = '" . $device['context_name'] . "'"; + foreach (dbFetchRows($af_query) as $entry) { + $afi = $entry['afi']; + $safi = $entry['safi']; + if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { + dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])); } } - - if (!isset($j_afisafi)) { - $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - foreach (array_keys($j_prefixes) as $key) { - list($index,$afisafi) = explode('.', $key, 2); - $j_afisafi[$index][] = $afisafi; - } - } - - foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { - list ($afi,$safi) = explode('.', $afisafi); - $safi = $safis[$safi]; - $af_list[$afi][$safi] = 1; - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { - dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); - } - } - } - - $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"; - foreach (dbFetchRows($af_query) as $entry) { - $afi = $entry['afi']; - $safi = $entry['safi']; - if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { - dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); - } } } + + unset($j_afisafi); + unset($j_prefixes); + unset($j_bgp); + unset($j_peerIndexes); } - unset($j_afisafi); - unset($j_prefixes); - unset($j_bgp); - unset($j_peerIndexes); - } + // Delete removed peers + $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."' AND `context_name` = '" . $device['context_name'] . "'"; - // Delete removed peers - $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; + foreach (dbFetchRows($sql) as $entry) { + unset($exists); + $i = 0; - foreach (dbFetchRows($sql) as $entry) { - unset($exists); - $i = 0; + while ($i < count($peerlist) && !isset($exists)) { + if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { + $exists = 1; + } - while ($i < count($peerlist) && !isset($exists)) { - if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { - $exists = 1; + $i++; } - $i++; + if (!isset($exists)) { + dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + echo '-'; + } } - if (!isset($exists)) { - dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - echo '-'; - } + unset($peerlist); + + echo "\n"; + unset($device['context_name']); } - - unset($peerlist); - - echo "\n"; + unset($device['context_name']); + unset($vrfs_c); } diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php new file mode 100644 index 000000000..ae2aff0e4 --- /dev/null +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -0,0 +1,142 @@ + and Mathieu Millet +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . */ + + +global $debug; + +// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco +if ($config['enable_vrf_lite_cisco']) { + + $ids = array(); + + // For the moment only will be cisco and the version 3 + if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') { + + echo ("VRF lite cisco : \n"); + $mib = "SNMP-COMMUNITY-MIB"; + + $mib = "CISCO-CONTEXT-MAPPING-MIB"; + //-Osq because if i put the n the oid from the first command is not the same of this one + $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); + $listVrf = str_replace("cContextMappingVrfName.", "", $listVrf); + $listVrf = str_replace('"', "", $listVrf); + $listVrf = trim($listVrf); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); + } + + $tableVrf; + foreach (explode("\n", $listVrf) as $lineVrf) { + $tmpVrf = explode(" ", $lineVrf, 2); + //the $tmpVrf[0] will be the context + if (count($tmpVrf) == 2 && !empty($tmpVrf[1])) { + $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1]; + } + } + + unset($listVrf); + + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); + $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); + $listIntance = str_replace('"', "", $listIntance); + $listIntance = trim($listIntance); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + } + + + foreach (explode("\n", $listIntance) as $lineIntance) { + $tmpIntance = explode(" ", $lineIntance, 2); + //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance + if (count($tmpIntance) == 2 && !empty($tmpIntance[1])) { + $tableVrf[$tmpIntance[0]]['intance_name'] = $tmpIntance[1]; + } + } + unset($listIntance); + + + foreach ($tableVrf as $context => $vrf) { + + + + if ($debug) { + + echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n"); + } + + $tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", array( + $device ['device_id'], + $context + )); + if (!empty($tmpVrf)) { + + $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id']; + + $vrfUpdate=array(); + + foreach ($vrfUpdate as $key => $value) { + if($vrf[$key]!=$value){ + $vrfUpdate[$key]=$value; + } + } + if (!empty($vrfUpdate)) { + dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array( + $tmp['vrf_lite_cisco_id'] + )); + } + } else { + + $id = dbInsert(array( + 'device_id' => $device ['device_id'], + 'context_name' => $context, + 'intance_name' => $vrf['intance_name'], + 'vrf_name' => $vrf['vrf_name'] + ), 'vrf_lite_cisco'); + + $ids[$id] = $id; + } + } + + unset($tableVrf); + } + + //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work + $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( + $device ['device_id'])); + + $device['vrf_lite_cisco'] = $tmpVrfC; + + //Delete all vrf that chaged + foreach ($tmpVrfC as $vrfC) { + unset($ids[$vrfC['vrf_lite_cisco_id']]); + } + if (!empty($ids)) { + foreach ($ids as $id) { + + dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array( + $id)); + } + } + + + unset($ids); + unset($tmpVrfC); +} // enable_vrf_lite_cisco +?> diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index b03ac9048..e8055e63c 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -669,8 +669,8 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity }//end discover_toner() - -function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin) { + +function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name='') { global $device,$config; $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen").'/'.$ipv6_prefixlen; @@ -683,21 +683,21 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') { $port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } // Below looks like a duplicate of the above FIXME - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } - $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)); + $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { - dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id), 'ipv6_addresses'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ? AND `context_name` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { + dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses'); echo '+'; } else { diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 53cf3ad57..26fc9ba28 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ network.'/'.$addr->bitmask; - $cidr = $addr->bitmask; - - if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { - $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') { - dbInsert(array('ipv4_network' => $network), 'ipv4_networks'); - // echo("Create Subnet $network\n"); - echo 'S'; - } - - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)) == '0') { - dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id), 'ipv4_addresses'); - // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); - echo '+'; - } - else { - echo '.'; - } - - $full_address = "$oid/$cidr|$ifIndex"; - $valid_v4[$full_address] = 1; - } - else { - echo '!'; - }//end if -}//end foreach - -$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; - - if (!$valid_v4[$full_address]) { - echo '-'; - $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { - $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); - } - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -echo "\n"; + $oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB')); + $oids = str_replace('ipAdEntIfIndex.', '', $oids); + foreach (explode("\n", $oids) as $data) { + $data = trim($data); + list($oid,$ifIndex) = explode(' ', $data); + $mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB')); + $addr = Net_IPv4::parseAddress("$oid/$mask"); + $network = $addr->network.'/'.$addr->bitmask; + $cidr = $addr->bitmask; -unset($valid_v4); + if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { + $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name` = ?', array($network, $device['context_name'])) < '1') { + dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks'); + // echo("Create Subnet $network\n"); + echo 'S'; + } + + $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name`= ?', array($network, $device['context_name'])); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? and `context_name`=?', array($oid, $cidr, $port_id, $device['context_name'])) == '0') { + dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id,'context_name' => $device['context_name']), 'ipv4_addresses'); + // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); + echo '+'; + } + else { + echo '.'; + } + + $full_address = "$oid/$cidr|$ifIndex"; + $valid_v4[$full_address] = 1; + } + else { + echo '!'; + }//end if + }//end foreach + + $sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND a.context_name= '" . $device['context_name'] . "'"; + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; + + if (!$valid_v4[$full_address]) { + echo '-'; + $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { + $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); + } + } + } + + echo "\n"; + unset($device['context_name']); + unset($valid_v4); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index 562428b6b..f7762ee98 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -1,78 +1,89 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); -$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); -$oids = str_replace('"', '', $oids); -$oids = str_replace('IP-MIB::', '', $oids); -$oids = trim($oids); - -foreach (explode("\n", $oids) as $data) { - if ($data) { - $data = trim($data); - list($ipv6addr,$ifIndex) = explode(' ', $data); - $oid = ''; - $sep = ''; - $adsep = ''; - unset($ipv6_address); - $do = '0'; - foreach (explode(':', $ipv6addr) as $part) { - $n = hexdec($part); - $oid = "$oid"."$sep"."$n"; - $sep = '.'; - $ipv6_address = $ipv6_address."$adsep".$part; - $do++; - if ($do == 2) { - $adsep = ':'; - $do = '0'; - } - else { - $adsep = ''; - } - } - - $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); - $ipv6_prefixlen = explode('.', $ipv6_prefixlen); - $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); - - $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); - - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); - } //end if -} //end foreach - -if (!$oids) { - $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); - $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); + $oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); $oids = str_replace('"', '', $oids); + $oids = str_replace('IP-MIB::', '', $oids); $oids = trim($oids); foreach (explode("\n", $oids) as $data) { if ($data) { - $data = trim($data); - list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); - list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); - $ipv6_address = snmp2ipv6($ipv6addr); - $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); + $data = trim($data); + list($ipv6addr,$ifIndex) = explode(' ', $data); + $oid = ''; + $sep = ''; + $adsep = ''; + unset($ipv6_address); + $do = '0'; + foreach (explode(':', $ipv6addr) as $part) { + $n = hexdec($part); + $oid = "$oid"."$sep"."$n"; + $sep = '.'; + $ipv6_address = $ipv6_address."$adsep".$part; + $do++; + if ($do == 2) { + $adsep = ':'; + $do = '0'; + } + else { + $adsep = ''; + } + } + + $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); + $ipv6_prefixlen = explode('.', $ipv6_prefixlen); + $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); + + $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); + + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); } //end if } //end foreach -} //end if -$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; + if (!$oids) { + $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); + $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = str_replace('"', '', $oids); + $oids = trim($oids); -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; - $port_id = $row['port_id']; - $valid_address = $full_address.'-'.$port_id; - if (!$valid['ipv6'][$valid_address]) { - echo '-'; - $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { - $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + foreach (explode("\n", $oids) as $data) { + if ($data) { + $data = trim($data); + list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); + list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); + $ipv6_address = snmp2ipv6($ipv6addr); + $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); + } //end if + } //end foreach + } //end if + + $sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND A.context_name= '" . $device['context_name'] . "'"; + + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; + $port_id = $row['port_id']; + $valid_address = $full_address.'-'.$port_id; + if (!$valid['ipv6'][$valid_address]) { + echo '-'; + $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { + $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + } } } -} -echo "\n"; + echo "\n"; + unset($device['context_name']); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index 56863ec10..40ff425a0 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -2,6 +2,9 @@ if ($config['enable_bgp']) { foreach (dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])) as $peer) { + //add context if exist + $device['context_name']= $peer['context_name']; + // Poll BGP Peer $peer2 = false; echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' '; @@ -62,14 +65,28 @@ if ($config['enable_bgp']) { } } else { - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; - $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; - $peer_data = trim(`$peer_cmd`); + // $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; + $oids = "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . ""; + $peer_data=snmp_get_multi($device,$oids,'-OUQs','BGP4-MIB'); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } }//end if - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + //list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + unset($peer_data); } else if ($device['os'] == 'junos') { // v6 for JunOS via Juniper MIB @@ -78,9 +95,9 @@ if ($config['enable_bgp']) { if (!isset($junos_v6)) { echo "\nCaching Oids..."; // FIXME - needs moved to function - $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; - foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { + //$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + + foreach (explode("\n",snmp_get($device,'jnxBgpM2PeerStatus.0.ipv6"','-OUnq','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos")) as $oid){ list($peer_oid) = explode(' ', $oid); $peer_id = explode('.', $peer_oid); $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); @@ -88,25 +105,34 @@ if ($config['enable_bgp']) { } // FIXME - move to function (and clean up, wtf?) - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); - $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; - $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; - // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? - $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= '|grep -v "No Such Instance"'; - d_echo("\n$peer_cmd\n"); - - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + + $oids = " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip]; # Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? + $oids .= " jnxBgpM2PeerInUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerFsmEstablishedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip]; + //$peer_cmd .= '|grep -v "No Such Instance"'; WHAT TO DO WITH THIS??,USE TO SEE -Ln?? + $peer_data=snmp_get_multi($device,$oids,'-OUQs -Ln','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos"); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + unset($peer_data); + d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); @@ -235,23 +261,37 @@ if ($config['enable_bgp']) { } else { // FIXME - move to function - $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - - d_echo("$cbgp_cmd\n"); - - $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); - $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); + + + $oids = " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + + d_echo("$oids\n"); + + $cbgp_data= snmp_get_multi($device,$oids,'-OUQs ','CISCO-BGP4-MIB'); + $cbgp_data= array_pop($cbgp_data); + d_echo("$cbgp_data\n"); + + }//end if - list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + + $cbgpPeerAcceptedPrefixes= !empty($cbgp_data['cbgpPeerAcceptedPrefixes'])?$cbgp_data['cbgpPeerAcceptedPrefixes']:''; + $cbgpPeerDeniedPrefixes= !empty($cbgp_data['cbgpPeerDeniedPrefixes'])?$cbgp_data['cbgpPeerDeniedPrefixes']:''; + $cbgpPeerPrefixAdminLimit= !empty($cbgp_data['cbgpPeerPrefixAdminLimit'])?$cbgp_data['cbgpPeerPrefixAdminLimit']:''; + $cbgpPeerPrefixThreshold= !empty($cbgp_data['cbgpPeerPrefixThreshold'])?$cbgp_data['cbgpPeerPrefixThreshold']:''; + $cbgpPeerPrefixClearThreshold= !empty($cbgp_data['cbgpPeerPrefixClearThreshold'])?$cbgp_data['cbgpPeerPrefixClearThreshold']:''; + $cbgpPeerAdvertisedPrefixes= !empty($cbgp_data['cbgpPeerAdvertisedPrefixes'])?$cbgp_data['cbgpPeerAdvertisedPrefixes']:''; + $cbgpPeerSuppressedPrefixes= !empty($cbgp_data['cbgpPeerSuppressedPrefixes'])?$cbgp_data['cbgpPeerSuppressedPrefixes']:''; + $cbgpPeerWithdrawnPrefixes= !empty($cbgp_data['cbgpPeerWithdrawnPrefixes'])?$cbgp_data['cbgpPeerWithdrawnPrefixes']:''; + + unset($cbgp_data); }//end if if ($device['os'] == 'junos') { @@ -331,5 +371,6 @@ if ($config['enable_bgp']) { } //end foreach } //end if echo "\n"; + unset($device['context_name']); } //end foreach } //end if diff --git a/includes/polling/ospf.inc.php b/includes/polling/ospf.inc.php index 8fec222a2..602255258 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_port_count = 0; $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ $ospf_oids_db = array( 'ospfDemandExtensions', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; -} - -// Pull data from device -$ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); -foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_instances_db[$ospf_instance_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id), 'ospf_instances'); - echo '+'; - $ospf_instances_db[$entry['ospf_instance_id']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_instances_poll); - echo 'Database: '; - print_r($ospf_instances_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_instances_db)) { - foreach ($ospf_instances_db as $ospf_instance_db) { - $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_db['ospf_instance_id']]; - foreach ($ospf_oids_db as $oid) { - // Loop the OIDs - if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid]) { - // If data has changed, build a query - $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_instance_update) { - dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - echo 'U'; - unset($ospf_instance_update); - } - else { - echo '.'; - } - - unset($ospf_instance_poll); - unset($ospf_instance_db); - $ospf_instance_count++; - }//end foreach -}//end if - -unset($ospf_instances_poll); -unset($ospf_instances_db); - -echo ' Areas: '; - $ospf_area_oids = array( 'ospfAuthType', 'ospfImportAsExtern', @@ -95,72 +38,6 @@ $ospf_area_oids = array( 'ospfAreaStatus', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_areas_db[$entry['ospfAreaId']] = $entry; -} - -// Pull data from device -$ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_areas_db[$ospf_area_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id), 'ospf_areas'); - echo '+'; - $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - $ospf_areas_db[$entry['ospf_area_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_areas_poll); - echo 'Database: '; - print_r($ospf_areas_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_areas_db)) { - foreach ($ospf_areas_db as $ospf_area_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_area_poll = $ospf_areas_poll[$ospf_area_db['ospfAreaId']]; - foreach ($ospf_area_oids as $oid) { - // Loop the OIDs - if ($ospf_area_db[$oid] != $ospf_area_poll[$oid]) { - // If data has changed, build a query - $ospf_area_update[$oid] = $ospf_area_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME - } - } - - if ($ospf_area_update) { - dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - echo 'U'; - unset($ospf_area_update); - } - else { - echo '.'; - } - - unset($ospf_area_poll); - unset($ospf_area_db); - $ospf_area_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'])); - }//end if - }//end foreach -}//end if - -unset($ospf_areas_db); -unset($ospf_areas_poll); - -// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); -// print_r($ospf_ports); -echo ' Ports: '; - $ospf_port_oids = array( 'ospfIfIpAddress', 'port_id', @@ -171,7 +48,7 @@ $ospf_port_oids = array( 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,87 +62,6 @@ $ospf_port_oids = array( 'ospfIfAuthType', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_ports_db[$entry['ospf_port_id']] = $entry; -} - -// Pull data from device -$ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_ports_db[$ospf_port_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id), 'ospf_ports'); - echo '+'; - $ospf_ports_db[$entry['ospf_port_id']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_ports_poll); - echo 'Database: '; - print_r($ospf_ports_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_ports_db)) { - foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_port_poll = $ospf_ports_poll[$ospf_port_db['ospf_port_id']]; - - if ($ospf_port_poll['ospfAddressLessIf']) { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); - } - else { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'])); - } - - foreach ($ospf_port_oids as $oid) { - // Loop the OIDs - if ($ospf_port_db[$oid] != $ospf_port_poll[$oid]) { - // If data has changed, build a query - $ospf_port_update[$oid] = $ospf_port_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_port_update) { - dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - echo 'U'; - unset($ospf_port_update); - } - else { - echo '.'; - } - - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'])); - // "DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); - echo '-'; - }//end if - }//end foreach -}//end if - -// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 -// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 -// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 -// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrState.172.22.203.98.0 full -// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 -// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 -// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active -// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic -// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false -echo ' Neighbours: '; - $ospf_nbr_oids_db = array( 'ospfNbrIpAddr', 'ospfNbrAddressLessIndex', @@ -279,83 +75,313 @@ $ospf_nbr_oids_db = array( 'ospfNbmaNbrPermanence', 'ospfNbrHelloSuppressed', ); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])) as $nbr_entry) { - $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry; + + +if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) { + $vrfs_lite_cisco = $device['vrf_lite_cisco']; +} else { + $vrfs_lite_cisco = array(array('context_name' => null)); } -// Pull data from device -$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_nbrs_db[$ospf_nbr_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id), 'ospf_nbrs'); - echo '+'; - $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - $ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry; + $device['context_name'] = $vrf_lite['context_name']; + + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; } -} -if ($debug) { - echo "\nPolled: "; - print_r($ospf_nbrs_poll); - echo 'Database: '; - print_r($ospf_nbrs_db); - echo "\n"; -} + // Pull data from device + $ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); + foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (empty($ospf_instances_db[$ospf_instance_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id, 'context_name' => $device['context_name']), 'ospf_instances'); + echo '+'; + $ospf_instances_db[$entry['ospf_instance_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; + } + } -// Loop array of entries and update -if (is_array($ospf_nbrs_db)) { - foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { - if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { - $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + if ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'])); + // Loop array of entries and update + if (is_array($ospf_instances_db)) { + foreach ($ospf_instances_db as $ospf_instance_id => $ospf_instance_db) { + if (is_array($ospf_instances_poll[$ospf_instance_id])) { + $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_id]; + foreach ($ospf_oids_db as $oid) { + // Loop the OIDs + if ($ospf_instance_db[$device['context_name']][$oid] != $ospf_instance_poll[$oid]) { + // If data has changed, build a query + $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } - if ($ospf_nbr_db['port_id'] != $ospf_nbr_poll['port_id']) { - if ($ospf_nbr_poll['port_id']) { - $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + if ($ospf_instance_update) { + dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + echo 'U'; + unset($ospf_instance_update); } else { - $ospf_nbr_update = array('port_id' => array('NULL')); + echo '.'; } + + unset($ospf_instance_poll); + unset($ospf_instance_db); + $ospf_instance_count++; + } else { + dbDelete('ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=? ', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); } + }//end foreach + }//end if + unset($ospf_instances_poll); + unset($ospf_instances_db); - foreach ($ospf_nbr_oids as $oid) { - // Loop the OIDs - d_echo($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n"); - if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid]) { - // If data has changed, build a query - $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; - // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + + echo ' Areas: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `context_name`=?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_areas_db[$entry['ospfAreaId']][$entry['context_name']] = $entry; + } + + // Pull data from device + $ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_areas_db[$ospf_area_id][$entry['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id, 'context_name' => $device['context_name']), 'ospf_areas'); + echo '+'; + $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + $ospf_areas_db[$ospf_area_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_areas_poll); + echo 'Database: '; + print_r($ospf_areas_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_areas_db)) { + foreach ($ospf_areas_db as $$ospf_area_id => $ospf_area_db) { + if (is_array($ospf_areas_poll[$ospf_area_id])) { + $ospf_area_poll = $ospf_areas_poll[$ospf_area_id]; + foreach ($ospf_area_oids as $oid) { + // Loop the OIDs + if ($ospf_area_db[$entry['context_name']][$oid] != $ospf_area_poll[$oid]) { + // If data has changed, build a query + $ospf_area_update[$oid] = $ospf_area_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME + } } - } - if ($ospf_nbr_update) { - dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - echo 'U'; - unset($ospf_nbr_update); + if ($ospf_area_update) { + dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + echo 'U'; + unset($ospf_area_update); + } + else { + echo '.'; + } + + unset($ospf_area_poll); + unset($ospf_area_db); + $ospf_area_count++; } else { - echo '.'; - } + dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); + }//end if + }//end foreach + }//end if - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; + unset($ospf_areas_db); + unset($ospf_areas_poll); + + +// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); +// print_r($ospf_ports); + echo ' Ports: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = $entry; + } + + // Pull data from device + $ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_ports_db[$ospf_port_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id, 'context_name' => $device['context_name']), 'ospf_ports'); + echo '+'; + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); } - else { - dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'])); - echo '-'; - }//end if - }//end foreach -}//end if + } + if ($debug) { + echo "\nPolled: "; + print_r($ospf_ports_poll); + echo 'Database: '; + print_r($ospf_ports_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_ports_db)) { + foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { + if (is_array($ospf_ports_poll[$ospf_port_id])) { + $ospf_port_poll = $ospf_ports_poll[$ospf_port_id]; + + if ($ospf_port_poll['ospfAddressLessIf']) { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); + } + else { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'], $device['context_name'])); + } + + foreach ($ospf_port_oids as $oid) { + // Loop the OIDs + if ($ospf_port_db[$device['context_name']][$oid] != $ospf_port_poll[$oid]) { + // If data has changed, build a query + $ospf_port_update[$oid] = $ospf_port_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } + + if ($ospf_port_update) { + dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); + echo 'U'; + unset($ospf_port_update); + } + else { + echo '.'; + } + + unset($ospf_port_poll); + unset($ospf_port_db); + $ospf_port_count++; + } + else { + dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'], $device['context_name'])); + // ("DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); + echo '-'; + }//end if + }//end foreach + }//end if + + +// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 +// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 +// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 +// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrState.172.22.203.98.0 full +// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 +// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 +// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active +// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic +// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false + echo ' Neighbours: '; + + $ospf_nbr_oids_rrd = array(); + $ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $nbr_entry) { + $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']][$device['context_name']] = $nbr_entry; + } + + // Pull data from device + $ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_nbrs_db[$ospf_nbr_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id, 'context_name' => $device['context_name']), 'ospf_nbrs'); + echo '+'; + $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id,$device['context_name'])); + $ospf_nbrs_db[$ospf_nbr_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_nbrs_poll); + echo 'Database: '; + print_r($ospf_nbrs_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_nbrs_db)) { + foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { + if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { + $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + + $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'], $device['context_name'])); + + if ($ospf_nbr_db[$device['context_name']]['port_id'] != $ospf_nbr_poll['port_id']) { + if (!empty($ospf_nbr_poll['port_id'])) { + $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + } + else { + $ospf_nbr_update = array('port_id' => array('NULL')); + } + } + + foreach ($ospf_nbr_oids as $oid) { + // Loop the OIDs + d_echo($ospf_nbr_db[$device['context_name']][$oid].'|'.$ospf_nbr_poll[$oid]."\n"); + + if ($ospf_nbr_db[$device['context_name']][$oid] != $ospf_nbr_poll[$oid]) { + // If data has changed, build a query + $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; + // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + } + } + + if ($ospf_nbr_update) { + dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id, $device['context_name'])); + echo 'U'; + unset($ospf_nbr_update); + } + else { + echo '.'; + } + + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; + } + else { + dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'], $device['context_name'])); + echo '-'; + }//end if + }//end foreach + }//end if + unset($ospf_nbrs_db); + unset($ospf_nbrs_poll); +} +unset($device['context_name']); +unset($vrfs_lite_cisco); // Create device-wide statistics RRD $filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('ospf-statistics.rrd'); diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index e2d4bac01..c27b2989f 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -750,8 +750,14 @@ function snmp_gen_auth(&$device) { $cmd = ''; if ($device['snmpver'] === 'v3') { + $cmd = " -v3 -n '' -l '".$device['authlevel']."'"; - + + //add context if exist context + if(key_exists('context_name', $device)){ + $cmd = " -v3 -n '".$device['context_name']."' -l '".$device['authlevel']."'"; + } + if ($device['authlevel'] === 'noAuthNoPriv') { // We have to provide a username anyway (see Net-SNMP doc) // FIXME: There are two other places this is set - why are they ignored here? From 286dcdcafe92b1542ccb4c0fbd972aa72575c7fa Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 011/104] Adding sql-schema --- sql-schema/094.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-schema/094.sql b/sql-schema/094.sql index 5dfced746..da527fcd0 100644 --- a/sql-schema/094.sql +++ b/sql-schema/094.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; From 1a21c5139a1e5e41c307531d3db49f1e551a7415 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Mon, 25 Jan 2016 11:17:06 +0100 Subject: [PATCH 012/104] Syntax update --- includes/defaults.inc.php | 4 +-- includes/discovery/arp-table.inc.php | 5 +-- includes/discovery/bgp-peers.inc.php | 3 +- includes/discovery/cisco-vrf-lite.inc.php | 41 +++++------------------ includes/discovery/ipv4-addresses.inc.php | 4 +-- includes/discovery/ipv6-addresses.inc.php | 2 +- 6 files changed, 18 insertions(+), 41 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index a418f7477..cadc5ae17 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -736,8 +736,8 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; -$config['discovery_modules']['cisco-vrf-lite'] = 1; -// $config['discovery_modules']['cisco-cef'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; +//$config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; $config['discovery_modules']['libvirt-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index c60d4ca95..a04b9db8a 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -7,9 +7,10 @@ echo 'ARP Table : '; if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } -else{ +else { $vrfs_lite_cisco = array(array('context_name'=>null)); } + foreach ($vrfs_lite_cisco as $vrf) { $device['context_name']=$vrf['context_name']; @@ -60,7 +61,7 @@ foreach ($vrfs_lite_cisco as $vrf) { dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name'])); echo '.'; } - else if (isset($interface['port_id'])) { + elseif (isset($interface['port_id'])) { echo '+'; // echo("Add MAC $mac\n"); $insert_data = array( diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index dd341715d..0d82f83ed 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -7,7 +7,7 @@ if ($config['enable_bgp']) { if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } - else{ + else { $vrfs_lite_cisco = array(array('context_name'=>null)); } @@ -237,7 +237,6 @@ if ($config['enable_bgp']) { echo '-'; } } - unset($peerlist); echo "\n"; diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php index ae2aff0e4..b079e618c 100644 --- a/includes/discovery/cisco-vrf-lite.inc.php +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -24,10 +24,8 @@ if ($config['enable_vrf_lite_cisco']) { // For the moment only will be cisco and the version 3 if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') { - echo ("VRF lite cisco : \n"); $mib = "SNMP-COMMUNITY-MIB"; - $mib = "CISCO-CONTEXT-MAPPING-MIB"; //-Osq because if i put the n the oid from the first command is not the same of this one $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); @@ -35,10 +33,8 @@ if ($config['enable_vrf_lite_cisco']) { $listVrf = str_replace('"', "", $listVrf); $listVrf = trim($listVrf); - if ($debug) { - echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); - echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); - } + d_echo("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + d_echo("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); $tableVrf; foreach (explode("\n", $listVrf) as $lineVrf) { @@ -48,20 +44,16 @@ if ($config['enable_vrf_lite_cisco']) { $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1]; } } - unset($listVrf); - + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); $listIntance = str_replace('"', "", $listIntance); $listIntance = trim($listIntance); - - if ($debug) { - echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); - echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); - } - - + + d_echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + d_echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + foreach (explode("\n", $listIntance) as $lineIntance) { $tmpIntance = explode(" ", $lineIntance, 2); //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance @@ -70,14 +62,9 @@ if ($config['enable_vrf_lite_cisco']) { } } unset($listIntance); - foreach ($tableVrf as $context => $vrf) { - - - if ($debug) { - echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n"); } @@ -86,9 +73,7 @@ if ($config['enable_vrf_lite_cisco']) { $context )); if (!empty($tmpVrf)) { - $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id']; - $vrfUpdate=array(); foreach ($vrfUpdate as $key => $value) { @@ -102,25 +87,21 @@ if ($config['enable_vrf_lite_cisco']) { )); } } else { - $id = dbInsert(array( 'device_id' => $device ['device_id'], 'context_name' => $context, 'intance_name' => $vrf['intance_name'], 'vrf_name' => $vrf['vrf_name'] ), 'vrf_lite_cisco'); - $ids[$id] = $id; } } - unset($tableVrf); } //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( $device ['device_id'])); - $device['vrf_lite_cisco'] = $tmpVrfC; //Delete all vrf that chaged @@ -129,14 +110,10 @@ if ($config['enable_vrf_lite_cisco']) { } if (!empty($ids)) { foreach ($ids as $id) { - - dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array( - $id)); + dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array($id)); } } - - unset($ids); unset($tmpVrfC); } // enable_vrf_lite_cisco -?> + diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 26fc9ba28..f930b8fd3 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,10 +1,10 @@ null)); } foreach ($vrfs_lite_cisco as $vrf) { diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index f7762ee98..fb9864020 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -4,7 +4,7 @@ echo 'IPv6 Addresses : '; if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } -else{ +else { $vrfs_lite_cisco = array(array('context_name'=>null)); } foreach ($vrfs_lite_cisco as $vrf) { From c801e4baf59c45b262906daf7c3d6cf3e47c0f10 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 013/104] Adding sql-schema --- sql-schema/094.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 sql-schema/094.sql diff --git a/sql-schema/094.sql b/sql-schema/094.sql new file mode 100644 index 000000000..6caaecf4e --- /dev/null +++ b/sql-schema/094.sql @@ -0,0 +1 @@ +DELETE FROM `device_mibs` WHERE `module` = 'CISCO-AAA-SESSION-MIB' AND `mib` = 'ciscoAAASessionMIB'; From 3c3cf96247a3bf75c98e6dfcb1e6d61ec656584a Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:05:14 +0100 Subject: [PATCH 014/104] Adding mibs --- mibs/CISCO-BRIDGE-DOMAIN-MIB | 450 +++++++++++++++++ mibs/CISCO-CONTEXT-MAPPING-MIB | 853 +++++++++++++++++++++++++++++++++ 2 files changed, 1303 insertions(+) create mode 100644 mibs/CISCO-BRIDGE-DOMAIN-MIB create mode 100644 mibs/CISCO-CONTEXT-MAPPING-MIB diff --git a/mibs/CISCO-BRIDGE-DOMAIN-MIB b/mibs/CISCO-BRIDGE-DOMAIN-MIB new file mode 100644 index 000000000..68e9ddb9c --- /dev/null +++ b/mibs/CISCO-BRIDGE-DOMAIN-MIB @@ -0,0 +1,450 @@ +-- ***************************************************************** +-- CISCO-BRIDGE-DOMAIN-MIB.my : Cisco Bridge Domain MIB +-- +-- Oct 2007, Madhavi Dokku +-- +-- Copyright (c) 2007 by Cisco Systems, Inc. +-- +-- All rights reserved. +-- ***************************************************************** + +CISCO-BRIDGE-DOMAIN-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE, + Unsigned32 + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + TEXTUAL-CONVENTION, + TruthValue, + RowStatus, + StorageType + FROM SNMPv2-TC + ifIndex + FROM IF-MIB + ciscoMgmt + FROM CISCO-SMI; + + +ciscoBridgeDomainMIB MODULE-IDENTITY + LAST-UPDATED "200712290000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + Tel: +1 800 553-NETS + + E-mail: cs-ethermibs@cisco.com" + DESCRIPTION + "A bridge domain is one of the means by which it is possible + to define a broadcast domain on a bridging device. It is an + alternative to 802.1D bridge-groups and to 802.1Q VLAN + bridging. + + Bridge domain is the service specification, and specifies the + broadcast domain number on which this frame of this particular + service instance must be made available on. The physical and + virtual interfaces that can comprise a bridge domain are + heterogeneous in nature comprising Ethernet service instances, + WAN Virtual Circuit for ATM or Frame Relay and VFIs. However, + the frame encapsulations for all interface types are + essentially Ethernet. + + Without bridge-domains, VLANs would have to be globally unique + per device and one would only be restricted to the theoretical + maximum of 4095 VLANs for single tagged traffic. However + with the introduction of bridge-domains, one can + associate a service instance with a bridge-domain and all + service instances in the same bridge-domain form a + broadcast domain. Bridge-domain ID determines the + broadcast domain and the VLAN id is merely used to match + and map traffic. With bridge domain feature configured + VLAN IDs would be unique per interface only and not globally. + Thus bridge domains make VLAN ids have only local + significance per port + + + Differences between Bridge Domains and 802.1AD Bridges: + ======================================================= + 1. Scope of the VLAN technology which uses 802.1 AD is global to + the box. + But in case of Bridge domain, the scope of vlan is local to + interface + + 2. Switchport 802.1AD restricts the number of broadcast domain + on a box to 4095. + However, with Bridge domains, we can have up to 16k broadcast + domain. + + 3. Under a single Bridge domain service instance, there can be + flexible service mapping criterion.(i.e match based on + outer vlan, outer cos, inner vlan, inner cos and payload + ethertype). + Whereas in case of switch port 802.1AD/dot1q this is not + supported. + + Similarities between Bridge Domains and 802.1AD Bridges: + ======================================================= + + 1. Both use the same MAC address lookup for forwarding. + + 2. Both work with protocols like STP, DTP etc. + + 3. Both of them classify 'ports' in a system into Bridges/Bridge + Domains. + + Ethernet service instance is the instantiation of an Ethernet + virtual circuit on a given port on a given router. In other + words, an Ethernet service instance is an object that holds + information about the layer 2 service that is being offered + on a given port of a given router as part of a given Ethernet + virtual circuit. Bridge domains feature is currently supported + on ethernet service instances only and can be later extented + to other interfaces like ATM and Frame Relay. + + This MIB helps the network management personnel to find out the + details of various broadcast domains configured in the network. + + Definition of terms and acronyms: + + ATM: Asynchronous Transfer mode + + BD: Bridge Domain + + C-mac: Customer MAC + + EVC: Ethernet Virtual Circuit + + FR: Frame Relay + + SH: Split Horizon + + VFI: Virtual Forwarding Instance + + VLAN: Virtual Local Area Network + + WAN: Wide Area Network" + REVISION "200712290000Z" + DESCRIPTION + "Modified the MIB description with details on similarities and + differences between Bridge Domains and 802.1AD Bridges." + REVISION "200712040000Z" + DESCRIPTION + "Initial version of this MIB module." + ::= { ciscoMgmt 642 } + + +ciscoBdMIBNotifications OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 0 } + +ciscoBdMIBObjects OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 1 } + +ciscoBdMIBConformance OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 2 } + +cbdSystemInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 1 } + +cbdMemberInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 2 } + + +-- Textual Conventions + +CbdType ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "Defines the different types of bridge domain members: + + 'other': none of the following + + 'ether': Ethernet Service Instance + + 'atmVc': ATM Virtual connection + + 'frVc': Frame Relay Virtual Connection" + SYNTAX INTEGER { + other(1), + ether(2), + atmVc(3), + frVc(4) + } + +cbdMembersConfigured OBJECT-TYPE + SYNTAX Unsigned32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the number of bridge domain + members configured on this bridge domain." + ::= { cbdSystemInfo 1 } +-- Member Info Table + +cbdMemberInfoTable OBJECT-TYPE + SYNTAX SEQUENCE OF CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table provides the bridge domain member attributes + of the members currently configured for each bridge + domain." + ::= { cbdMemberInfo 1 } + +cbdMemberInfoEntry OBJECT-TYPE + SYNTAX CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A conceptual row in cbdMemberInfoTable. This is indexed + by ifIndex and cbdSIIndex. Each row is created when a bridge + domain member is configured under a service instance." + INDEX { + ifIndex, + cbdSIIndex + } + ::= { cbdMemberInfoTable 1 } + +CbdMemberInfoEntry ::= SEQUENCE { + cbdSIIndex Unsigned32, + cbdMemberType CbdType, + cbdMemberOperState INTEGER , + cbdMemberAdminState INTEGER , + cbdMemberSplitHorizon TruthValue, + cbdMemberSplitHorizonNum Unsigned32, + cbdMemberStorageType StorageType, + cbdMemberStatus RowStatus, + cbdMembercMac TruthValue +} + +cbdSIIndex OBJECT-TYPE + SYNTAX Unsigned32 (1..4294967295 ) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This object indicates an arbitary index that uniquely + identifies the Service Instance to which this bridge domain + member belongs to." + ::= { cbdMemberInfoEntry 1 } + +cbdMemberType OBJECT-TYPE + SYNTAX CbdType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the type of the bridge domain member + like ATM VC, Frame Relay VC, or Ethernet service." + DEFVAL { other } + ::= { cbdMemberInfoEntry 2 } + +cbdMemberOperState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the operational state of the bridge + domain Member. Operational state of the Bridge domain member + is same as the operational state of the underlying service + instance. Bridge domain members are configured under service + instances and multiple service instances can be attached to a + single physical interface defining various kinds of services. + Bridge domain members have many to one relationship with + interface + Indexes. When ifOperStatus of the underlying interface is down, + the state of cbdMemberOperState should be down. When + ifOperStatus + of the underlying interface is up, cbdMemberOperState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is an unknown state. + + 'up': the bridge domain member is fully operational and + able to bridge the traffic. This means that both the + physical interface and the underlying service instance + are administratively up. + + 'down': the Bridge Domain member is down and not + capable of bridging. This state means either the underlying + service instance is down or the interface is down." + ::= { cbdMemberInfoEntry 3 } + +cbdMemberAdminState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the administrative state of the + bridge domain Member. Admin state of the Bridge domain member + is same as the admin state of the underlying service instance. + Bridge domain members are configured under service instances + and multiple service instances can be attached to a single + physical interface defining various kinds of services. Bridge + Domain members have many to one relationship with interface + Indexes. When ifAdminStatus of the unerlying interface is down + the state of cbdMemberAdminState should be down. When ifOperStatus + of the underlying interface is up cbdMemberAdminState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is in unknown + administrative state. + + 'up': the Bridge Domain member is administratively up. This + means that both the physical interface and the underlying service + instance are administratively up. + + 'admindown': the Bridge Domain member is down as it is + administratively configured to be down and is not + capable of bridging. This means that either the underlying + service instance is configured as administratively down or + the physical interface is configured as administratively + down." + ::= { cbdMemberInfoEntry 4 } + +cbdMemberSplitHorizon OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates whether split horizon is + configured on this bridge domain member." + ::= { cbdMemberInfoEntry 5 } + +cbdMemberSplitHorizonNum OBJECT-TYPE + SYNTAX Unsigned32 (0..65535 ) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the split horizon number if + configured on the bridge domain member. Split horizon + is used to avoid sending traffic between interfaces. + Frames are not forwarded to the members belonging to the + same split horizon group." + DEFVAL { 0 } + ::= { cbdMemberInfoEntry 6 } + +cbdMemberStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object specifies the storage type of this conceptual + row. This object can only have a value 'nonVolatile'. Other + values are not applicable for this conceptual row and are + not supported." + DEFVAL { nonVolatile } + ::= { cbdMemberInfoEntry 7 } + +cbdMemberStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object enables the SNMP agent to create, modify, + and delete rows in the cbdMemberInfoTable." + DEFVAL { active } + ::= { cbdMemberInfoEntry 8 } + +cbdMembercMac OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates if cmac is configured on this + bridge domain member. Cmac denotes if this bridge domain is + configured as a customer domain." + ::= { cbdMemberInfoEntry 9 } + + +-- Notifications + +ciscoBdNotificationPrefix OBJECT IDENTIFIER + ::= { ciscoBdMIBNotifications 0 } + +-- Conformance + +ciscoBdMIBCompliances OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 1 } + +ciscoBdMIBGroups OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 2 } + + +ciscoBdMIBComplianceRev1 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-BRIDGE-DOMAIN-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cbdSystemInfoGroup, + cbdMemberInfoGroup + } + ::= { ciscoBdMIBCompliances 1 } + +-- Units of Conformance + +cbdSystemInfoGroup OBJECT-GROUP + OBJECTS { cbdMembersConfigured } + STATUS current + DESCRIPTION + "This group contain information about bridge domain." + ::= { ciscoBdMIBGroups 1 } + +cbdMemberInfoGroup OBJECT-GROUP + OBJECTS { + cbdMemberType, + cbdMemberOperState, + cbdMemberAdminState, + cbdMemberSplitHorizon, + cbdMemberSplitHorizonNum, + cbdMemberStorageType, + cbdMemberStatus, + cbdMembercMac + } + STATUS current + DESCRIPTION + "This group contain information related to bridge domain + members." + ::= { ciscoBdMIBGroups 2 } + +END + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mibs/CISCO-CONTEXT-MAPPING-MIB b/mibs/CISCO-CONTEXT-MAPPING-MIB new file mode 100644 index 000000000..94451564d --- /dev/null +++ b/mibs/CISCO-CONTEXT-MAPPING-MIB @@ -0,0 +1,853 @@ +-- ***************************************************************** +-- CISCO-CONTEXT-MAPPING-MIB.my: Cisco Context Mapping MIB +-- +-- January 2005, Chinna Pellacuru. +-- +-- May 2008, Sheethal Gunjal. +-- +-- Copyright (c) 2004-2005, 2008 by cisco Systems Inc. +-- All rights reserved. +-- +-- **************************************************************** + +CISCO-CONTEXT-MAPPING-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + SnmpAdminString + FROM SNMP-FRAMEWORK-MIB + RowStatus, + StorageType + FROM SNMPv2-TC + CiscoBridgeDomain + FROM CISCO-TC + ciscoMgmt + FROM CISCO-SMI; + + +ciscoContextMappingMIB MODULE-IDENTITY + LAST-UPDATED "200811220000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + + Tel: +1 800 553-NETS + + E-mail: cs-snmp@cisco.com" + DESCRIPTION + "A single SNMP agent sometimes needs to support multiple + instances of the same MIB module, and does so through the + use of multiple SNMP contexts. This typically occurs because + the technology has evolved to have extra dimension(s), i.e., + one or more extra data and/or identifier values which are + different in the different contexts, but were not defined in + INDEX clause(s) of the original MIB module. In such cases, + network management applications need to know the specific + data/identifier values in each context, and this MIB module + provides mapping tables which contain that information. + + Within a network there can be multiple Virtual Private + Networks (VPNs) configured using Virtual Routing and + Forwarding Instances (VRFs). Within a VPN there can be + multiple topologies when Multi-topology Routing (MTR) is + used. Also, Interior Gateway Protocols (IGPs) can have + multiple protocol instances running on the device. + A network can have multiple broadcast domains configured + using Bridge Domain Identifiers. + + With MTR routing, VRFs, and Bridge domains, a router now + needs to support multiple instances of several existing + MIB modules, and this can be achieved if the router's SNMP + agent provides access to each instance of the same MIB module + via a different SNMP context (see Section 3.1.1 of RFC 3411). + For MTR routing, VRFs, and Bridge domains, a different SNMP + context is needed depending on one or more of the following: + the VRF, the topology-identifier, the routing protocol instance, + and the bridge domain identifier. + In other words, the router's management information can be + accessed through multiple SNMP contexts where each such + context represents a specific VRF, a specific + topology-identifier, a specific routing protocol instance + and/or a bridge domain identifier. This MIB module provides + a mapping of each such SNMP context to the corresponding VRF, + the corresponding topology, the corresponding routing protocol + instance, and the corresponding bridge domain identifier. + Some SNMP contexts are independent of VRFs, independent of + a topology, independent of a routing protocol instance, or + independent of a bridge domain and in such a case, the mapping + is to the zero length string. + + With the Cisco package licensing strategy, the features + available in the image are grouped into multiple packages + and each packages can be managed to operate at different + feature levels based on the available license. This MIB + module provides option to associate an SNMP context to a + feature package group. This will allow manageability of + license MIB objects specific to a feature package group. + + As technology evolves more we may need additional + identifiers to identify the context. Then we would need + to add those additional identifiers into the mapping." + REVISION "200811220000Z" + DESCRIPTION + "Added New Table cContextMappingLicenseGroupTable + to provide SNMP Context support for license package groups. + + Added cContextMappingLicenseGroupDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev2 in MODULE-COMPLIANCE + + Updated the MIB description to indicate the use of + the above additions" + REVISION "200805300000Z" + DESCRIPTION + "Add cContextMappingBridgeInstanceTable. + + Added cContextMappingBridgeInstanceDataGroup. + Deprecated cContextMappingMIBComplianceRev1 and added + cContextMappingMIBComplianceRev2 compliance statement." + REVISION "200802010000Z" + DESCRIPTION + "Added New Table cContextMappingBridgeDomainTable + to provide SNMP context support to the Bridge Domain. + + Added cContextMappingBridgeDomainDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev1 in MODULE-COMPLIANCE" + REVISION "200503170000Z" + DESCRIPTION + "Initial version of the MIB module." + ::= { ciscoMgmt 468 } + + +cContextMappingMIBObjects OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 1 } + +cContextMappingMIBConformance OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 2 } + + +cContextMappingTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which VRF, topology, and routing protocol instance. + + This table is indexed by SNMP VACM context. + + Configuring a row in this table for an SNMP context + does not require that the context be already defined, + i.e., a row can be created in this table for a context + before the corresponding row is created in RFC 3415's + vacmContextTable. + + To create a row in this table, a manager must set + cContextMappingRowStatus to either 'createAndGo' or + 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingRowStatus to 'destroy'." + ::= { cContextMappingMIBObjects 1 } + +cContextMappingEntry OBJECT-TYPE + SYNTAX CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the corresponding VRF, + the corresponding topology, and the corresponding routing + protocol instance." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingTable 1 } + +CContextMappingEntry ::= SEQUENCE { + cContextMappingVacmContextName SnmpAdminString, + cContextMappingVrfName SnmpAdminString, + cContextMappingTopologyName SnmpAdminString, + cContextMappingProtoInstName SnmpAdminString, + cContextMappingStorageType StorageType, + cContextMappingRowStatus RowStatus +} + +cContextMappingVacmContextName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The vacmContextName given to the SNMP context. + + This is a human readable name identifying a particular + SNMP VACM context at a particular SNMP entity. + The empty contextName (zero length) represents the + default context." + ::= { cContextMappingEntry 1 } + +cContextMappingVrfName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the VRF to which the SNMP context + is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this VRF. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any VRF." + DEFVAL { ''H } + ::= { cContextMappingEntry 2 } + +cContextMappingTopologyName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the topology to which the SNMP + context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this topology. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any topology." + DEFVAL { ''H } + ::= { cContextMappingEntry 3 } + +cContextMappingProtoInstName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the protocol instance to which the + SNMP context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this protocol instance. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any protocol instance." + DEFVAL { ''H } + ::= { cContextMappingEntry 4 } + +cContextMappingStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingEntry 5 } + +cContextMappingRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingEntry 6 } + + + +cContextMappingBridgeDomainTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which bridge domain. + + A Bridge Domain is one of the means by which it is possible + to define an Ethernet broadcast domain on a bridging device. + A network can have multiple broadcast domains configured. + This table helps the network management personnel to find + out the details of various broadcast domains configured + in the network. + + An entry need to exist in cContextMappingTable, to create + an entry in this table." + ::= { cContextMappingMIBObjects 2 } + +cContextMappingBridgeDomainEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge domain. + + To create a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeDomainTable 1 } + +CContextMappingBridgeDomainEntry ::= SEQUENCE { + cContextMappingBridgeDomainIdentifier CiscoBridgeDomain, + cContextMappingBridgeDomainStorageType StorageType, + cContextMappingBridgeDomainRowStatus RowStatus +} + +cContextMappingBridgeDomainIdentifier OBJECT-TYPE + SYNTAX CiscoBridgeDomain + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the bridge domain to which the SNMP context is + mapped to." + REFERENCE "CISCO-BRIDGE-DOMAIN-MIB" + ::= { cContextMappingBridgeDomainEntry 1 } + +cContextMappingBridgeDomainStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeDomainEntry 2 } + +cContextMappingBridgeDomainRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeDomainEntry 3 } + + + +cContextMappingBridgeInstanceTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on mapping between + cContextMappingVacmContextName and bridge instance. + + Bridge instance is an instance of a physical or logical + bridge which has unique bridge-id. + + If an entry is deleted from cContextMappingTable, the + corresponding entry in this table will also get deleted. + + If an entry needs to be created in this table, the + corresponding entry must exist in cContextMappingTable." + REFERENCE "BRIDGE-MIB" + ::= { cContextMappingMIBObjects 3 } + +cContextMappingBridgeInstanceEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge instance. + + To create a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeInstanceTable 1 } + +CContextMappingBridgeInstanceEntry ::= SEQUENCE { + cContextMappingBridgeInstName SnmpAdminString, + cContextMappingBridgeInstStorageType StorageType, + cContextMappingBridgeInstRowStatus RowStatus +} + +cContextMappingBridgeInstName OBJECT-TYPE + SYNTAX SnmpAdminString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The object identifies the name given to bridge + instance to which the SNMP context is mapped to. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this bridge instance. + + When the value of this object is a zero length + string, it indicates that the SNMP context is + independent of any bridge instances." + ::= { cContextMappingBridgeInstanceEntry 1 } + +cContextMappingBridgeInstStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeInstanceEntry 2 } + +cContextMappingBridgeInstRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeInstanceEntry 3 } + + + +cContextMappingLicenseGroupTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which License Group. + Group level licensing is used where each + Technology Package is enabled via a License." + ::= { cContextMappingMIBObjects 4 } + +cContextMappingLicenseGroupEntry OBJECT-TYPE + SYNTAX CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + CContextMappingVacmContextName to the + corresponding License Group." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingLicenseGroupTable 1 } + +CContextMappingLicenseGroupEntry ::= SEQUENCE { + cContextMappingLicenseGroupName SnmpAdminString, + cContextMappingLicenseGroupStorageType StorageType, + cContextMappingLicenseGroupRowStatus RowStatus +} + +cContextMappingLicenseGroupName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the Group to which the SNMP context + is mapped. + + Feature sets from all groups will be combined to form + universal image. User can configure multiple groups as needed. + + For example: In Next generation ISRs will use + the universal image package level licensing model + for its licensing need. Each group has + the feature set needed for that specific technology. + Feature sets from different groups are combined to + form universal image and each feature set for a group + can be enabled using a valid license key. There will + be a base level ipbase package in which the router + boots with out any license key. + + The following are the different Technology Groups. + 1.crypto + 2.data + 3.ip + 4.legacy + 5.novpn-security + 6.security + 7.uc" + ::= { cContextMappingLicenseGroupEntry 1 } + +cContextMappingLicenseGroupStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingLicenseGroupEntry 2 } + +cContextMappingLicenseGroupRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingLicenseGroupEntry 3 } + + +-- Conformance + +cContextMappingMIBCompliances OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 1 } + +cContextMappingMIBGroups OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 2 } + + +-- Compliance + +cContextMappingMIBCompliance MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { cContextMappingDataGroup } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 1 } + +cContextMappingMIBComplianceRev1 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB. This compliance statement + is superceded by cContextMappingMIBComplianceRev2." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 2 } + +cContextMappingMIBComplianceRev2 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + ::= { cContextMappingMIBCompliances 3 } + +cContextMappingMIBComplianceRev3 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup, + cContextMappingLicenseGroupDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + + OBJECT cContextMappingLicenseGroupName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 4 } + +-- Units of Conformance + +cContextMappingDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingVrfName, + cContextMappingTopologyName, + cContextMappingProtoInstName, + cContextMappingStorageType, + cContextMappingRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding VRF, the corresponding topology, + and the corresponding routing protocol instance." + ::= { cContextMappingMIBGroups 1 } + +cContextMappingBridgeDomainDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeDomainIdentifier, + cContextMappingBridgeDomainStorageType, + cContextMappingBridgeDomainRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge domain." + ::= { cContextMappingMIBGroups 2 } + +cContextMappingBridgeInstanceDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeInstName, + cContextMappingBridgeInstStorageType, + cContextMappingBridgeInstRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge instance." + ::= { cContextMappingMIBGroups 3 } + +cContextMappingLicenseGroupDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingLicenseGroupName, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding LicenseGroupName." + ::= { cContextMappingMIBGroups 4 } + +END + + + + + + + + From 30eb276155d584389cf83b756550185f808b4223 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:13:53 +0100 Subject: [PATCH 015/104] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 158 ++++--- includes/discovery/bgp-peers.inc.php | 378 ++++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 114 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 125 +++-- includes/polling/ospf.inc.php | 548 +++++++++++----------- includes/snmp.inc.php | 8 +- 11 files changed, 957 insertions(+), 682 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index 9fe13efe5..0db9dad86 100644 --- a/includes/common.php +++ b/includes/common.php @@ -290,6 +290,16 @@ function device_by_id_cache($device_id, $refresh = '0') { } else { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id)); + + //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time + $vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id)); + $device['vrf_lite_cisco'] = array(); + if(!empty($vrfs_lite_cisco)){ + foreach ($vrfs_lite_cisco as $vrf){ + $device['vrf_lite_cisco'][$vrf['context_name']] = $vrf; + } + } + $cache['devices']['id'][$device_id] = $device; } return $device; diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 328ae2ce0..a418f7477 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ $config['enable_pseudowires'] = 1; // Enable Pseudowires $config['enable_vrfs'] = 1; // Enable VRFs +$config['enable_vrf_lite_cisco'] = 1; +// Enable VRF lite cisco $config['enable_printers'] = 0; // Enable Printer support $config['enable_sla'] = 0; @@ -734,6 +736,7 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; // $config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index 69b0d9b75..c60d4ca95 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ unset($mac_table); echo 'ARP Table : '; -$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); -$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); -$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); - -foreach (explode("\n", $ipNetToMedia_data) as $data) { - list($oid, $mac) = explode(' ', $data); - list($if, $first, $second, $third, $fourth) = explode('.', $oid); - $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; - if ($ip != '...') { - $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); - - list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); - $m_a = zeropad($m_a); - $m_b = zeropad($m_b); - $m_c = zeropad($m_c); - $m_d = zeropad($m_d); - $m_e = zeropad($m_e); - $m_f = zeropad($m_f); - $md_a = hexdec($m_a); - $md_b = hexdec($m_b); - $md_c = hexdec($m_c); - $md_d = hexdec($m_d); - $md_e = hexdec($m_e); - $md_f = hexdec($m_f); - $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; - - $mac_table[$if][$mac]['ip'] = $ip; - $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; - $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; - $mac_table[$if][$mac]['cleanmac'] = $clean_mac; - $port_id = $interface['port_id']; - $mac_table[$port_id][$clean_mac] = 1; - - if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) { - // Commented below, no longer needed but leaving for reference. - // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; - $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id'])); - - if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { - d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); - - log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); - } - - dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); - echo '.'; - } - else if (isset($interface['port_id'])) { - echo '+'; - // echo("Add MAC $mac\n"); - $insert_data = array( - 'port_id' => $interface['port_id'], - 'mac_address' => $clean_mac, - 'ipv4_address' => $ip, - ); - - dbInsert($insert_data, 'ipv4_mac'); - }//end if - }//end if -}//end foreach - -$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'"; -foreach (dbFetchRows($sql) as $entry) { - $entry_mac = $entry['mac_address']; - $entry_if = $entry['port_id']; - if (!$mac_table[$entry_if][$entry_mac]) { - dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); - d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); - - echo '-'; - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; + + $ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); + $ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); + $ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); -echo "\n"; -unset($mac); + foreach (explode("\n", $ipNetToMedia_data) as $data) { + list($oid, $mac) = explode(' ', $data); + list($if, $first, $second, $third, $fourth) = explode('.', $oid); + $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; + if ($ip != '...') { + $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); + + list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); + $m_a = zeropad($m_a); + $m_b = zeropad($m_b); + $m_c = zeropad($m_c); + $m_d = zeropad($m_d); + $m_e = zeropad($m_e); + $m_f = zeropad($m_f); + $md_a = hexdec($m_a); + $md_b = hexdec($m_b); + $md_c = hexdec($m_c); + $md_d = hexdec($m_d); + $md_e = hexdec($m_e); + $md_f = hexdec($m_f); + $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; + + $mac_table[$if][$mac]['ip'] = $ip; + $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; + $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; + $mac_table[$if][$mac]['cleanmac'] = $clean_mac; + $port_id = $interface['port_id']; + $mac_table[$port_id][$clean_mac] = 1; + + if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']))) { + // Commented below, no longer needed but leaving for reference. + // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; + $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=? AND `context_name`= ?', array($ip, $interface['port_id']), $device['context_name']); + + if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { + d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); + + log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); + } + + dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name'])); + echo '.'; + } + else if (isset($interface['port_id'])) { + echo '+'; + // echo("Add MAC $mac\n"); + $insert_data = array( + 'port_id' => $interface['port_id'], + 'mac_address' => $clean_mac, + 'ipv4_address' => $ip, + 'context_name' => $device['context_name'], + ); + + dbInsert($insert_data, 'ipv4_mac'); + }//end if + }//end if + }//end foreach + + $sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = ' AND `context_name`= ?".$device['device_id']." AND M.context_name='". $device['context_name'] ."'"; + foreach (dbFetchRows($sql) as $entry) { + $entry_mac = $entry['mac_address']; + $entry_if = $entry['port_id']; + if (!$mac_table[$entry_if][$entry_mac]) { + dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ? AND `context_name`= ?', array($entry_if, $entry_mac, $device['context_name'])); + d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); + + echo '-'; + } + } + echo "\n"; + unset($mac); + unset($device['context_name']); +} +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf..dd341715d 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -3,232 +3,246 @@ if ($config['enable_bgp']) { // Discover BGP peers echo 'BGP Sessions : '; - + + if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; + } + else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); + } + $bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB', $config['mibdir'])); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + if (is_numeric($bgpLocalAs)) { + echo "AS$bgpLocalAs "; - if (is_numeric($bgpLocalAs)) { - echo "AS$bgpLocalAs "; - - if ($bgpLocalAs != $device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); - echo 'Updated AS '; - } - - $peer2 = false; - $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); - if (empty($peers_data)) { - $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); - } - else { - $peer2 = true; - } - - d_echo("Peers : $peers_data \n"); - - $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); - $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - - foreach (explode("\n", $peers) as $peer) { - if ($peer2 === true) { - list($ver, $peer) = explode('.', $peer, 2); + if ($bgpLocalAs != $device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); + echo 'Updated AS '; } - list($peer_ip, $peer_as) = explode(' ', $peer); - if (strstr($peer_ip, ':')) { - $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); - $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); - $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + $peer2 = false; + $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); + if (empty($peers_data)) { + $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); + } + else { + $peer2 = true; } - if ($peer && $peer_ip != '0.0.0.0') { - d_echo("Found peer $peer_ip (AS$peer_as)\n"); + d_echo("Peers : $peers_data \n"); - $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, - 'ver' => $ver, - ); - } - } + $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); + $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - if ($device['os'] == 'junos') { - // Juniper BGP4-V2 MIB - // FIXME: needs a big cleanup! also see below. - // FIXME: is .0.ipv6 the only possible value here? - $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); foreach (explode("\n", $peers) as $peer) { - list($peer_ip_snmp, $peer_as) = explode(' ', $peer); + if ($peer2 === true) { + list($ver, $peer) = explode('.', $peer, 2); + } - // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. - $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + list($peer_ip, $peer_as) = explode(' ', $peer); + if (strstr($peer_ip, ':')) { + $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); + $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); + $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + } - if ($peer) { + if ($peer && $peer_ip != '0.0.0.0') { d_echo("Found peer $peer_ip (AS$peer_as)\n"); $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, + 'ip' => $peer_ip, + 'as' => $peer_as, + 'ver' => $ver, ); } } - } - } - else { - echo 'No BGP on host'; - if ($device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); - echo ' (Removed ASN) '; - } - } - // Process disovered peers - if (isset($peerlist)) { - foreach ($peerlist as $peer) { - $astext = get_astext($peer['as']); + if ($device['os'] == 'junos') { + // Juniper BGP4-V2 MIB + // FIXME: needs a big cleanup! also see below. + // FIXME: is .0.ipv6 the only possible value here? + $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); + foreach (explode("\n", $peers) as $peer) { + list($peer_ip_snmp, $peer_as) = explode(' ', $peer); - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') { - $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as']), 'bgpPeers'); - if ($config['autodiscovery']['bgp'] === true) { - $name = gethostbyaddr($peer['ip']); - $remote_device_id = discover_new_device($name, $device, 'BGP'); + // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. + $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + + if ($peer) { + d_echo("Found peer $peer_ip (AS$peer_as)\n"); + + $peerlist[] = array( + 'ip' => $peer_ip, + 'as' => $peer_as, + ); + } + } + } + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; + } + } + + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); + + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $device['context_name'])) < '1') { + $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'],'context_name' => $device['context_name']), 'bgpPeers'); + if ($config['autodiscovery']['bgp'] === true) { + $name = gethostbyaddr($peer['ip']); + $remote_device_id = discover_new_device($name, $device, 'BGP'); + } + + echo '+'; + } + else { + $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); + echo '.'; } - echo '+'; - } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; - } + if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { + if ($device['os_group'] == 'cisco') { + // Get afi/safi and populate cbgp on cisco ios (xe/xr) + unset($af_list); - if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { - if ($device['os_group'] == 'cisco') { - // Get afi/safi and populate cbgp on cisco ios (xe/xr) - unset($af_list); - - if ($peer2 === true) { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - else { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - - d_echo('afi data :: '); - d_echo($af_data); - - foreach ($af_data as $k => $v) { if ($peer2 === true) { - list(,$k) = explode('.', $k, 2); + $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); + } + else { + $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); } - d_echo("AFISAFI = $k\n"); + d_echo('afi data :: '); + d_echo($af_data); - $afisafi_tmp = explode('.', $k); - $safi = array_pop($afisafi_tmp); - $afi = array_pop($afisafi_tmp); - $bgp_ip = str_replace(".$afi.$safi", '', $k); - $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); - $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); - $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); - if ($afi && $safi && $bgp_ip == $peer['ip']) { - $af_list[$bgp_ip][$afi][$safi] = 1; + foreach ($af_data as $k => $v) { + if ($peer2 === true) { + list(,$k) = explode('.', $k, 2); + } + + d_echo("AFISAFI = $k\n"); + + $afisafi_tmp = explode('.', $k); + $safi = array_pop($afisafi_tmp); + $afi = array_pop($afisafi_tmp); + $bgp_ip = str_replace(".$afi.$safi", '', $k); + $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); + $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); + $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); + if ($afi && $safi && $bgp_ip == $peer['ip']) { + $af_list[$bgp_ip][$afi][$safi] = 1; + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=? AND `context_name`=?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])) == 0) { + dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); + } + } + } + } + + if ($device['os'] == 'junos') { + $safis[1] = 'unicast'; + $safis[2] = 'multicast'; + + if (!isset($j_peerIndexes)) { + $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + + foreach ($j_bgp as $index => $entry) { + switch ($entry['jnxBgpM2PeerRemoteAddrType']) { + case 'ipv4': + $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); + d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; + break; + + case 'ipv6': + $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); + $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); + $ip6 = Net_IPv6::compress($ip6); + d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; + + default: + echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; + break; + } + } + } + + if (!isset($j_afisafi)) { + $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + foreach (array_keys($j_prefixes) as $key) { + list($index,$afisafi) = explode('.', $key, 2); + $j_afisafi[$index][] = $afisafi; + } + } + + foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { + list ($afi,$safi) = explode('.', $afisafi); + $safi = $safis[$safi]; + $af_list[$afi][$safi] = 1; if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); } } } - } - if ($device['os'] == 'junos') { - $safis[1] = 'unicast'; - $safis[2] = 'multicast'; - - if (!isset($j_peerIndexes)) { - $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - - foreach ($j_bgp as $index => $entry) { - switch ($entry['jnxBgpM2PeerRemoteAddrType']) { - case 'ipv4': - $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); - d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; - break; - - case 'ipv6': - $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); - $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); - $ip6 = Net_IPv6::compress($ip6); - d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; - break; - - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - break; - } + $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND `context_name` = '" . $device['context_name'] . "'"; + foreach (dbFetchRows($af_query) as $entry) { + $afi = $entry['afi']; + $safi = $entry['safi']; + if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { + dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])); } } - - if (!isset($j_afisafi)) { - $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - foreach (array_keys($j_prefixes) as $key) { - list($index,$afisafi) = explode('.', $key, 2); - $j_afisafi[$index][] = $afisafi; - } - } - - foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { - list ($afi,$safi) = explode('.', $afisafi); - $safi = $safis[$safi]; - $af_list[$afi][$safi] = 1; - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { - dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); - } - } - } - - $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"; - foreach (dbFetchRows($af_query) as $entry) { - $afi = $entry['afi']; - $safi = $entry['safi']; - if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { - dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); - } } } + + unset($j_afisafi); + unset($j_prefixes); + unset($j_bgp); + unset($j_peerIndexes); } - unset($j_afisafi); - unset($j_prefixes); - unset($j_bgp); - unset($j_peerIndexes); - } + // Delete removed peers + $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."' AND `context_name` = '" . $device['context_name'] . "'"; - // Delete removed peers - $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; + foreach (dbFetchRows($sql) as $entry) { + unset($exists); + $i = 0; - foreach (dbFetchRows($sql) as $entry) { - unset($exists); - $i = 0; + while ($i < count($peerlist) && !isset($exists)) { + if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { + $exists = 1; + } - while ($i < count($peerlist) && !isset($exists)) { - if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { - $exists = 1; + $i++; } - $i++; + if (!isset($exists)) { + dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + echo '-'; + } } - if (!isset($exists)) { - dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - echo '-'; - } + unset($peerlist); + + echo "\n"; + unset($device['context_name']); } - - unset($peerlist); - - echo "\n"; + unset($device['context_name']); + unset($vrfs_c); } diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php new file mode 100644 index 000000000..ae2aff0e4 --- /dev/null +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -0,0 +1,142 @@ + and Mathieu Millet +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . */ + + +global $debug; + +// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco +if ($config['enable_vrf_lite_cisco']) { + + $ids = array(); + + // For the moment only will be cisco and the version 3 + if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') { + + echo ("VRF lite cisco : \n"); + $mib = "SNMP-COMMUNITY-MIB"; + + $mib = "CISCO-CONTEXT-MAPPING-MIB"; + //-Osq because if i put the n the oid from the first command is not the same of this one + $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); + $listVrf = str_replace("cContextMappingVrfName.", "", $listVrf); + $listVrf = str_replace('"', "", $listVrf); + $listVrf = trim($listVrf); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); + } + + $tableVrf; + foreach (explode("\n", $listVrf) as $lineVrf) { + $tmpVrf = explode(" ", $lineVrf, 2); + //the $tmpVrf[0] will be the context + if (count($tmpVrf) == 2 && !empty($tmpVrf[1])) { + $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1]; + } + } + + unset($listVrf); + + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); + $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); + $listIntance = str_replace('"', "", $listIntance); + $listIntance = trim($listIntance); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + } + + + foreach (explode("\n", $listIntance) as $lineIntance) { + $tmpIntance = explode(" ", $lineIntance, 2); + //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance + if (count($tmpIntance) == 2 && !empty($tmpIntance[1])) { + $tableVrf[$tmpIntance[0]]['intance_name'] = $tmpIntance[1]; + } + } + unset($listIntance); + + + foreach ($tableVrf as $context => $vrf) { + + + + if ($debug) { + + echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n"); + } + + $tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", array( + $device ['device_id'], + $context + )); + if (!empty($tmpVrf)) { + + $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id']; + + $vrfUpdate=array(); + + foreach ($vrfUpdate as $key => $value) { + if($vrf[$key]!=$value){ + $vrfUpdate[$key]=$value; + } + } + if (!empty($vrfUpdate)) { + dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array( + $tmp['vrf_lite_cisco_id'] + )); + } + } else { + + $id = dbInsert(array( + 'device_id' => $device ['device_id'], + 'context_name' => $context, + 'intance_name' => $vrf['intance_name'], + 'vrf_name' => $vrf['vrf_name'] + ), 'vrf_lite_cisco'); + + $ids[$id] = $id; + } + } + + unset($tableVrf); + } + + //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work + $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( + $device ['device_id'])); + + $device['vrf_lite_cisco'] = $tmpVrfC; + + //Delete all vrf that chaged + foreach ($tmpVrfC as $vrfC) { + unset($ids[$vrfC['vrf_lite_cisco_id']]); + } + if (!empty($ids)) { + foreach ($ids as $id) { + + dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array( + $id)); + } + } + + + unset($ids); + unset($tmpVrfC); +} // enable_vrf_lite_cisco +?> diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index b03ac9048..e8055e63c 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -669,8 +669,8 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity }//end discover_toner() - -function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin) { + +function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name='') { global $device,$config; $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen").'/'.$ipv6_prefixlen; @@ -683,21 +683,21 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') { $port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } // Below looks like a duplicate of the above FIXME - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } - $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)); + $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { - dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id), 'ipv6_addresses'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ? AND `context_name` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { + dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses'); echo '+'; } else { diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 53cf3ad57..26fc9ba28 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ network.'/'.$addr->bitmask; - $cidr = $addr->bitmask; - - if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { - $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') { - dbInsert(array('ipv4_network' => $network), 'ipv4_networks'); - // echo("Create Subnet $network\n"); - echo 'S'; - } - - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)) == '0') { - dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id), 'ipv4_addresses'); - // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); - echo '+'; - } - else { - echo '.'; - } - - $full_address = "$oid/$cidr|$ifIndex"; - $valid_v4[$full_address] = 1; - } - else { - echo '!'; - }//end if -}//end foreach - -$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; - - if (!$valid_v4[$full_address]) { - echo '-'; - $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { - $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); - } - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -echo "\n"; + $oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB')); + $oids = str_replace('ipAdEntIfIndex.', '', $oids); + foreach (explode("\n", $oids) as $data) { + $data = trim($data); + list($oid,$ifIndex) = explode(' ', $data); + $mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB')); + $addr = Net_IPv4::parseAddress("$oid/$mask"); + $network = $addr->network.'/'.$addr->bitmask; + $cidr = $addr->bitmask; -unset($valid_v4); + if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { + $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name` = ?', array($network, $device['context_name'])) < '1') { + dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks'); + // echo("Create Subnet $network\n"); + echo 'S'; + } + + $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name`= ?', array($network, $device['context_name'])); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? and `context_name`=?', array($oid, $cidr, $port_id, $device['context_name'])) == '0') { + dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id,'context_name' => $device['context_name']), 'ipv4_addresses'); + // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); + echo '+'; + } + else { + echo '.'; + } + + $full_address = "$oid/$cidr|$ifIndex"; + $valid_v4[$full_address] = 1; + } + else { + echo '!'; + }//end if + }//end foreach + + $sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND a.context_name= '" . $device['context_name'] . "'"; + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; + + if (!$valid_v4[$full_address]) { + echo '-'; + $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { + $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); + } + } + } + + echo "\n"; + unset($device['context_name']); + unset($valid_v4); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index 562428b6b..f7762ee98 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -1,78 +1,89 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); -$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); -$oids = str_replace('"', '', $oids); -$oids = str_replace('IP-MIB::', '', $oids); -$oids = trim($oids); - -foreach (explode("\n", $oids) as $data) { - if ($data) { - $data = trim($data); - list($ipv6addr,$ifIndex) = explode(' ', $data); - $oid = ''; - $sep = ''; - $adsep = ''; - unset($ipv6_address); - $do = '0'; - foreach (explode(':', $ipv6addr) as $part) { - $n = hexdec($part); - $oid = "$oid"."$sep"."$n"; - $sep = '.'; - $ipv6_address = $ipv6_address."$adsep".$part; - $do++; - if ($do == 2) { - $adsep = ':'; - $do = '0'; - } - else { - $adsep = ''; - } - } - - $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); - $ipv6_prefixlen = explode('.', $ipv6_prefixlen); - $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); - - $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); - - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); - } //end if -} //end foreach - -if (!$oids) { - $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); - $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); + $oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); $oids = str_replace('"', '', $oids); + $oids = str_replace('IP-MIB::', '', $oids); $oids = trim($oids); foreach (explode("\n", $oids) as $data) { if ($data) { - $data = trim($data); - list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); - list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); - $ipv6_address = snmp2ipv6($ipv6addr); - $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); + $data = trim($data); + list($ipv6addr,$ifIndex) = explode(' ', $data); + $oid = ''; + $sep = ''; + $adsep = ''; + unset($ipv6_address); + $do = '0'; + foreach (explode(':', $ipv6addr) as $part) { + $n = hexdec($part); + $oid = "$oid"."$sep"."$n"; + $sep = '.'; + $ipv6_address = $ipv6_address."$adsep".$part; + $do++; + if ($do == 2) { + $adsep = ':'; + $do = '0'; + } + else { + $adsep = ''; + } + } + + $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); + $ipv6_prefixlen = explode('.', $ipv6_prefixlen); + $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); + + $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); + + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); } //end if } //end foreach -} //end if -$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; + if (!$oids) { + $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); + $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = str_replace('"', '', $oids); + $oids = trim($oids); -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; - $port_id = $row['port_id']; - $valid_address = $full_address.'-'.$port_id; - if (!$valid['ipv6'][$valid_address]) { - echo '-'; - $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { - $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + foreach (explode("\n", $oids) as $data) { + if ($data) { + $data = trim($data); + list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); + list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); + $ipv6_address = snmp2ipv6($ipv6addr); + $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); + } //end if + } //end foreach + } //end if + + $sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND A.context_name= '" . $device['context_name'] . "'"; + + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; + $port_id = $row['port_id']; + $valid_address = $full_address.'-'.$port_id; + if (!$valid['ipv6'][$valid_address]) { + echo '-'; + $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { + $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + } } } -} -echo "\n"; + echo "\n"; + unset($device['context_name']); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index 56863ec10..40ff425a0 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -2,6 +2,9 @@ if ($config['enable_bgp']) { foreach (dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])) as $peer) { + //add context if exist + $device['context_name']= $peer['context_name']; + // Poll BGP Peer $peer2 = false; echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' '; @@ -62,14 +65,28 @@ if ($config['enable_bgp']) { } } else { - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; - $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; - $peer_data = trim(`$peer_cmd`); + // $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; + $oids = "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . ""; + $peer_data=snmp_get_multi($device,$oids,'-OUQs','BGP4-MIB'); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } }//end if - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + //list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + unset($peer_data); } else if ($device['os'] == 'junos') { // v6 for JunOS via Juniper MIB @@ -78,9 +95,9 @@ if ($config['enable_bgp']) { if (!isset($junos_v6)) { echo "\nCaching Oids..."; // FIXME - needs moved to function - $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; - foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { + //$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + + foreach (explode("\n",snmp_get($device,'jnxBgpM2PeerStatus.0.ipv6"','-OUnq','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos")) as $oid){ list($peer_oid) = explode(' ', $oid); $peer_id = explode('.', $peer_oid); $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); @@ -88,25 +105,34 @@ if ($config['enable_bgp']) { } // FIXME - move to function (and clean up, wtf?) - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); - $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; - $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; - // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? - $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= '|grep -v "No Such Instance"'; - d_echo("\n$peer_cmd\n"); - - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + + $oids = " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip]; # Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? + $oids .= " jnxBgpM2PeerInUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerFsmEstablishedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip]; + //$peer_cmd .= '|grep -v "No Such Instance"'; WHAT TO DO WITH THIS??,USE TO SEE -Ln?? + $peer_data=snmp_get_multi($device,$oids,'-OUQs -Ln','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos"); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + unset($peer_data); + d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); @@ -235,23 +261,37 @@ if ($config['enable_bgp']) { } else { // FIXME - move to function - $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - - d_echo("$cbgp_cmd\n"); - - $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); - $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); + + + $oids = " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + + d_echo("$oids\n"); + + $cbgp_data= snmp_get_multi($device,$oids,'-OUQs ','CISCO-BGP4-MIB'); + $cbgp_data= array_pop($cbgp_data); + d_echo("$cbgp_data\n"); + + }//end if - list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + + $cbgpPeerAcceptedPrefixes= !empty($cbgp_data['cbgpPeerAcceptedPrefixes'])?$cbgp_data['cbgpPeerAcceptedPrefixes']:''; + $cbgpPeerDeniedPrefixes= !empty($cbgp_data['cbgpPeerDeniedPrefixes'])?$cbgp_data['cbgpPeerDeniedPrefixes']:''; + $cbgpPeerPrefixAdminLimit= !empty($cbgp_data['cbgpPeerPrefixAdminLimit'])?$cbgp_data['cbgpPeerPrefixAdminLimit']:''; + $cbgpPeerPrefixThreshold= !empty($cbgp_data['cbgpPeerPrefixThreshold'])?$cbgp_data['cbgpPeerPrefixThreshold']:''; + $cbgpPeerPrefixClearThreshold= !empty($cbgp_data['cbgpPeerPrefixClearThreshold'])?$cbgp_data['cbgpPeerPrefixClearThreshold']:''; + $cbgpPeerAdvertisedPrefixes= !empty($cbgp_data['cbgpPeerAdvertisedPrefixes'])?$cbgp_data['cbgpPeerAdvertisedPrefixes']:''; + $cbgpPeerSuppressedPrefixes= !empty($cbgp_data['cbgpPeerSuppressedPrefixes'])?$cbgp_data['cbgpPeerSuppressedPrefixes']:''; + $cbgpPeerWithdrawnPrefixes= !empty($cbgp_data['cbgpPeerWithdrawnPrefixes'])?$cbgp_data['cbgpPeerWithdrawnPrefixes']:''; + + unset($cbgp_data); }//end if if ($device['os'] == 'junos') { @@ -331,5 +371,6 @@ if ($config['enable_bgp']) { } //end foreach } //end if echo "\n"; + unset($device['context_name']); } //end foreach } //end if diff --git a/includes/polling/ospf.inc.php b/includes/polling/ospf.inc.php index 8fec222a2..602255258 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_port_count = 0; $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ $ospf_oids_db = array( 'ospfDemandExtensions', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; -} - -// Pull data from device -$ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); -foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_instances_db[$ospf_instance_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id), 'ospf_instances'); - echo '+'; - $ospf_instances_db[$entry['ospf_instance_id']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_instances_poll); - echo 'Database: '; - print_r($ospf_instances_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_instances_db)) { - foreach ($ospf_instances_db as $ospf_instance_db) { - $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_db['ospf_instance_id']]; - foreach ($ospf_oids_db as $oid) { - // Loop the OIDs - if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid]) { - // If data has changed, build a query - $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_instance_update) { - dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - echo 'U'; - unset($ospf_instance_update); - } - else { - echo '.'; - } - - unset($ospf_instance_poll); - unset($ospf_instance_db); - $ospf_instance_count++; - }//end foreach -}//end if - -unset($ospf_instances_poll); -unset($ospf_instances_db); - -echo ' Areas: '; - $ospf_area_oids = array( 'ospfAuthType', 'ospfImportAsExtern', @@ -95,72 +38,6 @@ $ospf_area_oids = array( 'ospfAreaStatus', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_areas_db[$entry['ospfAreaId']] = $entry; -} - -// Pull data from device -$ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_areas_db[$ospf_area_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id), 'ospf_areas'); - echo '+'; - $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - $ospf_areas_db[$entry['ospf_area_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_areas_poll); - echo 'Database: '; - print_r($ospf_areas_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_areas_db)) { - foreach ($ospf_areas_db as $ospf_area_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_area_poll = $ospf_areas_poll[$ospf_area_db['ospfAreaId']]; - foreach ($ospf_area_oids as $oid) { - // Loop the OIDs - if ($ospf_area_db[$oid] != $ospf_area_poll[$oid]) { - // If data has changed, build a query - $ospf_area_update[$oid] = $ospf_area_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME - } - } - - if ($ospf_area_update) { - dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - echo 'U'; - unset($ospf_area_update); - } - else { - echo '.'; - } - - unset($ospf_area_poll); - unset($ospf_area_db); - $ospf_area_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'])); - }//end if - }//end foreach -}//end if - -unset($ospf_areas_db); -unset($ospf_areas_poll); - -// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); -// print_r($ospf_ports); -echo ' Ports: '; - $ospf_port_oids = array( 'ospfIfIpAddress', 'port_id', @@ -171,7 +48,7 @@ $ospf_port_oids = array( 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,87 +62,6 @@ $ospf_port_oids = array( 'ospfIfAuthType', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_ports_db[$entry['ospf_port_id']] = $entry; -} - -// Pull data from device -$ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_ports_db[$ospf_port_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id), 'ospf_ports'); - echo '+'; - $ospf_ports_db[$entry['ospf_port_id']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_ports_poll); - echo 'Database: '; - print_r($ospf_ports_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_ports_db)) { - foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_port_poll = $ospf_ports_poll[$ospf_port_db['ospf_port_id']]; - - if ($ospf_port_poll['ospfAddressLessIf']) { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); - } - else { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'])); - } - - foreach ($ospf_port_oids as $oid) { - // Loop the OIDs - if ($ospf_port_db[$oid] != $ospf_port_poll[$oid]) { - // If data has changed, build a query - $ospf_port_update[$oid] = $ospf_port_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_port_update) { - dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - echo 'U'; - unset($ospf_port_update); - } - else { - echo '.'; - } - - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'])); - // "DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); - echo '-'; - }//end if - }//end foreach -}//end if - -// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 -// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 -// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 -// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrState.172.22.203.98.0 full -// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 -// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 -// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active -// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic -// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false -echo ' Neighbours: '; - $ospf_nbr_oids_db = array( 'ospfNbrIpAddr', 'ospfNbrAddressLessIndex', @@ -279,83 +75,313 @@ $ospf_nbr_oids_db = array( 'ospfNbmaNbrPermanence', 'ospfNbrHelloSuppressed', ); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])) as $nbr_entry) { - $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry; + + +if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) { + $vrfs_lite_cisco = $device['vrf_lite_cisco']; +} else { + $vrfs_lite_cisco = array(array('context_name' => null)); } -// Pull data from device -$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_nbrs_db[$ospf_nbr_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id), 'ospf_nbrs'); - echo '+'; - $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - $ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry; + $device['context_name'] = $vrf_lite['context_name']; + + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; } -} -if ($debug) { - echo "\nPolled: "; - print_r($ospf_nbrs_poll); - echo 'Database: '; - print_r($ospf_nbrs_db); - echo "\n"; -} + // Pull data from device + $ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); + foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (empty($ospf_instances_db[$ospf_instance_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id, 'context_name' => $device['context_name']), 'ospf_instances'); + echo '+'; + $ospf_instances_db[$entry['ospf_instance_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; + } + } -// Loop array of entries and update -if (is_array($ospf_nbrs_db)) { - foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { - if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { - $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + if ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'])); + // Loop array of entries and update + if (is_array($ospf_instances_db)) { + foreach ($ospf_instances_db as $ospf_instance_id => $ospf_instance_db) { + if (is_array($ospf_instances_poll[$ospf_instance_id])) { + $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_id]; + foreach ($ospf_oids_db as $oid) { + // Loop the OIDs + if ($ospf_instance_db[$device['context_name']][$oid] != $ospf_instance_poll[$oid]) { + // If data has changed, build a query + $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } - if ($ospf_nbr_db['port_id'] != $ospf_nbr_poll['port_id']) { - if ($ospf_nbr_poll['port_id']) { - $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + if ($ospf_instance_update) { + dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + echo 'U'; + unset($ospf_instance_update); } else { - $ospf_nbr_update = array('port_id' => array('NULL')); + echo '.'; } + + unset($ospf_instance_poll); + unset($ospf_instance_db); + $ospf_instance_count++; + } else { + dbDelete('ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=? ', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); } + }//end foreach + }//end if + unset($ospf_instances_poll); + unset($ospf_instances_db); - foreach ($ospf_nbr_oids as $oid) { - // Loop the OIDs - d_echo($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n"); - if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid]) { - // If data has changed, build a query - $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; - // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + + echo ' Areas: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `context_name`=?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_areas_db[$entry['ospfAreaId']][$entry['context_name']] = $entry; + } + + // Pull data from device + $ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_areas_db[$ospf_area_id][$entry['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id, 'context_name' => $device['context_name']), 'ospf_areas'); + echo '+'; + $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + $ospf_areas_db[$ospf_area_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_areas_poll); + echo 'Database: '; + print_r($ospf_areas_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_areas_db)) { + foreach ($ospf_areas_db as $$ospf_area_id => $ospf_area_db) { + if (is_array($ospf_areas_poll[$ospf_area_id])) { + $ospf_area_poll = $ospf_areas_poll[$ospf_area_id]; + foreach ($ospf_area_oids as $oid) { + // Loop the OIDs + if ($ospf_area_db[$entry['context_name']][$oid] != $ospf_area_poll[$oid]) { + // If data has changed, build a query + $ospf_area_update[$oid] = $ospf_area_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME + } } - } - if ($ospf_nbr_update) { - dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - echo 'U'; - unset($ospf_nbr_update); + if ($ospf_area_update) { + dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + echo 'U'; + unset($ospf_area_update); + } + else { + echo '.'; + } + + unset($ospf_area_poll); + unset($ospf_area_db); + $ospf_area_count++; } else { - echo '.'; - } + dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); + }//end if + }//end foreach + }//end if - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; + unset($ospf_areas_db); + unset($ospf_areas_poll); + + +// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); +// print_r($ospf_ports); + echo ' Ports: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = $entry; + } + + // Pull data from device + $ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_ports_db[$ospf_port_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id, 'context_name' => $device['context_name']), 'ospf_ports'); + echo '+'; + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); } - else { - dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'])); - echo '-'; - }//end if - }//end foreach -}//end if + } + if ($debug) { + echo "\nPolled: "; + print_r($ospf_ports_poll); + echo 'Database: '; + print_r($ospf_ports_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_ports_db)) { + foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { + if (is_array($ospf_ports_poll[$ospf_port_id])) { + $ospf_port_poll = $ospf_ports_poll[$ospf_port_id]; + + if ($ospf_port_poll['ospfAddressLessIf']) { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); + } + else { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'], $device['context_name'])); + } + + foreach ($ospf_port_oids as $oid) { + // Loop the OIDs + if ($ospf_port_db[$device['context_name']][$oid] != $ospf_port_poll[$oid]) { + // If data has changed, build a query + $ospf_port_update[$oid] = $ospf_port_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } + + if ($ospf_port_update) { + dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); + echo 'U'; + unset($ospf_port_update); + } + else { + echo '.'; + } + + unset($ospf_port_poll); + unset($ospf_port_db); + $ospf_port_count++; + } + else { + dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'], $device['context_name'])); + // ("DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); + echo '-'; + }//end if + }//end foreach + }//end if + + +// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 +// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 +// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 +// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrState.172.22.203.98.0 full +// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 +// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 +// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active +// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic +// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false + echo ' Neighbours: '; + + $ospf_nbr_oids_rrd = array(); + $ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $nbr_entry) { + $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']][$device['context_name']] = $nbr_entry; + } + + // Pull data from device + $ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_nbrs_db[$ospf_nbr_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id, 'context_name' => $device['context_name']), 'ospf_nbrs'); + echo '+'; + $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id,$device['context_name'])); + $ospf_nbrs_db[$ospf_nbr_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_nbrs_poll); + echo 'Database: '; + print_r($ospf_nbrs_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_nbrs_db)) { + foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { + if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { + $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + + $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'], $device['context_name'])); + + if ($ospf_nbr_db[$device['context_name']]['port_id'] != $ospf_nbr_poll['port_id']) { + if (!empty($ospf_nbr_poll['port_id'])) { + $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + } + else { + $ospf_nbr_update = array('port_id' => array('NULL')); + } + } + + foreach ($ospf_nbr_oids as $oid) { + // Loop the OIDs + d_echo($ospf_nbr_db[$device['context_name']][$oid].'|'.$ospf_nbr_poll[$oid]."\n"); + + if ($ospf_nbr_db[$device['context_name']][$oid] != $ospf_nbr_poll[$oid]) { + // If data has changed, build a query + $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; + // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + } + } + + if ($ospf_nbr_update) { + dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id, $device['context_name'])); + echo 'U'; + unset($ospf_nbr_update); + } + else { + echo '.'; + } + + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; + } + else { + dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'], $device['context_name'])); + echo '-'; + }//end if + }//end foreach + }//end if + unset($ospf_nbrs_db); + unset($ospf_nbrs_poll); +} +unset($device['context_name']); +unset($vrfs_lite_cisco); // Create device-wide statistics RRD $filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('ospf-statistics.rrd'); diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index e2d4bac01..c27b2989f 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -750,8 +750,14 @@ function snmp_gen_auth(&$device) { $cmd = ''; if ($device['snmpver'] === 'v3') { + $cmd = " -v3 -n '' -l '".$device['authlevel']."'"; - + + //add context if exist context + if(key_exists('context_name', $device)){ + $cmd = " -v3 -n '".$device['context_name']."' -l '".$device['authlevel']."'"; + } + if ($device['authlevel'] === 'noAuthNoPriv') { // We have to provide a username anyway (see Net-SNMP doc) // FIXME: There are two other places this is set - why are they ignored here? From 6a03b7dd049f565532adf303374f34f3f1d0e686 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 016/104] Adding sql-schema --- sql-schema/095.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sql-schema/095.sql diff --git a/sql-schema/095.sql b/sql-schema/095.sql new file mode 100644 index 000000000..61aa90432 --- /dev/null +++ b/sql-schema/095.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); +ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_mac ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers_cbgp ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas DROP INDEX device_area, ADD UNIQUE KEY `device_area` (`device_id`,`ospfAreaId`,`context_name`); +ALTER TABLE ospf_instances ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_instances DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_instance_id`,`context_name`); +ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); +ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; + From b50ca4b640dea5d2b3af8f6037902975591ef330 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 017/104] Adding sql-schema --- sql-schema/095.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/sql-schema/095.sql b/sql-schema/095.sql index 61aa90432..d35435553 100644 --- a/sql-schema/095.sql +++ b/sql-schema/095.sql @@ -16,4 +16,3 @@ ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`d ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; - From 63fa63559bc78d288aa28203ce4147bba7788c6c Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 018/104] Adding sql-schema --- sql-schema/095.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-schema/095.sql b/sql-schema/095.sql index d35435553..00bef74e3 100644 --- a/sql-schema/095.sql +++ b/sql-schema/095.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); +ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC) ; ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ipv4_mac ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; From 674171c2a37591e8cd41e4ad6dcbc97d484744a7 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Mon, 25 Jan 2016 11:17:06 +0100 Subject: [PATCH 019/104] Syntax update --- includes/defaults.inc.php | 4 +-- includes/discovery/arp-table.inc.php | 5 +-- includes/discovery/bgp-peers.inc.php | 3 +- includes/discovery/cisco-vrf-lite.inc.php | 41 +++++------------------ includes/discovery/ipv4-addresses.inc.php | 4 +-- includes/discovery/ipv6-addresses.inc.php | 2 +- 6 files changed, 18 insertions(+), 41 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index a418f7477..cadc5ae17 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -736,8 +736,8 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; -$config['discovery_modules']['cisco-vrf-lite'] = 1; -// $config['discovery_modules']['cisco-cef'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; +//$config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; $config['discovery_modules']['libvirt-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index c60d4ca95..a04b9db8a 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -7,9 +7,10 @@ echo 'ARP Table : '; if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } -else{ +else { $vrfs_lite_cisco = array(array('context_name'=>null)); } + foreach ($vrfs_lite_cisco as $vrf) { $device['context_name']=$vrf['context_name']; @@ -60,7 +61,7 @@ foreach ($vrfs_lite_cisco as $vrf) { dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name'])); echo '.'; } - else if (isset($interface['port_id'])) { + elseif (isset($interface['port_id'])) { echo '+'; // echo("Add MAC $mac\n"); $insert_data = array( diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index dd341715d..0d82f83ed 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -7,7 +7,7 @@ if ($config['enable_bgp']) { if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } - else{ + else { $vrfs_lite_cisco = array(array('context_name'=>null)); } @@ -237,7 +237,6 @@ if ($config['enable_bgp']) { echo '-'; } } - unset($peerlist); echo "\n"; diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php index ae2aff0e4..b079e618c 100644 --- a/includes/discovery/cisco-vrf-lite.inc.php +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -24,10 +24,8 @@ if ($config['enable_vrf_lite_cisco']) { // For the moment only will be cisco and the version 3 if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') { - echo ("VRF lite cisco : \n"); $mib = "SNMP-COMMUNITY-MIB"; - $mib = "CISCO-CONTEXT-MAPPING-MIB"; //-Osq because if i put the n the oid from the first command is not the same of this one $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); @@ -35,10 +33,8 @@ if ($config['enable_vrf_lite_cisco']) { $listVrf = str_replace('"', "", $listVrf); $listVrf = trim($listVrf); - if ($debug) { - echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); - echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); - } + d_echo("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + d_echo("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); $tableVrf; foreach (explode("\n", $listVrf) as $lineVrf) { @@ -48,20 +44,16 @@ if ($config['enable_vrf_lite_cisco']) { $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1]; } } - unset($listVrf); - + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); $listIntance = str_replace('"', "", $listIntance); $listIntance = trim($listIntance); - - if ($debug) { - echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); - echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); - } - - + + d_echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + d_echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + foreach (explode("\n", $listIntance) as $lineIntance) { $tmpIntance = explode(" ", $lineIntance, 2); //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance @@ -70,14 +62,9 @@ if ($config['enable_vrf_lite_cisco']) { } } unset($listIntance); - foreach ($tableVrf as $context => $vrf) { - - - if ($debug) { - echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n"); } @@ -86,9 +73,7 @@ if ($config['enable_vrf_lite_cisco']) { $context )); if (!empty($tmpVrf)) { - $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id']; - $vrfUpdate=array(); foreach ($vrfUpdate as $key => $value) { @@ -102,25 +87,21 @@ if ($config['enable_vrf_lite_cisco']) { )); } } else { - $id = dbInsert(array( 'device_id' => $device ['device_id'], 'context_name' => $context, 'intance_name' => $vrf['intance_name'], 'vrf_name' => $vrf['vrf_name'] ), 'vrf_lite_cisco'); - $ids[$id] = $id; } } - unset($tableVrf); } //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( $device ['device_id'])); - $device['vrf_lite_cisco'] = $tmpVrfC; //Delete all vrf that chaged @@ -129,14 +110,10 @@ if ($config['enable_vrf_lite_cisco']) { } if (!empty($ids)) { foreach ($ids as $id) { - - dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array( - $id)); + dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array($id)); } } - - unset($ids); unset($tmpVrfC); } // enable_vrf_lite_cisco -?> + diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 26fc9ba28..f930b8fd3 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,10 +1,10 @@ null)); } foreach ($vrfs_lite_cisco as $vrf) { diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index f7762ee98..fb9864020 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -4,7 +4,7 @@ echo 'IPv6 Addresses : '; if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } -else{ +else { $vrfs_lite_cisco = array(array('context_name'=>null)); } foreach ($vrfs_lite_cisco as $vrf) { From a01fc7cd69b9f9db2306ad8e88db392083d06f65 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Tue, 26 Jan 2016 14:54:24 +0100 Subject: [PATCH 020/104] modify order of cisco-vrf-lite --- includes/defaults.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index cadc5ae17..a02588729 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -722,6 +722,7 @@ $config['discovery_modules']['ports-stack'] = 1; $config['discovery_modules']['entity-physical'] = 1; $config['discovery_modules']['processors'] = 1; $config['discovery_modules']['mempools'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; $config['discovery_modules']['ipv4-addresses'] = 1; $config['discovery_modules']['ipv6-addresses'] = 1; $config['discovery_modules']['sensors'] = 1; @@ -736,8 +737,7 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; -$config['discovery_modules']['cisco-vrf-lite'] = 1; -//$config['discovery_modules']['cisco-cef'] = 1; +//$config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; $config['discovery_modules']['libvirt-vminfo'] = 1; From 24231cd6996b92558e18a03d58a6540daea2c7e3 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 021/104] Adding sql-schema --- sql-schema/097.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sql-schema/097.sql diff --git a/sql-schema/097.sql b/sql-schema/097.sql new file mode 100644 index 000000000..d35435553 --- /dev/null +++ b/sql-schema/097.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); +ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_mac ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers_cbgp ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas DROP INDEX device_area, ADD UNIQUE KEY `device_area` (`device_id`,`ospfAreaId`,`context_name`); +ALTER TABLE ospf_instances ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_instances DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_instance_id`,`context_name`); +ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); +ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; From ea5d2c66e6c5bd8c573b2ee6977d3c418c8400c3 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:05:14 +0100 Subject: [PATCH 022/104] Adding mibs --- mibs/CISCO-BRIDGE-DOMAIN-MIB | 450 +++++++++++++++++ mibs/CISCO-CONTEXT-MAPPING-MIB | 853 +++++++++++++++++++++++++++++++++ 2 files changed, 1303 insertions(+) create mode 100644 mibs/CISCO-BRIDGE-DOMAIN-MIB create mode 100644 mibs/CISCO-CONTEXT-MAPPING-MIB diff --git a/mibs/CISCO-BRIDGE-DOMAIN-MIB b/mibs/CISCO-BRIDGE-DOMAIN-MIB new file mode 100644 index 000000000..68e9ddb9c --- /dev/null +++ b/mibs/CISCO-BRIDGE-DOMAIN-MIB @@ -0,0 +1,450 @@ +-- ***************************************************************** +-- CISCO-BRIDGE-DOMAIN-MIB.my : Cisco Bridge Domain MIB +-- +-- Oct 2007, Madhavi Dokku +-- +-- Copyright (c) 2007 by Cisco Systems, Inc. +-- +-- All rights reserved. +-- ***************************************************************** + +CISCO-BRIDGE-DOMAIN-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE, + Unsigned32 + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + TEXTUAL-CONVENTION, + TruthValue, + RowStatus, + StorageType + FROM SNMPv2-TC + ifIndex + FROM IF-MIB + ciscoMgmt + FROM CISCO-SMI; + + +ciscoBridgeDomainMIB MODULE-IDENTITY + LAST-UPDATED "200712290000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + Tel: +1 800 553-NETS + + E-mail: cs-ethermibs@cisco.com" + DESCRIPTION + "A bridge domain is one of the means by which it is possible + to define a broadcast domain on a bridging device. It is an + alternative to 802.1D bridge-groups and to 802.1Q VLAN + bridging. + + Bridge domain is the service specification, and specifies the + broadcast domain number on which this frame of this particular + service instance must be made available on. The physical and + virtual interfaces that can comprise a bridge domain are + heterogeneous in nature comprising Ethernet service instances, + WAN Virtual Circuit for ATM or Frame Relay and VFIs. However, + the frame encapsulations for all interface types are + essentially Ethernet. + + Without bridge-domains, VLANs would have to be globally unique + per device and one would only be restricted to the theoretical + maximum of 4095 VLANs for single tagged traffic. However + with the introduction of bridge-domains, one can + associate a service instance with a bridge-domain and all + service instances in the same bridge-domain form a + broadcast domain. Bridge-domain ID determines the + broadcast domain and the VLAN id is merely used to match + and map traffic. With bridge domain feature configured + VLAN IDs would be unique per interface only and not globally. + Thus bridge domains make VLAN ids have only local + significance per port + + + Differences between Bridge Domains and 802.1AD Bridges: + ======================================================= + 1. Scope of the VLAN technology which uses 802.1 AD is global to + the box. + But in case of Bridge domain, the scope of vlan is local to + interface + + 2. Switchport 802.1AD restricts the number of broadcast domain + on a box to 4095. + However, with Bridge domains, we can have up to 16k broadcast + domain. + + 3. Under a single Bridge domain service instance, there can be + flexible service mapping criterion.(i.e match based on + outer vlan, outer cos, inner vlan, inner cos and payload + ethertype). + Whereas in case of switch port 802.1AD/dot1q this is not + supported. + + Similarities between Bridge Domains and 802.1AD Bridges: + ======================================================= + + 1. Both use the same MAC address lookup for forwarding. + + 2. Both work with protocols like STP, DTP etc. + + 3. Both of them classify 'ports' in a system into Bridges/Bridge + Domains. + + Ethernet service instance is the instantiation of an Ethernet + virtual circuit on a given port on a given router. In other + words, an Ethernet service instance is an object that holds + information about the layer 2 service that is being offered + on a given port of a given router as part of a given Ethernet + virtual circuit. Bridge domains feature is currently supported + on ethernet service instances only and can be later extented + to other interfaces like ATM and Frame Relay. + + This MIB helps the network management personnel to find out the + details of various broadcast domains configured in the network. + + Definition of terms and acronyms: + + ATM: Asynchronous Transfer mode + + BD: Bridge Domain + + C-mac: Customer MAC + + EVC: Ethernet Virtual Circuit + + FR: Frame Relay + + SH: Split Horizon + + VFI: Virtual Forwarding Instance + + VLAN: Virtual Local Area Network + + WAN: Wide Area Network" + REVISION "200712290000Z" + DESCRIPTION + "Modified the MIB description with details on similarities and + differences between Bridge Domains and 802.1AD Bridges." + REVISION "200712040000Z" + DESCRIPTION + "Initial version of this MIB module." + ::= { ciscoMgmt 642 } + + +ciscoBdMIBNotifications OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 0 } + +ciscoBdMIBObjects OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 1 } + +ciscoBdMIBConformance OBJECT IDENTIFIER + ::= { ciscoBridgeDomainMIB 2 } + +cbdSystemInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 1 } + +cbdMemberInfo OBJECT IDENTIFIER + ::= { ciscoBdMIBObjects 2 } + + +-- Textual Conventions + +CbdType ::= TEXTUAL-CONVENTION + STATUS current + DESCRIPTION + "Defines the different types of bridge domain members: + + 'other': none of the following + + 'ether': Ethernet Service Instance + + 'atmVc': ATM Virtual connection + + 'frVc': Frame Relay Virtual Connection" + SYNTAX INTEGER { + other(1), + ether(2), + atmVc(3), + frVc(4) + } + +cbdMembersConfigured OBJECT-TYPE + SYNTAX Unsigned32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the number of bridge domain + members configured on this bridge domain." + ::= { cbdSystemInfo 1 } +-- Member Info Table + +cbdMemberInfoTable OBJECT-TYPE + SYNTAX SEQUENCE OF CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table provides the bridge domain member attributes + of the members currently configured for each bridge + domain." + ::= { cbdMemberInfo 1 } + +cbdMemberInfoEntry OBJECT-TYPE + SYNTAX CbdMemberInfoEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A conceptual row in cbdMemberInfoTable. This is indexed + by ifIndex and cbdSIIndex. Each row is created when a bridge + domain member is configured under a service instance." + INDEX { + ifIndex, + cbdSIIndex + } + ::= { cbdMemberInfoTable 1 } + +CbdMemberInfoEntry ::= SEQUENCE { + cbdSIIndex Unsigned32, + cbdMemberType CbdType, + cbdMemberOperState INTEGER , + cbdMemberAdminState INTEGER , + cbdMemberSplitHorizon TruthValue, + cbdMemberSplitHorizonNum Unsigned32, + cbdMemberStorageType StorageType, + cbdMemberStatus RowStatus, + cbdMembercMac TruthValue +} + +cbdSIIndex OBJECT-TYPE + SYNTAX Unsigned32 (1..4294967295 ) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This object indicates an arbitary index that uniquely + identifies the Service Instance to which this bridge domain + member belongs to." + ::= { cbdMemberInfoEntry 1 } + +cbdMemberType OBJECT-TYPE + SYNTAX CbdType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object identifies the type of the bridge domain member + like ATM VC, Frame Relay VC, or Ethernet service." + DEFVAL { other } + ::= { cbdMemberInfoEntry 2 } + +cbdMemberOperState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "This object indicates the operational state of the bridge + domain Member. Operational state of the Bridge domain member + is same as the operational state of the underlying service + instance. Bridge domain members are configured under service + instances and multiple service instances can be attached to a + single physical interface defining various kinds of services. + Bridge domain members have many to one relationship with + interface + Indexes. When ifOperStatus of the underlying interface is down, + the state of cbdMemberOperState should be down. When + ifOperStatus + of the underlying interface is up, cbdMemberOperState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is an unknown state. + + 'up': the bridge domain member is fully operational and + able to bridge the traffic. This means that both the + physical interface and the underlying service instance + are administratively up. + + 'down': the Bridge Domain member is down and not + capable of bridging. This state means either the underlying + service instance is down or the interface is down." + ::= { cbdMemberInfoEntry 3 } + +cbdMemberAdminState OBJECT-TYPE + SYNTAX INTEGER { + unknown(1), + up(2), + down(3) + } + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the administrative state of the + bridge domain Member. Admin state of the Bridge domain member + is same as the admin state of the underlying service instance. + Bridge domain members are configured under service instances + and multiple service instances can be attached to a single + physical interface defining various kinds of services. Bridge + Domain members have many to one relationship with interface + Indexes. When ifAdminStatus of the unerlying interface is down + the state of cbdMemberAdminState should be down. When ifOperStatus + of the underlying interface is up cbdMemberAdminState can be + either up or down based on the state of underlying service + instance. + + 'unknown': the bridge domain member is in unknown + administrative state. + + 'up': the Bridge Domain member is administratively up. This + means that both the physical interface and the underlying service + instance are administratively up. + + 'admindown': the Bridge Domain member is down as it is + administratively configured to be down and is not + capable of bridging. This means that either the underlying + service instance is configured as administratively down or + the physical interface is configured as administratively + down." + ::= { cbdMemberInfoEntry 4 } + +cbdMemberSplitHorizon OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates whether split horizon is + configured on this bridge domain member." + ::= { cbdMemberInfoEntry 5 } + +cbdMemberSplitHorizonNum OBJECT-TYPE + SYNTAX Unsigned32 (0..65535 ) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates the split horizon number if + configured on the bridge domain member. Split horizon + is used to avoid sending traffic between interfaces. + Frames are not forwarded to the members belonging to the + same split horizon group." + DEFVAL { 0 } + ::= { cbdMemberInfoEntry 6 } + +cbdMemberStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object specifies the storage type of this conceptual + row. This object can only have a value 'nonVolatile'. Other + values are not applicable for this conceptual row and are + not supported." + DEFVAL { nonVolatile } + ::= { cbdMemberInfoEntry 7 } + +cbdMemberStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object enables the SNMP agent to create, modify, + and delete rows in the cbdMemberInfoTable." + DEFVAL { active } + ::= { cbdMemberInfoEntry 8 } + +cbdMembercMac OBJECT-TYPE + SYNTAX TruthValue + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object indicates if cmac is configured on this + bridge domain member. Cmac denotes if this bridge domain is + configured as a customer domain." + ::= { cbdMemberInfoEntry 9 } + + +-- Notifications + +ciscoBdNotificationPrefix OBJECT IDENTIFIER + ::= { ciscoBdMIBNotifications 0 } + +-- Conformance + +ciscoBdMIBCompliances OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 1 } + +ciscoBdMIBGroups OBJECT IDENTIFIER + ::= { ciscoBdMIBConformance 2 } + + +ciscoBdMIBComplianceRev1 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-BRIDGE-DOMAIN-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cbdSystemInfoGroup, + cbdMemberInfoGroup + } + ::= { ciscoBdMIBCompliances 1 } + +-- Units of Conformance + +cbdSystemInfoGroup OBJECT-GROUP + OBJECTS { cbdMembersConfigured } + STATUS current + DESCRIPTION + "This group contain information about bridge domain." + ::= { ciscoBdMIBGroups 1 } + +cbdMemberInfoGroup OBJECT-GROUP + OBJECTS { + cbdMemberType, + cbdMemberOperState, + cbdMemberAdminState, + cbdMemberSplitHorizon, + cbdMemberSplitHorizonNum, + cbdMemberStorageType, + cbdMemberStatus, + cbdMembercMac + } + STATUS current + DESCRIPTION + "This group contain information related to bridge domain + members." + ::= { ciscoBdMIBGroups 2 } + +END + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mibs/CISCO-CONTEXT-MAPPING-MIB b/mibs/CISCO-CONTEXT-MAPPING-MIB new file mode 100644 index 000000000..94451564d --- /dev/null +++ b/mibs/CISCO-CONTEXT-MAPPING-MIB @@ -0,0 +1,853 @@ +-- ***************************************************************** +-- CISCO-CONTEXT-MAPPING-MIB.my: Cisco Context Mapping MIB +-- +-- January 2005, Chinna Pellacuru. +-- +-- May 2008, Sheethal Gunjal. +-- +-- Copyright (c) 2004-2005, 2008 by cisco Systems Inc. +-- All rights reserved. +-- +-- **************************************************************** + +CISCO-CONTEXT-MAPPING-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, + OBJECT-TYPE + FROM SNMPv2-SMI + MODULE-COMPLIANCE, + OBJECT-GROUP + FROM SNMPv2-CONF + SnmpAdminString + FROM SNMP-FRAMEWORK-MIB + RowStatus, + StorageType + FROM SNMPv2-TC + CiscoBridgeDomain + FROM CISCO-TC + ciscoMgmt + FROM CISCO-SMI; + + +ciscoContextMappingMIB MODULE-IDENTITY + LAST-UPDATED "200811220000Z" + ORGANIZATION "Cisco Systems, Inc." + CONTACT-INFO + "Cisco Systems + Customer Service + + Postal: 170 W Tasman Drive + San Jose, CA 95134 + USA + + Tel: +1 800 553-NETS + + E-mail: cs-snmp@cisco.com" + DESCRIPTION + "A single SNMP agent sometimes needs to support multiple + instances of the same MIB module, and does so through the + use of multiple SNMP contexts. This typically occurs because + the technology has evolved to have extra dimension(s), i.e., + one or more extra data and/or identifier values which are + different in the different contexts, but were not defined in + INDEX clause(s) of the original MIB module. In such cases, + network management applications need to know the specific + data/identifier values in each context, and this MIB module + provides mapping tables which contain that information. + + Within a network there can be multiple Virtual Private + Networks (VPNs) configured using Virtual Routing and + Forwarding Instances (VRFs). Within a VPN there can be + multiple topologies when Multi-topology Routing (MTR) is + used. Also, Interior Gateway Protocols (IGPs) can have + multiple protocol instances running on the device. + A network can have multiple broadcast domains configured + using Bridge Domain Identifiers. + + With MTR routing, VRFs, and Bridge domains, a router now + needs to support multiple instances of several existing + MIB modules, and this can be achieved if the router's SNMP + agent provides access to each instance of the same MIB module + via a different SNMP context (see Section 3.1.1 of RFC 3411). + For MTR routing, VRFs, and Bridge domains, a different SNMP + context is needed depending on one or more of the following: + the VRF, the topology-identifier, the routing protocol instance, + and the bridge domain identifier. + In other words, the router's management information can be + accessed through multiple SNMP contexts where each such + context represents a specific VRF, a specific + topology-identifier, a specific routing protocol instance + and/or a bridge domain identifier. This MIB module provides + a mapping of each such SNMP context to the corresponding VRF, + the corresponding topology, the corresponding routing protocol + instance, and the corresponding bridge domain identifier. + Some SNMP contexts are independent of VRFs, independent of + a topology, independent of a routing protocol instance, or + independent of a bridge domain and in such a case, the mapping + is to the zero length string. + + With the Cisco package licensing strategy, the features + available in the image are grouped into multiple packages + and each packages can be managed to operate at different + feature levels based on the available license. This MIB + module provides option to associate an SNMP context to a + feature package group. This will allow manageability of + license MIB objects specific to a feature package group. + + As technology evolves more we may need additional + identifiers to identify the context. Then we would need + to add those additional identifiers into the mapping." + REVISION "200811220000Z" + DESCRIPTION + "Added New Table cContextMappingLicenseGroupTable + to provide SNMP Context support for license package groups. + + Added cContextMappingLicenseGroupDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev2 in MODULE-COMPLIANCE + + Updated the MIB description to indicate the use of + the above additions" + REVISION "200805300000Z" + DESCRIPTION + "Add cContextMappingBridgeInstanceTable. + + Added cContextMappingBridgeInstanceDataGroup. + Deprecated cContextMappingMIBComplianceRev1 and added + cContextMappingMIBComplianceRev2 compliance statement." + REVISION "200802010000Z" + DESCRIPTION + "Added New Table cContextMappingBridgeDomainTable + to provide SNMP context support to the Bridge Domain. + + Added cContextMappingBridgeDomainDataGroup in OBJECT-GROUP + Added cContextMappingMIBComplianceRev1 in MODULE-COMPLIANCE" + REVISION "200503170000Z" + DESCRIPTION + "Initial version of the MIB module." + ::= { ciscoMgmt 468 } + + +cContextMappingMIBObjects OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 1 } + +cContextMappingMIBConformance OBJECT IDENTIFIER + ::= { ciscoContextMappingMIB 2 } + + +cContextMappingTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which VRF, topology, and routing protocol instance. + + This table is indexed by SNMP VACM context. + + Configuring a row in this table for an SNMP context + does not require that the context be already defined, + i.e., a row can be created in this table for a context + before the corresponding row is created in RFC 3415's + vacmContextTable. + + To create a row in this table, a manager must set + cContextMappingRowStatus to either 'createAndGo' or + 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingRowStatus to 'destroy'." + ::= { cContextMappingMIBObjects 1 } + +cContextMappingEntry OBJECT-TYPE + SYNTAX CContextMappingEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the corresponding VRF, + the corresponding topology, and the corresponding routing + protocol instance." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingTable 1 } + +CContextMappingEntry ::= SEQUENCE { + cContextMappingVacmContextName SnmpAdminString, + cContextMappingVrfName SnmpAdminString, + cContextMappingTopologyName SnmpAdminString, + cContextMappingProtoInstName SnmpAdminString, + cContextMappingStorageType StorageType, + cContextMappingRowStatus RowStatus +} + +cContextMappingVacmContextName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The vacmContextName given to the SNMP context. + + This is a human readable name identifying a particular + SNMP VACM context at a particular SNMP entity. + The empty contextName (zero length) represents the + default context." + ::= { cContextMappingEntry 1 } + +cContextMappingVrfName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the VRF to which the SNMP context + is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this VRF. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any VRF." + DEFVAL { ''H } + ::= { cContextMappingEntry 2 } + +cContextMappingTopologyName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the topology to which the SNMP + context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this topology. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any topology." + DEFVAL { ''H } + ::= { cContextMappingEntry 3 } + +cContextMappingProtoInstName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the protocol instance to which the + SNMP context is mapped to. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this protocol instance. + + When the value of this object is the zero length + string it indicates that the SNMP context is independent + of any protocol instance." + DEFVAL { ''H } + ::= { cContextMappingEntry 4 } + +cContextMappingStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingEntry 5 } + +cContextMappingRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingEntry 6 } + + + +cContextMappingBridgeDomainTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which bridge domain. + + A Bridge Domain is one of the means by which it is possible + to define an Ethernet broadcast domain on a bridging device. + A network can have multiple broadcast domains configured. + This table helps the network management personnel to find + out the details of various broadcast domains configured + in the network. + + An entry need to exist in cContextMappingTable, to create + an entry in this table." + ::= { cContextMappingMIBObjects 2 } + +cContextMappingBridgeDomainEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeDomainEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge domain. + + To create a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeDomainRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeDomainTable 1 } + +CContextMappingBridgeDomainEntry ::= SEQUENCE { + cContextMappingBridgeDomainIdentifier CiscoBridgeDomain, + cContextMappingBridgeDomainStorageType StorageType, + cContextMappingBridgeDomainRowStatus RowStatus +} + +cContextMappingBridgeDomainIdentifier OBJECT-TYPE + SYNTAX CiscoBridgeDomain + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the bridge domain to which the SNMP context is + mapped to." + REFERENCE "CISCO-BRIDGE-DOMAIN-MIB" + ::= { cContextMappingBridgeDomainEntry 1 } + +cContextMappingBridgeDomainStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeDomainEntry 2 } + +cContextMappingBridgeDomainRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeDomainEntry 3 } + + + +cContextMappingBridgeInstanceTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on mapping between + cContextMappingVacmContextName and bridge instance. + + Bridge instance is an instance of a physical or logical + bridge which has unique bridge-id. + + If an entry is deleted from cContextMappingTable, the + corresponding entry in this table will also get deleted. + + If an entry needs to be created in this table, the + corresponding entry must exist in cContextMappingTable." + REFERENCE "BRIDGE-MIB" + ::= { cContextMappingMIBObjects 3 } + +cContextMappingBridgeInstanceEntry OBJECT-TYPE + SYNTAX CContextMappingBridgeInstanceEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + cContextMappingVacmContextName to the + corresponding bridge instance. + + To create a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to either + 'createAndGo' or 'createAndWait'. + + To delete a row in this table, a manager must set + cContextMappingBridgeInstRowStatus to 'destroy'." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingBridgeInstanceTable 1 } + +CContextMappingBridgeInstanceEntry ::= SEQUENCE { + cContextMappingBridgeInstName SnmpAdminString, + cContextMappingBridgeInstStorageType StorageType, + cContextMappingBridgeInstRowStatus RowStatus +} + +cContextMappingBridgeInstName OBJECT-TYPE + SYNTAX SnmpAdminString + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The object identifies the name given to bridge + instance to which the SNMP context is mapped to. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + This is typically a human-readable string. This is + the same ASCII string used in the router's console + interface to refer to this bridge instance. + + When the value of this object is a zero length + string, it indicates that the SNMP context is + independent of any bridge instances." + ::= { cContextMappingBridgeInstanceEntry 1 } + +cContextMappingBridgeInstStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Value of this object cannot be changed when the + RowStatus object in the same row is 'active'. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingBridgeInstanceEntry 2 } + +cContextMappingBridgeInstRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingBridgeInstanceEntry 3 } + + + +cContextMappingLicenseGroupTable OBJECT-TYPE + SYNTAX SEQUENCE OF CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "This table contains information on which + cContextMappingVacmContextName is mapped to + which License Group. + Group level licensing is used where each + Technology Package is enabled via a License." + ::= { cContextMappingMIBObjects 4 } + +cContextMappingLicenseGroupEntry OBJECT-TYPE + SYNTAX CContextMappingLicenseGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "Information relating to a single mapping of + CContextMappingVacmContextName to the + corresponding License Group." + INDEX { cContextMappingVacmContextName } + ::= { cContextMappingLicenseGroupTable 1 } + +CContextMappingLicenseGroupEntry ::= SEQUENCE { + cContextMappingLicenseGroupName SnmpAdminString, + cContextMappingLicenseGroupStorageType StorageType, + cContextMappingLicenseGroupRowStatus RowStatus +} + +cContextMappingLicenseGroupName OBJECT-TYPE + SYNTAX SnmpAdminString (SIZE (0..32)) + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The value of an instance of this object identifies + the name given to the Group to which the SNMP context + is mapped. + + Feature sets from all groups will be combined to form + universal image. User can configure multiple groups as needed. + + For example: In Next generation ISRs will use + the universal image package level licensing model + for its licensing need. Each group has + the feature set needed for that specific technology. + Feature sets from different groups are combined to + form universal image and each feature set for a group + can be enabled using a valid license key. There will + be a base level ipbase package in which the router + boots with out any license key. + + The following are the different Technology Groups. + 1.crypto + 2.data + 3.ip + 4.legacy + 5.novpn-security + 6.security + 7.uc" + ::= { cContextMappingLicenseGroupEntry 1 } + +cContextMappingLicenseGroupStorageType OBJECT-TYPE + SYNTAX StorageType + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "The storage type for this conceptual row. + + Conceptual rows having the value 'permanent' need not + allow write-access to any columnar objects in the row." + DEFVAL { nonVolatile } + ::= { cContextMappingLicenseGroupEntry 2 } + +cContextMappingLicenseGroupRowStatus OBJECT-TYPE + SYNTAX RowStatus + MAX-ACCESS read-create + STATUS current + DESCRIPTION + "This object facilitates the creation, modification, or + deletion of a conceptual row in this table." + ::= { cContextMappingLicenseGroupEntry 3 } + + +-- Conformance + +cContextMappingMIBCompliances OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 1 } + +cContextMappingMIBGroups OBJECT IDENTIFIER + ::= { cContextMappingMIBConformance 2 } + + +-- Compliance + +cContextMappingMIBCompliance MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { cContextMappingDataGroup } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 1 } + +cContextMappingMIBComplianceRev1 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB. This compliance statement + is superceded by cContextMappingMIBComplianceRev2." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 2 } + +cContextMappingMIBComplianceRev2 MODULE-COMPLIANCE + STATUS deprecated + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + ::= { cContextMappingMIBCompliances 3 } + +cContextMappingMIBComplianceRev3 MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "The compliance statement for entities which implement + the CISCO-CONTEXT-MAPPING-MIB." + MODULE -- this module + MANDATORY-GROUPS { + cContextMappingDataGroup, + cContextMappingBridgeDomainDataGroup, + cContextMappingBridgeInstanceDataGroup, + cContextMappingLicenseGroupDataGroup + } + + OBJECT cContextMappingVrfName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingTopologyName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingProtoInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + + OBJECT cContextMappingBridgeDomainIdentifier + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeDomainRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeDomainTable is not required." + + OBJECT cContextMappingBridgeInstName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingBridgeInstRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingBridgeInstanceTable is not required." + + OBJECT cContextMappingLicenseGroupName + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupStorageType + MIN-ACCESS read-only + DESCRIPTION + "Write access is not required." + + OBJECT cContextMappingLicenseGroupRowStatus + MIN-ACCESS read-only + DESCRIPTION + "Create/delete/modify access to the + cContextMappingTable is not required." + ::= { cContextMappingMIBCompliances 4 } + +-- Units of Conformance + +cContextMappingDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingVrfName, + cContextMappingTopologyName, + cContextMappingProtoInstName, + cContextMappingStorageType, + cContextMappingRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding VRF, the corresponding topology, + and the corresponding routing protocol instance." + ::= { cContextMappingMIBGroups 1 } + +cContextMappingBridgeDomainDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeDomainIdentifier, + cContextMappingBridgeDomainStorageType, + cContextMappingBridgeDomainRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge domain." + ::= { cContextMappingMIBGroups 2 } + +cContextMappingBridgeInstanceDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingBridgeInstName, + cContextMappingBridgeInstStorageType, + cContextMappingBridgeInstRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding bridge instance." + ::= { cContextMappingMIBGroups 3 } + +cContextMappingLicenseGroupDataGroup OBJECT-GROUP + OBJECTS { + cContextMappingLicenseGroupName, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupStorageType, + cContextMappingLicenseGroupRowStatus + } + STATUS current + DESCRIPTION + "The collection of objects providing the context + mapping data between the SNMP context to the + corresponding LicenseGroupName." + ::= { cContextMappingMIBGroups 4 } + +END + + + + + + + + From 0ac8f584b23b155fbed9614b59eee2ab55e8d4ca Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:13:53 +0100 Subject: [PATCH 023/104] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 158 ++++--- includes/discovery/bgp-peers.inc.php | 378 ++++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 114 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 125 +++-- includes/polling/ospf.inc.php | 548 +++++++++++----------- includes/snmp.inc.php | 8 +- 11 files changed, 957 insertions(+), 682 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index d32f836ab..0b7a63573 100644 --- a/includes/common.php +++ b/includes/common.php @@ -306,6 +306,16 @@ function device_by_id_cache($device_id, $refresh = '0') { } else { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id)); + + //order vrf_lite_cisco with context, this will help to get the vrf_name and instance_name all the time + $vrfs_lite_cisco = dbFetchRows("SELECT * FROM `vrf_lite_cisco` WHERE `device_id` = ?", array($device_id)); + $device['vrf_lite_cisco'] = array(); + if(!empty($vrfs_lite_cisco)){ + foreach ($vrfs_lite_cisco as $vrf){ + $device['vrf_lite_cisco'][$vrf['context_name']] = $vrf; + } + } + $cache['devices']['id'][$device_id] = $device; } return $device; diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 328ae2ce0..a418f7477 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ $config['enable_pseudowires'] = 1; // Enable Pseudowires $config['enable_vrfs'] = 1; // Enable VRFs +$config['enable_vrf_lite_cisco'] = 1; +// Enable VRF lite cisco $config['enable_printers'] = 0; // Enable Printer support $config['enable_sla'] = 0; @@ -734,6 +736,7 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; // $config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index 69b0d9b75..c60d4ca95 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ unset($mac_table); echo 'ARP Table : '; -$ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); -$ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); -$ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); - -foreach (explode("\n", $ipNetToMedia_data) as $data) { - list($oid, $mac) = explode(' ', $data); - list($if, $first, $second, $third, $fourth) = explode('.', $oid); - $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; - if ($ip != '...') { - $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); - - list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); - $m_a = zeropad($m_a); - $m_b = zeropad($m_b); - $m_c = zeropad($m_c); - $m_d = zeropad($m_d); - $m_e = zeropad($m_e); - $m_f = zeropad($m_f); - $md_a = hexdec($m_a); - $md_b = hexdec($m_b); - $md_c = hexdec($m_c); - $md_d = hexdec($m_d); - $md_e = hexdec($m_e); - $md_f = hexdec($m_f); - $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; - - $mac_table[$if][$mac]['ip'] = $ip; - $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; - $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; - $mac_table[$if][$mac]['cleanmac'] = $clean_mac; - $port_id = $interface['port_id']; - $mac_table[$port_id][$clean_mac] = 1; - - if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ?', array($interface['port_id'], $ip))) { - // Commented below, no longer needed but leaving for reference. - // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; - $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=?', array($ip, $interface['port_id'])); - - if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { - d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); - - log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); - } - - dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); - echo '.'; - } - else if (isset($interface['port_id'])) { - echo '+'; - // echo("Add MAC $mac\n"); - $insert_data = array( - 'port_id' => $interface['port_id'], - 'mac_address' => $clean_mac, - 'ipv4_address' => $ip, - ); - - dbInsert($insert_data, 'ipv4_mac'); - }//end if - }//end if -}//end foreach - -$sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = '".$device['device_id']."'"; -foreach (dbFetchRows($sql) as $entry) { - $entry_mac = $entry['mac_address']; - $entry_if = $entry['port_id']; - if (!$mac_table[$entry_if][$entry_mac]) { - dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); - d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); - - echo '-'; - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; + + $ipNetToMedia_data = snmp_walk($device, 'ipNetToMediaPhysAddress', '-Oq', 'IP-MIB'); + $ipNetToMedia_data = str_replace('ipNetToMediaPhysAddress.', '', trim($ipNetToMedia_data)); + $ipNetToMedia_data = str_replace('IP-MIB::', '', trim($ipNetToMedia_data)); -echo "\n"; -unset($mac); + foreach (explode("\n", $ipNetToMedia_data) as $data) { + list($oid, $mac) = explode(' ', $data); + list($if, $first, $second, $third, $fourth) = explode('.', $oid); + $ip = $first.'.'.$second.'.'.$third.'.'.$fourth; + if ($ip != '...') { + $interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if)); + + list($m_a, $m_b, $m_c, $m_d, $m_e, $m_f) = explode(':', $mac); + $m_a = zeropad($m_a); + $m_b = zeropad($m_b); + $m_c = zeropad($m_c); + $m_d = zeropad($m_d); + $m_e = zeropad($m_e); + $m_f = zeropad($m_f); + $md_a = hexdec($m_a); + $md_b = hexdec($m_b); + $md_c = hexdec($m_c); + $md_d = hexdec($m_d); + $md_e = hexdec($m_e); + $md_f = hexdec($m_f); + $mac = "$m_a:$m_b:$m_c:$m_d:$m_e:$m_f"; + + $mac_table[$if][$mac]['ip'] = $ip; + $mac_table[$if][$mac]['ciscomac'] = "$m_a$m_b.$m_c$m_d.$m_e$m_f"; + $clean_mac = $m_a.$m_b.$m_c.$m_d.$m_e.$m_f; + $mac_table[$if][$mac]['cleanmac'] = $clean_mac; + $port_id = $interface['port_id']; + $mac_table[$port_id][$clean_mac] = 1; + + if (dbFetchCell('SELECT COUNT(*) from ipv4_mac WHERE port_id = ? AND ipv4_address = ? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name']))) { + // Commented below, no longer needed but leaving for reference. + // $sql = "UPDATE `ipv4_mac` SET `mac_address` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND ipv4_address = '$ip'"; + $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=? AND port_id=? AND `context_name`= ?', array($ip, $interface['port_id']), $device['context_name']); + + if ($clean_mac != $old_mac && $clean_mac != '' && $old_mac != '') { + d_echo("Changed mac address for $ip from $old_mac to $clean_mac\n"); + + log_event("MAC change: $ip : ".mac_clean_to_readable($old_mac).' -> '.mac_clean_to_readable($clean_mac), $device, 'interface', $interface['port_id']); + } + + dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name'])); + echo '.'; + } + else if (isset($interface['port_id'])) { + echo '+'; + // echo("Add MAC $mac\n"); + $insert_data = array( + 'port_id' => $interface['port_id'], + 'mac_address' => $clean_mac, + 'ipv4_address' => $ip, + 'context_name' => $device['context_name'], + ); + + dbInsert($insert_data, 'ipv4_mac'); + }//end if + }//end if + }//end foreach + + $sql = "SELECT * from ipv4_mac AS M, ports as I WHERE M.port_id = I.port_id and I.device_id = ' AND `context_name`= ?".$device['device_id']." AND M.context_name='". $device['context_name'] ."'"; + foreach (dbFetchRows($sql) as $entry) { + $entry_mac = $entry['mac_address']; + $entry_if = $entry['port_id']; + if (!$mac_table[$entry_if][$entry_mac]) { + dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ? AND `context_name`= ?', array($entry_if, $entry_mac, $device['context_name'])); + d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); + + echo '-'; + } + } + echo "\n"; + unset($mac); + unset($device['context_name']); +} +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf..dd341715d 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -3,232 +3,246 @@ if ($config['enable_bgp']) { // Discover BGP peers echo 'BGP Sessions : '; - + + if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; + } + else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); + } + $bgpLocalAs = trim(snmp_walk($device, '.1.3.6.1.2.1.15.2', '-Oqvn', 'BGP4-MIB', $config['mibdir'])); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + if (is_numeric($bgpLocalAs)) { + echo "AS$bgpLocalAs "; - if (is_numeric($bgpLocalAs)) { - echo "AS$bgpLocalAs "; - - if ($bgpLocalAs != $device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); - echo 'Updated AS '; - } - - $peer2 = false; - $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); - if (empty($peers_data)) { - $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); - } - else { - $peer2 = true; - } - - d_echo("Peers : $peers_data \n"); - - $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); - $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - - foreach (explode("\n", $peers) as $peer) { - if ($peer2 === true) { - list($ver, $peer) = explode('.', $peer, 2); + if ($bgpLocalAs != $device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => $bgpLocalAs), 'devices', 'device_id=?', array($device['device_id'])); + echo 'Updated AS '; } - list($peer_ip, $peer_as) = explode(' ', $peer); - if (strstr($peer_ip, ':')) { - $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); - $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); - $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + $peer2 = false; + $peers_data = snmp_walk($device, 'cbgpPeer2RemoteAs', '-Oq', 'CISCO-BGP4-MIB', $config['mibdir']); + if (empty($peers_data)) { + $peers_data = snmp_walk($device, 'BGP4-MIB::bgpPeerRemoteAs', '-Oq', 'BGP4-MIB', $config['mibdir']); + } + else { + $peer2 = true; } - if ($peer && $peer_ip != '0.0.0.0') { - d_echo("Found peer $peer_ip (AS$peer_as)\n"); + d_echo("Peers : $peers_data \n"); - $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, - 'ver' => $ver, - ); - } - } + $peers = trim(str_replace('CISCO-BGP4-MIB::cbgpPeer2RemoteAs.', '', $peers_data)); + $peers = trim(str_replace('BGP4-MIB::bgpPeerRemoteAs.', '', $peers)); - if ($device['os'] == 'junos') { - // Juniper BGP4-V2 MIB - // FIXME: needs a big cleanup! also see below. - // FIXME: is .0.ipv6 the only possible value here? - $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); foreach (explode("\n", $peers) as $peer) { - list($peer_ip_snmp, $peer_as) = explode(' ', $peer); + if ($peer2 === true) { + list($ver, $peer) = explode('.', $peer, 2); + } - // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. - $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + list($peer_ip, $peer_as) = explode(' ', $peer); + if (strstr($peer_ip, ':')) { + $peer_ip_snmp = preg_replace('/:/', ' ', $peer_ip); + $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); + $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); + } - if ($peer) { + if ($peer && $peer_ip != '0.0.0.0') { d_echo("Found peer $peer_ip (AS$peer_as)\n"); $peerlist[] = array( - 'ip' => $peer_ip, - 'as' => $peer_as, + 'ip' => $peer_ip, + 'as' => $peer_as, + 'ver' => $ver, ); } } - } - } - else { - echo 'No BGP on host'; - if ($device['bgpLocalAs']) { - dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); - echo ' (Removed ASN) '; - } - } - // Process disovered peers - if (isset($peerlist)) { - foreach ($peerlist as $peer) { - $astext = get_astext($peer['as']); + if ($device['os'] == 'junos') { + // Juniper BGP4-V2 MIB + // FIXME: needs a big cleanup! also see below. + // FIXME: is .0.ipv6 the only possible value here? + $result = snmp_walk($device, 'jnxBgpM2PeerRemoteAs.0.ipv6', '-Onq', 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + $peers = trim(str_replace('.1.3.6.1.4.1.2636.5.1.1.2.1.1.1.13.0.', '', $result)); + foreach (explode("\n", $peers) as $peer) { + list($peer_ip_snmp, $peer_as) = explode(' ', $peer); - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['ip'])) < '1') { - $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as']), 'bgpPeers'); - if ($config['autodiscovery']['bgp'] === true) { - $name = gethostbyaddr($peer['ip']); - $remote_device_id = discover_new_device($name, $device, 'BGP'); + // Magic! Basically, takes SNMP form and finds peer IPs from the walk OIDs. + $peer_ip = Net_IPv6::compress(snmp2ipv6(implode('.', array_slice(explode('.', $peer_ip_snmp), (count(explode('.', $peer_ip_snmp)) - 16))))); + + if ($peer) { + d_echo("Found peer $peer_ip (AS$peer_as)\n"); + + $peerlist[] = array( + 'ip' => $peer_ip, + 'as' => $peer_as, + ); + } + } + } + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; + } + } + + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); + + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers` WHERE device_id = ? AND bgpPeerIdentifier = ? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $device['context_name'])) < '1') { + $add = dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'bgpPeerRemoteAs' => $peer['as'],'context_name' => $device['context_name']), 'bgpPeers'); + if ($config['autodiscovery']['bgp'] === true) { + $name = gethostbyaddr($peer['ip']); + $remote_device_id = discover_new_device($name, $device, 'BGP'); + } + + echo '+'; + } + else { + $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); + echo '.'; } - echo '+'; - } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; - } + if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { + if ($device['os_group'] == 'cisco') { + // Get afi/safi and populate cbgp on cisco ios (xe/xr) + unset($af_list); - if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { - if ($device['os_group'] == 'cisco') { - // Get afi/safi and populate cbgp on cisco ios (xe/xr) - unset($af_list); - - if ($peer2 === true) { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - else { - $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - - d_echo('afi data :: '); - d_echo($af_data); - - foreach ($af_data as $k => $v) { if ($peer2 === true) { - list(,$k) = explode('.', $k, 2); + $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); + } + else { + $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); } - d_echo("AFISAFI = $k\n"); + d_echo('afi data :: '); + d_echo($af_data); - $afisafi_tmp = explode('.', $k); - $safi = array_pop($afisafi_tmp); - $afi = array_pop($afisafi_tmp); - $bgp_ip = str_replace(".$afi.$safi", '', $k); - $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); - $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); - $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); - if ($afi && $safi && $bgp_ip == $peer['ip']) { - $af_list[$bgp_ip][$afi][$safi] = 1; + foreach ($af_data as $k => $v) { + if ($peer2 === true) { + list(,$k) = explode('.', $k, 2); + } + + d_echo("AFISAFI = $k\n"); + + $afisafi_tmp = explode('.', $k); + $safi = array_pop($afisafi_tmp); + $afi = array_pop($afisafi_tmp); + $bgp_ip = str_replace(".$afi.$safi", '', $k); + $bgp_ip = preg_replace('/:/', ' ', $bgp_ip); + $bgp_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $bgp_ip); + $bgp_ip = str_replace('"', '', str_replace(' ', '', $bgp_ip)); + if ($afi && $safi && $bgp_ip == $peer['ip']) { + $af_list[$bgp_ip][$afi][$safi] = 1; + if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=? AND `context_name`=?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])) == 0) { + dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); + } + } + } + } + + if ($device['os'] == 'junos') { + $safis[1] = 'unicast'; + $safis[2] = 'multicast'; + + if (!isset($j_peerIndexes)) { + $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + + foreach ($j_bgp as $index => $entry) { + switch ($entry['jnxBgpM2PeerRemoteAddrType']) { + case 'ipv4': + $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); + d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; + break; + + case 'ipv6': + $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); + $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); + $ip6 = Net_IPv6::compress($ip6); + d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); + + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; + + default: + echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; + break; + } + } + } + + if (!isset($j_afisafi)) { + $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); + foreach (array_keys($j_prefixes) as $key) { + list($index,$afisafi) = explode('.', $key, 2); + $j_afisafi[$index][] = $afisafi; + } + } + + foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { + list ($afi,$safi) = explode('.', $afisafi); + $safi = $safis[$safi]; + $af_list[$afi][$safi] = 1; if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); } } } - } - if ($device['os'] == 'junos') { - $safis[1] = 'unicast'; - $safis[2] = 'multicast'; - - if (!isset($j_peerIndexes)) { - $j_bgp = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PeerTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - - foreach ($j_bgp as $index => $entry) { - switch ($entry['jnxBgpM2PeerRemoteAddrType']) { - case 'ipv4': - $ip = long2ip(hexdec($entry['jnxBgpM2PeerRemoteAddr'])); - d_echo("peerindex for ipv4 $ip is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip] = $entry['jnxBgpM2PeerIndex']; - break; - - case 'ipv6': - $ip6 = trim(str_replace(' ', '', $entry['jnxBgpM2PeerRemoteAddr']), '"'); - $ip6 = substr($ip6, 0, 4).':'.substr($ip6, 4, 4).':'.substr($ip6, 8, 4).':'.substr($ip6, 12, 4).':'.substr($ip6, 16, 4).':'.substr($ip6, 20, 4).':'.substr($ip6, 24, 4).':'.substr($ip6, 28, 4); - $ip6 = Net_IPv6::compress($ip6); - d_echo("peerindex for ipv6 $ip6 is ".$entry['jnxBgpM2PeerIndex']."\n"); - - $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; - break; - - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - break; - } + $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND `context_name` = '" . $device['context_name'] . "'"; + foreach (dbFetchRows($af_query) as $entry) { + $afi = $entry['afi']; + $safi = $entry['safi']; + if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { + dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=? AND `context_name` = ?', array($device['device_id'], $peer['ip'], $afi, $safi, $device['context_name'])); } } - - if (!isset($j_afisafi)) { - $j_prefixes = snmpwalk_cache_multi_oid($device, 'jnxBgpM2PrefixCountersTable', $jbgp, 'BGP4-V2-MIB-JUNIPER', $config['install_dir'].'/mibs/junos'); - foreach (array_keys($j_prefixes) as $key) { - list($index,$afisafi) = explode('.', $key, 2); - $j_afisafi[$index][] = $afisafi; - } - } - - foreach ($j_afisafi[$j_peerIndexes[$peer['ip']]] as $afisafi) { - list ($afi,$safi) = explode('.', $afisafi); - $safi = $safis[$safi]; - $af_list[$afi][$safi] = 1; - if (dbFetchCell('SELECT COUNT(*) from `bgpPeers_cbgp` WHERE device_id = ? AND bgpPeerIdentifier = ?, AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)) == 0) { - dbInsert(array('device_id' => $device['device_id'], 'bgpPeerIdentifier' => $peer['ip'], 'afi' => $afi, 'safi' => $safi), 'bgpPeers_cbgp'); - } - } - } - - $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."'"; - foreach (dbFetchRows($af_query) as $entry) { - $afi = $entry['afi']; - $safi = $entry['safi']; - if (!$af_list[$afi][$safi] || !$af_list[$entry['bgpPeerIdentifier']][$afi][$safi]) { - dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); - } } } + + unset($j_afisafi); + unset($j_prefixes); + unset($j_bgp); + unset($j_peerIndexes); } - unset($j_afisafi); - unset($j_prefixes); - unset($j_bgp); - unset($j_peerIndexes); - } + // Delete removed peers + $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."' AND `context_name` = '" . $device['context_name'] . "'"; - // Delete removed peers - $sql = "SELECT * FROM bgpPeers AS B, devices AS D WHERE B.device_id = D.device_id AND D.device_id = '".$device['device_id']."'"; + foreach (dbFetchRows($sql) as $entry) { + unset($exists); + $i = 0; - foreach (dbFetchRows($sql) as $entry) { - unset($exists); - $i = 0; + while ($i < count($peerlist) && !isset($exists)) { + if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { + $exists = 1; + } - while ($i < count($peerlist) && !isset($exists)) { - if ($peerlist[$i]['ip'] == $entry['bgpPeerIdentifier']) { - $exists = 1; + $i++; } - $i++; + if (!isset($exists)) { + dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); + echo '-'; + } } - if (!isset($exists)) { - dbDelete('bgpPeers', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - dbDelete('bgpPeers_cbgp', '`bgpPeer_id` = ?', array($entry['bgpPeer_id'])); - echo '-'; - } + unset($peerlist); + + echo "\n"; + unset($device['context_name']); } - - unset($peerlist); - - echo "\n"; + unset($device['context_name']); + unset($vrfs_c); } diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php new file mode 100644 index 000000000..ae2aff0e4 --- /dev/null +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -0,0 +1,142 @@ + and Mathieu Millet +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . */ + + +global $debug; + +// This one only will work with the CISCO-CONTEXT-MAPPING-MIB V2 of cisco +if ($config['enable_vrf_lite_cisco']) { + + $ids = array(); + + // For the moment only will be cisco and the version 3 + if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') { + + echo ("VRF lite cisco : \n"); + $mib = "SNMP-COMMUNITY-MIB"; + + $mib = "CISCO-CONTEXT-MAPPING-MIB"; + //-Osq because if i put the n the oid from the first command is not the same of this one + $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); + $listVrf = str_replace("cContextMappingVrfName.", "", $listVrf); + $listVrf = str_replace('"', "", $listVrf); + $listVrf = trim($listVrf); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); + } + + $tableVrf; + foreach (explode("\n", $listVrf) as $lineVrf) { + $tmpVrf = explode(" ", $lineVrf, 2); + //the $tmpVrf[0] will be the context + if (count($tmpVrf) == 2 && !empty($tmpVrf[1])) { + $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1]; + } + } + + unset($listVrf); + + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); + $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); + $listIntance = str_replace('"', "", $listIntance); + $listIntance = trim($listIntance); + + if ($debug) { + echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + } + + + foreach (explode("\n", $listIntance) as $lineIntance) { + $tmpIntance = explode(" ", $lineIntance, 2); + //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance + if (count($tmpIntance) == 2 && !empty($tmpIntance[1])) { + $tableVrf[$tmpIntance[0]]['intance_name'] = $tmpIntance[1]; + } + } + unset($listIntance); + + + foreach ($tableVrf as $context => $vrf) { + + + + if ($debug) { + + echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n"); + } + + $tmpVrf = dbFetchRow("SELECT * FROM vrf_lite_cisco WHERE device_id = ? and context_name=?", array( + $device ['device_id'], + $context + )); + if (!empty($tmpVrf)) { + + $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id']; + + $vrfUpdate=array(); + + foreach ($vrfUpdate as $key => $value) { + if($vrf[$key]!=$value){ + $vrfUpdate[$key]=$value; + } + } + if (!empty($vrfUpdate)) { + dbUpdate($vrfUpdate, 'vrf_lite_cisco', 'vrf_lite_cisco_id=?', array( + $tmp['vrf_lite_cisco_id'] + )); + } + } else { + + $id = dbInsert(array( + 'device_id' => $device ['device_id'], + 'context_name' => $context, + 'intance_name' => $vrf['intance_name'], + 'vrf_name' => $vrf['vrf_name'] + ), 'vrf_lite_cisco'); + + $ids[$id] = $id; + } + } + + unset($tableVrf); + } + + //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work + $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( + $device ['device_id'])); + + $device['vrf_lite_cisco'] = $tmpVrfC; + + //Delete all vrf that chaged + foreach ($tmpVrfC as $vrfC) { + unset($ids[$vrfC['vrf_lite_cisco_id']]); + } + if (!empty($ids)) { + foreach ($ids as $id) { + + dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array( + $id)); + } + } + + + unset($ids); + unset($tmpVrfC); +} // enable_vrf_lite_cisco +?> diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index b03ac9048..e8055e63c 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -669,8 +669,8 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity }//end discover_toner() - -function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin) { + +function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name='') { global $device,$config; $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen").'/'.$ipv6_prefixlen; @@ -683,21 +683,21 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $ipv6_prefixlen > '0' && $ipv6_prefixlen < '129' && $ipv6_compressed != '::1') { $port_id = dbFetchCell('SELECT port_id FROM `ports` WHERE device_id = ? AND ifIndex = ?', array($device['device_id'], $ifIndex)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } // Below looks like a duplicate of the above FIXME - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { - dbInsert(array('ipv6_network' => $ipv6_network), 'ipv6_networks'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; } - $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)); + $ipv6_network_id = dbFetchCell('SELECT `ipv6_network_id` FROM `ipv6_networks` WHERE `ipv6_network` = ? AND `context_name` = ?', array($ipv6_network, $context_name)); - if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { - dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id), 'ipv6_addresses'); + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ? AND `context_name` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)) == '0') { + dbInsert(array('ipv6_address' => $ipv6_address, 'ipv6_compressed' => $ipv6_compressed, 'ipv6_prefixlen' => $ipv6_prefixlen, 'ipv6_origin' => $ipv6_origin, 'ipv6_network_id' => $ipv6_network_id, 'port_id' => $port_id, 'context_name' => $context_name), 'ipv6_addresses'); echo '+'; } else { diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 53cf3ad57..26fc9ba28 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ network.'/'.$addr->bitmask; - $cidr = $addr->bitmask; - - if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { - $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') { - dbInsert(array('ipv4_network' => $network), 'ipv4_networks'); - // echo("Create Subnet $network\n"); - echo 'S'; - } - - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); - - if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?', array($oid, $cidr, $port_id)) == '0') { - dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id), 'ipv4_addresses'); - // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); - echo '+'; - } - else { - echo '.'; - } - - $full_address = "$oid/$cidr|$ifIndex"; - $valid_v4[$full_address] = 1; - } - else { - echo '!'; - }//end if -}//end foreach - -$sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; - - if (!$valid_v4[$full_address]) { - echo '-'; - $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { - $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); - } - } +if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + $vrfs_lite_cisco = $device['vrf_lite_cisco']; } +else{ + $vrfs_lite_cisco = array(array('context_name'=>null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -echo "\n"; + $oids = trim(snmp_walk($device, 'ipAdEntIfIndex', '-Osq', 'IP-MIB')); + $oids = str_replace('ipAdEntIfIndex.', '', $oids); + foreach (explode("\n", $oids) as $data) { + $data = trim($data); + list($oid,$ifIndex) = explode(' ', $data); + $mask = trim(snmp_get($device, "ipAdEntNetMask.$oid", '-Oqv', 'IP-MIB')); + $addr = Net_IPv4::parseAddress("$oid/$mask"); + $network = $addr->network.'/'.$addr->bitmask; + $cidr = $addr->bitmask; -unset($valid_v4); + if (dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE device_id = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)) != '0' && $oid != '0.0.0.0' && $oid != 'ipAdEntIfIndex') { + $port_id = dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ifIndex)); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name` = ?', array($network, $device['context_name'])) < '1') { + dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks'); + // echo("Create Subnet $network\n"); + echo 'S'; + } + + $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name`= ?', array($network, $device['context_name'])); + + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ? and `context_name`=?', array($oid, $cidr, $port_id, $device['context_name'])) == '0') { + dbInsert(array('ipv4_address' => $oid, 'ipv4_prefixlen' => $cidr, 'ipv4_network_id' => $ipv4_network_id, 'port_id' => $port_id,'context_name' => $device['context_name']), 'ipv4_addresses'); + // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); + echo '+'; + } + else { + echo '.'; + } + + $full_address = "$oid/$cidr|$ifIndex"; + $valid_v4[$full_address] = 1; + } + else { + echo '!'; + }//end if + }//end foreach + + $sql = "SELECT * FROM ipv4_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND a.context_name= '" . $device['context_name'] . "'"; + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv4_address'].'/'.$row['ipv4_prefixlen'].'|'.$row['ifIndex']; + + if (!$valid_v4[$full_address]) { + echo '-'; + $query = dbDelete('ipv4_addresses', '`ipv4_address_id` = ?', array($row['ipv4_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv4_addresses` WHERE `ipv4_network_id` = ?', array($row['ipv4_network_id']))) { + $query = dbDelete('ipv4_networks', '`ipv4_network_id` = ?', array($row['ipv4_network_id'])); + } + } + } + + echo "\n"; + unset($device['context_name']); + unset($valid_v4); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index 562428b6b..f7762ee98 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -1,78 +1,89 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); -$oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); -$oids = str_replace('"', '', $oids); -$oids = str_replace('IP-MIB::', '', $oids); -$oids = trim($oids); - -foreach (explode("\n", $oids) as $data) { - if ($data) { - $data = trim($data); - list($ipv6addr,$ifIndex) = explode(' ', $data); - $oid = ''; - $sep = ''; - $adsep = ''; - unset($ipv6_address); - $do = '0'; - foreach (explode(':', $ipv6addr) as $part) { - $n = hexdec($part); - $oid = "$oid"."$sep"."$n"; - $sep = '.'; - $ipv6_address = $ipv6_address."$adsep".$part; - $do++; - if ($do == 2) { - $adsep = ':'; - $do = '0'; - } - else { - $adsep = ''; - } - } - - $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); - $ipv6_prefixlen = explode('.', $ipv6_prefixlen); - $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); - - $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); - - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); - } //end if -} //end foreach - -if (!$oids) { - $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); - $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = snmp_walk($device, 'ipAddressIfIndex.ipv6', '-Ln -Osq', 'IP-MIB'); + $oids = str_replace('ipAddressIfIndex.ipv6.', '', $oids); $oids = str_replace('"', '', $oids); + $oids = str_replace('IP-MIB::', '', $oids); $oids = trim($oids); foreach (explode("\n", $oids) as $data) { if ($data) { - $data = trim($data); - list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); - list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); - $ipv6_address = snmp2ipv6($ipv6addr); - $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); - discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin); + $data = trim($data); + list($ipv6addr,$ifIndex) = explode(' ', $data); + $oid = ''; + $sep = ''; + $adsep = ''; + unset($ipv6_address); + $do = '0'; + foreach (explode(':', $ipv6addr) as $part) { + $n = hexdec($part); + $oid = "$oid"."$sep"."$n"; + $sep = '.'; + $ipv6_address = $ipv6_address."$adsep".$part; + $do++; + if ($do == 2) { + $adsep = ':'; + $do = '0'; + } + else { + $adsep = ''; + } + } + + $ipv6_prefixlen = snmp_get($device, ".1.3.6.1.2.1.4.34.1.5.2.16.$oid", '', 'IP-MIB'); + $ipv6_prefixlen = explode('.', $ipv6_prefixlen); + $ipv6_prefixlen = str_replace('"', '', end($ipv6_prefixlen)); + + $ipv6_origin = snmp_get($device, ".1.3.6.1.2.1.4.34.1.6.2.16.$oid", '-Ovq', 'IP-MIB'); + + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); } //end if } //end foreach -} //end if -$sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id"; + if (!$oids) { + $oids = snmp_walk($device, 'ipv6AddrPfxLength', '-Ln -Osq -OnU', 'IPV6-MIB'); + $oids = str_replace('.1.3.6.1.2.1.55.1.8.1.2.', '', $oids); + $oids = str_replace('"', '', $oids); + $oids = trim($oids); -foreach (dbFetchRows($sql) as $row) { - $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; - $port_id = $row['port_id']; - $valid_address = $full_address.'-'.$port_id; - if (!$valid['ipv6'][$valid_address]) { - echo '-'; - $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); - if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { - $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + foreach (explode("\n", $oids) as $data) { + if ($data) { + $data = trim($data); + list($if_ipv6addr,$ipv6_prefixlen) = explode(' ', $data); + list($ifIndex,$ipv6addr) = explode('.', $if_ipv6addr, 2); + $ipv6_address = snmp2ipv6($ipv6addr); + $ipv6_origin = snmp_get($device, "IPV6-MIB::ipv6AddrType.$if_ipv6addr", '-Ovq', 'IPV6-MIB'); + discover_process_ipv6($valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $device['context_name']); + } //end if + } //end foreach + } //end if + + $sql = "SELECT * FROM ipv6_addresses AS A, ports AS I WHERE I.device_id = '".$device['device_id']."' AND A.port_id = I.port_id AND A.context_name= '" . $device['context_name'] . "'"; + + foreach (dbFetchRows($sql) as $row) { + $full_address = $row['ipv6_address'].'/'.$row['ipv6_prefixlen']; + $port_id = $row['port_id']; + $valid_address = $full_address.'-'.$port_id; + if (!$valid['ipv6'][$valid_address]) { + echo '-'; + $query = dbDelete('ipv6_addresses', '`ipv6_address_id` = ?', array($row['ipv6_address_id'])); + if (!dbFetchCell('SELECT COUNT(*) FROM `ipv6_addresses` WHERE `ipv6_network_id` = ?', array($row['ipv6_network_id']))) { + $query = dbDelete('ipv6_networks', '`ipv6_network_id` = ?', array($row['ipv6_network_id'])); + } } } -} -echo "\n"; + echo "\n"; + unset($device['context_name']); +} +unset($vrfs_c); \ No newline at end of file diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index 56863ec10..40ff425a0 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -2,6 +2,9 @@ if ($config['enable_bgp']) { foreach (dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])) as $peer) { + //add context if exist + $device['context_name']= $peer['context_name']; + // Poll BGP Peer $peer2 = false; echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' '; @@ -62,14 +65,28 @@ if ($config['enable_bgp']) { } } else { - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; - $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; - $peer_data = trim(`$peer_cmd`); + // $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; + $oids = "bgpPeerState." . $peer['bgpPeerIdentifier'] . " bgpPeerAdminStatus." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerOutUpdates." . $peer['bgpPeerIdentifier'] . " bgpPeerInTotalMessages." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerOutTotalMessages." . $peer['bgpPeerIdentifier'] . " bgpPeerFsmEstablishedTime." . $peer['bgpPeerIdentifier'] . " bgpPeerInUpdateElapsedTime." . $peer['bgpPeerIdentifier'] . " "; + $oids .= "bgpPeerLocalAddr." . $peer['bgpPeerIdentifier'] . ""; + $peer_data=snmp_get_multi($device,$oids,'-OUQs','BGP4-MIB'); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } }//end if - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + //list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + unset($peer_data); } else if ($device['os'] == 'junos') { // v6 for JunOS via Juniper MIB @@ -78,9 +95,9 @@ if ($config['enable_bgp']) { if (!isset($junos_v6)) { echo "\nCaching Oids..."; // FIXME - needs moved to function - $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; - foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { + //$peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + + foreach (explode("\n",snmp_get($device,'jnxBgpM2PeerStatus.0.ipv6"','-OUnq','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos")) as $oid){ list($peer_oid) = explode(' ', $oid); $peer_id = explode('.', $peer_oid); $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); @@ -88,25 +105,34 @@ if ($config['enable_bgp']) { } // FIXME - move to function (and clean up, wtf?) - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); - $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; - $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; - // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? - $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= '|grep -v "No Such Instance"'; - d_echo("\n$peer_cmd\n"); - - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + + $oids = " jnxBgpM2PeerState.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerStatus.0.ipv6." . $junos_v6[$peer_ip]; # Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? + $oids .= " jnxBgpM2PeerInUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutUpdates.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerOutTotalMessages.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerFsmEstablishedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6." . $junos_v6[$peer_ip]; + $oids .= " jnxBgpM2PeerLocalAddr.0.ipv6." . $junos_v6[$peer_ip]; + //$peer_cmd .= '|grep -v "No Such Instance"'; WHAT TO DO WITH THIS??,USE TO SEE -Ln?? + $peer_data=snmp_get_multi($device,$oids,'-OUQs -Ln','BGP4-V2-MIB-JUNIPER',$config['mibdir'] . "/junos"); + $peer_data= array_pop($peer_data); + if($debug){ + var_dump($peer_data); + } + $bgpPeerState= !empty($peer_data['bgpPeerState'])?$peer_data['bgpPeerState']:''; + $bgpPeerAdminStatus= !empty($peer_data['bgpPeerAdminStatus'])?$peer_data['bgpPeerAdminStatus']:''; + $bgpPeerInUpdates= !empty($peer_data['bgpPeerInUpdates'])?$peer_data['bgpPeerInUpdates']:''; + $bgpPeerOutUpdates= !empty($peer_data['bgpPeerOutUpdates'])?$peer_data['bgpPeerOutUpdates']:''; + $bgpPeerInTotalMessages= !empty($peer_data['bgpPeerInTotalMessages'])?$peer_data['bgpPeerInTotalMessages']:''; + $bgpPeerOutTotalMessages= !empty($peer_data['bgpPeerOutTotalMessages'])?$peer_data['bgpPeerOutTotalMessages']:''; + $bgpPeerFsmEstablishedTime= !empty($peer_data['bgpPeerFsmEstablishedTime'])?$peer_data['bgpPeerFsmEstablishedTime']:''; + $bgpPeerInUpdateElapsedTime= !empty($peer_data['bgpPeerInUpdateElapsedTime'])?$peer_data['bgpPeerInUpdateElapsedTime']:''; + $bgpLocalAddr= !empty($peer_data['bgpPeerLocalAddr'])?$peer_data['bgpPeerLocalAddr']:''; + unset($peer_data); + d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); @@ -235,23 +261,37 @@ if ($config['enable_bgp']) { } else { // FIXME - move to function - $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - - d_echo("$cbgp_cmd\n"); - - $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); - $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); + + + $oids = " cbgpPeerAcceptedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerDeniedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixAdminLimit." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerPrefixClearThreshold." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerAdvertisedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerSuppressedPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + $oids .= " cbgpPeerWithdrawnPrefixes." . $peer['bgpPeerIdentifier'] . ".$afi.$safi"; + + d_echo("$oids\n"); + + $cbgp_data= snmp_get_multi($device,$oids,'-OUQs ','CISCO-BGP4-MIB'); + $cbgp_data= array_pop($cbgp_data); + d_echo("$cbgp_data\n"); + + }//end if - list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + + $cbgpPeerAcceptedPrefixes= !empty($cbgp_data['cbgpPeerAcceptedPrefixes'])?$cbgp_data['cbgpPeerAcceptedPrefixes']:''; + $cbgpPeerDeniedPrefixes= !empty($cbgp_data['cbgpPeerDeniedPrefixes'])?$cbgp_data['cbgpPeerDeniedPrefixes']:''; + $cbgpPeerPrefixAdminLimit= !empty($cbgp_data['cbgpPeerPrefixAdminLimit'])?$cbgp_data['cbgpPeerPrefixAdminLimit']:''; + $cbgpPeerPrefixThreshold= !empty($cbgp_data['cbgpPeerPrefixThreshold'])?$cbgp_data['cbgpPeerPrefixThreshold']:''; + $cbgpPeerPrefixClearThreshold= !empty($cbgp_data['cbgpPeerPrefixClearThreshold'])?$cbgp_data['cbgpPeerPrefixClearThreshold']:''; + $cbgpPeerAdvertisedPrefixes= !empty($cbgp_data['cbgpPeerAdvertisedPrefixes'])?$cbgp_data['cbgpPeerAdvertisedPrefixes']:''; + $cbgpPeerSuppressedPrefixes= !empty($cbgp_data['cbgpPeerSuppressedPrefixes'])?$cbgp_data['cbgpPeerSuppressedPrefixes']:''; + $cbgpPeerWithdrawnPrefixes= !empty($cbgp_data['cbgpPeerWithdrawnPrefixes'])?$cbgp_data['cbgpPeerWithdrawnPrefixes']:''; + + unset($cbgp_data); }//end if if ($device['os'] == 'junos') { @@ -331,5 +371,6 @@ if ($config['enable_bgp']) { } //end foreach } //end if echo "\n"; + unset($device['context_name']); } //end foreach } //end if diff --git a/includes/polling/ospf.inc.php b/includes/polling/ospf.inc.php index 8fec222a2..602255258 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_port_count = 0; $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ $ospf_oids_db = array( 'ospfDemandExtensions', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; -} - -// Pull data from device -$ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); -foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_instances_db[$ospf_instance_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id), 'ospf_instances'); - echo '+'; - $ospf_instances_db[$entry['ospf_instance_id']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - $ospf_instances_db[$entry['ospf_instance_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_instances_poll); - echo 'Database: '; - print_r($ospf_instances_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_instances_db)) { - foreach ($ospf_instances_db as $ospf_instance_db) { - $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_db['ospf_instance_id']]; - foreach ($ospf_oids_db as $oid) { - // Loop the OIDs - if ($ospf_instance_db[$oid] != $ospf_instance_poll[$oid]) { - // If data has changed, build a query - $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_instance_update) { - dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ?', array($device['device_id'], $ospf_instance_id)); - echo 'U'; - unset($ospf_instance_update); - } - else { - echo '.'; - } - - unset($ospf_instance_poll); - unset($ospf_instance_db); - $ospf_instance_count++; - }//end foreach -}//end if - -unset($ospf_instances_poll); -unset($ospf_instances_db); - -echo ' Areas: '; - $ospf_area_oids = array( 'ospfAuthType', 'ospfImportAsExtern', @@ -95,72 +38,6 @@ $ospf_area_oids = array( 'ospfAreaStatus', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_areas_db[$entry['ospfAreaId']] = $entry; -} - -// Pull data from device -$ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_areas_db[$ospf_area_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id), 'ospf_areas'); - echo '+'; - $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - $ospf_areas_db[$entry['ospf_area_id']] = $entry; - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_areas_poll); - echo 'Database: '; - print_r($ospf_areas_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_areas_db)) { - foreach ($ospf_areas_db as $ospf_area_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_area_poll = $ospf_areas_poll[$ospf_area_db['ospfAreaId']]; - foreach ($ospf_area_oids as $oid) { - // Loop the OIDs - if ($ospf_area_db[$oid] != $ospf_area_poll[$oid]) { - // If data has changed, build a query - $ospf_area_update[$oid] = $ospf_area_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME - } - } - - if ($ospf_area_update) { - dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_id)); - echo 'U'; - unset($ospf_area_update); - } - else { - echo '.'; - } - - unset($ospf_area_poll); - unset($ospf_area_db); - $ospf_area_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'])); - }//end if - }//end foreach -}//end if - -unset($ospf_areas_db); -unset($ospf_areas_poll); - -// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); -// print_r($ospf_ports); -echo ' Ports: '; - $ospf_port_oids = array( 'ospfIfIpAddress', 'port_id', @@ -171,7 +48,7 @@ $ospf_port_oids = array( 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,87 +62,6 @@ $ospf_port_oids = array( 'ospfIfAuthType', ); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ?', array($device['device_id'])) as $entry) { - $ospf_ports_db[$entry['ospf_port_id']] = $entry; -} - -// Pull data from device -$ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); - -foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_ports_db[$ospf_port_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id), 'ospf_ports'); - echo '+'; - $ospf_ports_db[$entry['ospf_port_id']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - } -} - -if ($debug) { - echo "\nPolled: "; - print_r($ospf_ports_poll); - echo 'Database: '; - print_r($ospf_ports_db); - echo "\n"; -} - -// Loop array of entries and update -if (is_array($ospf_ports_db)) { - foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { - if (is_array($ospf_ports_poll[$ospf_port_db['ospf_port_id']])) { - $ospf_port_poll = $ospf_ports_poll[$ospf_port_db['ospf_port_id']]; - - if ($ospf_port_poll['ospfAddressLessIf']) { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); - } - else { - $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'])); - } - - foreach ($ospf_port_oids as $oid) { - // Loop the OIDs - if ($ospf_port_db[$oid] != $ospf_port_poll[$oid]) { - // If data has changed, build a query - $ospf_port_update[$oid] = $ospf_port_poll[$oid]; - // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME - } - } - - if ($ospf_port_update) { - dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_id)); - echo 'U'; - unset($ospf_port_update); - } - else { - echo '.'; - } - - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; - } - else { - dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'])); - // "DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); - echo '-'; - }//end if - }//end foreach -}//end if - -// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 -// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 -// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 -// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 -// OSPF-MIB::ospfNbrState.172.22.203.98.0 full -// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 -// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 -// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active -// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic -// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false -echo ' Neighbours: '; - $ospf_nbr_oids_db = array( 'ospfNbrIpAddr', 'ospfNbrAddressLessIndex', @@ -279,83 +75,313 @@ $ospf_nbr_oids_db = array( 'ospfNbmaNbrPermanence', 'ospfNbrHelloSuppressed', ); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); -// Build array of existing entries -foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ?', array($device['device_id'])) as $nbr_entry) { - $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']] = $nbr_entry; + + +if (key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco']) != 0)) { + $vrfs_lite_cisco = $device['vrf_lite_cisco']; +} else { + $vrfs_lite_cisco = array(array('context_name' => null)); } -// Pull data from device -$ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { - // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array - if (!isset($ospf_nbrs_db[$ospf_nbr_id])) { - dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id), 'ospf_nbrs'); - echo '+'; - $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - $ospf_nbrs_db[$entry['ospf_nbr_id']] = $entry; + $device['context_name'] = $vrf_lite['context_name']; + + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; } -} -if ($debug) { - echo "\nPolled: "; - print_r($ospf_nbrs_poll); - echo 'Database: '; - print_r($ospf_nbrs_db); - echo "\n"; -} + // Pull data from device + $ospf_instances_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfGeneralGroup', array(), 'OSPF-MIB'); + foreach ($ospf_instances_poll as $ospf_instance_id => $ospf_entry) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (empty($ospf_instances_db[$ospf_instance_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_instance_id' => $ospf_instance_id, 'context_name' => $device['context_name']), 'ospf_instances'); + echo '+'; + $ospf_instances_db[$entry['ospf_instance_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_instances` WHERE `device_id` = ? AND `ospf_instance_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + $ospf_instances_db[$entry['ospf_instance_id']][$entry['context_name']] = $entry; + } + } -// Loop array of entries and update -if (is_array($ospf_nbrs_db)) { - foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { - if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { - $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + if ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'])); + // Loop array of entries and update + if (is_array($ospf_instances_db)) { + foreach ($ospf_instances_db as $ospf_instance_id => $ospf_instance_db) { + if (is_array($ospf_instances_poll[$ospf_instance_id])) { + $ospf_instance_poll = $ospf_instances_poll[$ospf_instance_id]; + foreach ($ospf_oids_db as $oid) { + // Loop the OIDs + if ($ospf_instance_db[$device['context_name']][$oid] != $ospf_instance_poll[$oid]) { + // If data has changed, build a query + $ospf_instance_update[$oid] = $ospf_instance_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } - if ($ospf_nbr_db['port_id'] != $ospf_nbr_poll['port_id']) { - if ($ospf_nbr_poll['port_id']) { - $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + if ($ospf_instance_update) { + dbUpdate($ospf_instance_update, 'ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=?', array($device['device_id'], $ospf_instance_id, $device['context_name'])); + echo 'U'; + unset($ospf_instance_update); } else { - $ospf_nbr_update = array('port_id' => array('NULL')); + echo '.'; } + + unset($ospf_instance_poll); + unset($ospf_instance_db); + $ospf_instance_count++; + } else { + dbDelete('ospf_instances', '`device_id` = ? AND `ospf_instance_id` = ? AND `context_name`=? ', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); } + }//end foreach + }//end if + unset($ospf_instances_poll); + unset($ospf_instances_db); - foreach ($ospf_nbr_oids as $oid) { - // Loop the OIDs - d_echo($ospf_nbr_db[$oid].'|'.$ospf_nbr_poll[$oid]."\n"); - if ($ospf_nbr_db[$oid] != $ospf_nbr_poll[$oid]) { - // If data has changed, build a query - $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; - // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + + echo ' Areas: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `context_name`=?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_areas_db[$entry['ospfAreaId']][$entry['context_name']] = $entry; + } + + // Pull data from device + $ospf_areas_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfAreaEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_areas_poll as $ospf_area_id => $ospf_area) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_areas_db[$ospf_area_id][$entry['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospfAreaId' => $ospf_area_id, 'context_name' => $device['context_name']), 'ospf_areas'); + echo '+'; + $entry = dbFetchRows('SELECT * FROM `ospf_areas` WHERE `device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + $ospf_areas_db[$ospf_area_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_areas_poll); + echo 'Database: '; + print_r($ospf_areas_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_areas_db)) { + foreach ($ospf_areas_db as $$ospf_area_id => $ospf_area_db) { + if (is_array($ospf_areas_poll[$ospf_area_id])) { + $ospf_area_poll = $ospf_areas_poll[$ospf_area_id]; + foreach ($ospf_area_oids as $oid) { + // Loop the OIDs + if ($ospf_area_db[$entry['context_name']][$oid] != $ospf_area_poll[$oid]) { + // If data has changed, build a query + $ospf_area_update[$oid] = $ospf_area_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'interface', $port['port_id']); // FIXME + } } - } - if ($ospf_nbr_update) { - dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_id)); - echo 'U'; - unset($ospf_nbr_update); + if ($ospf_area_update) { + dbUpdate($ospf_area_update, 'ospf_areas', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_id, $device['context_name'])); + echo 'U'; + unset($ospf_area_update); + } + else { + echo '.'; + } + + unset($ospf_area_poll); + unset($ospf_area_db); + $ospf_area_count++; } else { - echo '.'; - } + dbDelete('ospf_ports', '`device_id` = ? AND `ospfAreaId` = ? AND `context_name` = ?', array($device['device_id'], $ospf_area_db['ospfAreaId'], $device['context_name'])); + }//end if + }//end foreach + }//end if - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; + unset($ospf_areas_db); + unset($ospf_areas_poll); + + +// $ospf_ports = snmpwalk_cache_oid($device, "OSPF-MIB::ospfIfEntry", array(), "OSPF-MIB"); +// print_r($ospf_ports); + echo ' Ports: '; + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $entry) { + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = $entry; + } + + // Pull data from device + $ospf_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_ports_poll as $ospf_port_id => $ospf_port) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_ports_db[$ospf_port_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_port_id' => $ospf_port_id, 'context_name' => $device['context_name']), 'ospf_ports'); + echo '+'; + $ospf_ports_db[$entry['ospf_port_id']][$device['context_name']] = dbFetchRow('SELECT * FROM `ospf_ports` WHERE `device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); } - else { - dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'])); - echo '-'; - }//end if - }//end foreach -}//end if + } + if ($debug) { + echo "\nPolled: "; + print_r($ospf_ports_poll); + echo 'Database: '; + print_r($ospf_ports_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_ports_db)) { + foreach ($ospf_ports_db as $ospf_port_id => $ospf_port_db) { + if (is_array($ospf_ports_poll[$ospf_port_id])) { + $ospf_port_poll = $ospf_ports_poll[$ospf_port_id]; + + if ($ospf_port_poll['ospfAddressLessIf']) { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT `port_id` FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $ospf_port_poll['ospfAddressLessIf'])); + } + else { + $ospf_port_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ports AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_port_poll['ospfIfIpAddress'], $device['device_id'], $device['context_name'])); + } + + foreach ($ospf_port_oids as $oid) { + // Loop the OIDs + if ($ospf_port_db[$device['context_name']][$oid] != $ospf_port_poll[$oid]) { + // If data has changed, build a query + $ospf_port_update[$oid] = $ospf_port_poll[$oid]; + // log_event("$oid -> ".$this_port[$oid], $device, 'ospf', $port['port_id']); // FIXME + } + } + + if ($ospf_port_update) { + dbUpdate($ospf_port_update, 'ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_id, $device['context_name'])); + echo 'U'; + unset($ospf_port_update); + } + else { + echo '.'; + } + + unset($ospf_port_poll); + unset($ospf_port_db); + $ospf_port_count++; + } + else { + dbDelete('ospf_ports', '`device_id` = ? AND `ospf_port_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_port_db['ospf_port_id'], $device['context_name'])); + // ("DELETE FROM `ospf_ports` WHERE `device_id` = '".$device['device_id']."' AND `ospf_port_id` = '".$ospf_port_db['ospf_port_id']."'"); + echo '-'; + }//end if + }//end foreach + }//end if + + +// OSPF-MIB::ospfNbrIpAddr.172.22.203.98.0 172.22.203.98 +// OSPF-MIB::ospfNbrAddressLessIndex.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrRtrId.172.22.203.98.0 172.22.203.128 +// OSPF-MIB::ospfNbrOptions.172.22.203.98.0 2 +// OSPF-MIB::ospfNbrPriority.172.22.203.98.0 0 +// OSPF-MIB::ospfNbrState.172.22.203.98.0 full +// OSPF-MIB::ospfNbrEvents.172.22.203.98.0 6 +// OSPF-MIB::ospfNbrLsRetransQLen.172.22.203.98.0 1 +// OSPF-MIB::ospfNbmaNbrStatus.172.22.203.98.0 active +// OSPF-MIB::ospfNbmaNbrPermanence.172.22.203.98.0 dynamic +// OSPF-MIB::ospfNbrHelloSuppressed.172.22.203.98.0 false + echo ' Neighbours: '; + + $ospf_nbr_oids_rrd = array(); + $ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + + // Build array of existing entries + foreach (dbFetchRows('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `context_name` = ?', array($device['device_id'], $device['context_name'])) as $nbr_entry) { + $ospf_nbrs_db[$nbr_entry['ospf_nbr_id']][$device['context_name']] = $nbr_entry; + } + + // Pull data from device + $ospf_nbrs_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfNbrEntry', array(), 'OSPF-MIB'); + + foreach ($ospf_nbrs_poll as $ospf_nbr_id => $ospf_nbr) { + // If the entry doesn't already exist in the prebuilt array, insert into the database and put into the array + if (!isset($ospf_nbrs_db[$ospf_nbr_id][$device['context_name']])) { + dbInsert(array('device_id' => $device['device_id'], 'ospf_nbr_id' => $ospf_nbr_id, 'context_name' => $device['context_name']), 'ospf_nbrs'); + echo '+'; + $entry = dbFetchRow('SELECT * FROM `ospf_nbrs` WHERE `device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id,$device['context_name'])); + $ospf_nbrs_db[$ospf_nbr_id][$device['context_name']] = $entry; + } + } + + if ($debug) { + echo "\nPolled: "; + print_r($ospf_nbrs_poll); + echo 'Database: '; + print_r($ospf_nbrs_db); + echo "\n"; + } + + // Loop array of entries and update + if (is_array($ospf_nbrs_db)) { + foreach ($ospf_nbrs_db as $ospf_nbr_id => $ospf_nbr_db) { + if (is_array($ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']])) { + $ospf_nbr_poll = $ospf_nbrs_poll[$ospf_nbr_db['ospf_nbr_id']]; + + $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, nbrs AS I WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND I.device_id = ? AND A.context_name = ?', array($ospf_nbr_poll['ospfNbrIpAddr'], $device['device_id'], $device['context_name'])); + + if ($ospf_nbr_db[$device['context_name']]['port_id'] != $ospf_nbr_poll['port_id']) { + if (!empty($ospf_nbr_poll['port_id'])) { + $ospf_nbr_update = array('port_id' => $ospf_nbr_poll['port_id']); + } + else { + $ospf_nbr_update = array('port_id' => array('NULL')); + } + } + + foreach ($ospf_nbr_oids as $oid) { + // Loop the OIDs + d_echo($ospf_nbr_db[$device['context_name']][$oid].'|'.$ospf_nbr_poll[$oid]."\n"); + + if ($ospf_nbr_db[$device['context_name']][$oid] != $ospf_nbr_poll[$oid]) { + // If data has changed, build a query + $ospf_nbr_update[$oid] = $ospf_nbr_poll[$oid]; + // log_event("$oid -> ".$this_nbr[$oid], $device, 'ospf', $nbr['port_id']); // FIXME + } + } + + if ($ospf_nbr_update) { + dbUpdate($ospf_nbr_update, 'ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_id, $device['context_name'])); + echo 'U'; + unset($ospf_nbr_update); + } + else { + echo '.'; + } + + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; + } + else { + dbDelete('ospf_nbrs', '`device_id` = ? AND `ospf_nbr_id` = ? AND `context_name` = ?', array($device['device_id'], $ospf_nbr_db['ospf_nbr_id'], $device['context_name'])); + echo '-'; + }//end if + }//end foreach + }//end if + unset($ospf_nbrs_db); + unset($ospf_nbrs_poll); +} +unset($device['context_name']); +unset($vrfs_lite_cisco); // Create device-wide statistics RRD $filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('ospf-statistics.rrd'); diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 3c7abd018..635346a37 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -750,8 +750,14 @@ function snmp_gen_auth(&$device) { $cmd = ''; if ($device['snmpver'] === 'v3') { + $cmd = " -v3 -n '' -l '".$device['authlevel']."'"; - + + //add context if exist context + if(key_exists('context_name', $device)){ + $cmd = " -v3 -n '".$device['context_name']."' -l '".$device['authlevel']."'"; + } + if ($device['authlevel'] === 'noAuthNoPriv') { // We have to provide a username anyway (see Net-SNMP doc) // FIXME: There are two other places this is set - why are they ignored here? From 386ed4bd8d549b957d030c21f4318407b42d7f9d Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 024/104] Adding sql-schema --- sql-schema/097.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-schema/097.sql b/sql-schema/097.sql index d35435553..501e4c583 100644 --- a/sql-schema/097.sql +++ b/sql-schema/097.sql @@ -15,4 +15,4 @@ ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); -ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; From b9f9189b05800da4e8dc532bbf1a5c876c5fce44 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 025/104] Adding sql-schema --- sql-schema/097.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-schema/097.sql b/sql-schema/097.sql index 501e4c583..d35435553 100644 --- a/sql-schema/097.sql +++ b/sql-schema/097.sql @@ -15,4 +15,4 @@ ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); -ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; From 570579110d5d04a0ed8c04676fe7e686b82fd952 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 026/104] Adding sql-schema --- sql-schema/097.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-schema/097.sql b/sql-schema/097.sql index d35435553..501e4c583 100644 --- a/sql-schema/097.sql +++ b/sql-schema/097.sql @@ -15,4 +15,4 @@ ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); -ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; From 21d2b45742be5a437e6fe38b6317dca0096fb585 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Mon, 25 Jan 2016 11:17:06 +0100 Subject: [PATCH 027/104] Syntax update --- includes/defaults.inc.php | 4 +-- includes/discovery/arp-table.inc.php | 5 +-- includes/discovery/bgp-peers.inc.php | 3 +- includes/discovery/cisco-vrf-lite.inc.php | 41 +++++------------------ includes/discovery/ipv4-addresses.inc.php | 4 +-- includes/discovery/ipv6-addresses.inc.php | 2 +- 6 files changed, 18 insertions(+), 41 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index a418f7477..cadc5ae17 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -736,8 +736,8 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; -$config['discovery_modules']['cisco-vrf-lite'] = 1; -// $config['discovery_modules']['cisco-cef'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; +//$config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; $config['discovery_modules']['libvirt-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index c60d4ca95..a04b9db8a 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -7,9 +7,10 @@ echo 'ARP Table : '; if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } -else{ +else { $vrfs_lite_cisco = array(array('context_name'=>null)); } + foreach ($vrfs_lite_cisco as $vrf) { $device['context_name']=$vrf['context_name']; @@ -60,7 +61,7 @@ foreach ($vrfs_lite_cisco as $vrf) { dbUpdate(array('mac_address' => $clean_mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND `context_name`= ?', array($interface['port_id'], $ip, $device['context_name'])); echo '.'; } - else if (isset($interface['port_id'])) { + elseif (isset($interface['port_id'])) { echo '+'; // echo("Add MAC $mac\n"); $insert_data = array( diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index dd341715d..0d82f83ed 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -7,7 +7,7 @@ if ($config['enable_bgp']) { if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } - else{ + else { $vrfs_lite_cisco = array(array('context_name'=>null)); } @@ -237,7 +237,6 @@ if ($config['enable_bgp']) { echo '-'; } } - unset($peerlist); echo "\n"; diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php index ae2aff0e4..b079e618c 100644 --- a/includes/discovery/cisco-vrf-lite.inc.php +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -24,10 +24,8 @@ if ($config['enable_vrf_lite_cisco']) { // For the moment only will be cisco and the version 3 if ($device['os_group'] == "cisco" && $device['snmpver'] == 'v3') { - echo ("VRF lite cisco : \n"); $mib = "SNMP-COMMUNITY-MIB"; - $mib = "CISCO-CONTEXT-MAPPING-MIB"; //-Osq because if i put the n the oid from the first command is not the same of this one $listVrf = snmp_walk($device, "cContextMappingVrfName", "-Osq -Ln", $mib, NULL); @@ -35,10 +33,8 @@ if ($config['enable_vrf_lite_cisco']) { $listVrf = str_replace('"', "", $listVrf); $listVrf = trim($listVrf); - if ($debug) { - echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); - echo ("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); - } + d_echo("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + d_echo("\n[DEBUG List Vrf only name]\n$listVrf\n[/DEBUG]\n"); $tableVrf; foreach (explode("\n", $listVrf) as $lineVrf) { @@ -48,20 +44,16 @@ if ($config['enable_vrf_lite_cisco']) { $tableVrf[$tmpVrf[0]]['vrf_name'] = $tmpVrf[1]; } } - unset($listVrf); - + $listIntance = snmp_walk($device, "cContextMappingProtoInstName", "-Osq -Ln", $mib, NULL); $listIntance = str_replace("cContextMappingProtoInstName.", "", $listIntance); $listIntance = str_replace('"', "", $listIntance); $listIntance = trim($listIntance); - - if ($debug) { - echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); - echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); - } - - + + d_echo ("\n[DEBUG]\nUsing $mib\n[/DEBUG]\n"); + d_echo ("\n[DEBUG]\n List Intance only names\n$listIntance\n[/DEBUG]\n"); + foreach (explode("\n", $listIntance) as $lineIntance) { $tmpIntance = explode(" ", $lineIntance, 2); //the $tmpIntance[0] will be the context and $tmpIntance[1] the intance @@ -70,14 +62,9 @@ if ($config['enable_vrf_lite_cisco']) { } } unset($listIntance); - foreach ($tableVrf as $context => $vrf) { - - - if ($debug) { - echo ("\n[DEBUG]\nRelation:t" . $context . "t" . $vrf['intance'] . "t" . $vrf['vrf'] . "\n[/DEBUG]\n"); } @@ -86,9 +73,7 @@ if ($config['enable_vrf_lite_cisco']) { $context )); if (!empty($tmpVrf)) { - $ids[$tmpVrf['vrf_lite_cisco_id']] = $tmpVrf['vrf_lite_cisco_id']; - $vrfUpdate=array(); foreach ($vrfUpdate as $key => $value) { @@ -102,25 +87,21 @@ if ($config['enable_vrf_lite_cisco']) { )); } } else { - $id = dbInsert(array( 'device_id' => $device ['device_id'], 'context_name' => $context, 'intance_name' => $vrf['intance_name'], 'vrf_name' => $vrf['vrf_name'] ), 'vrf_lite_cisco'); - $ids[$id] = $id; } } - unset($tableVrf); } //get all vrf_lite_cisco, this will used where the value depend of the context, be careful with the order that you call this module, if the module is disabled the context search will not work $tmpVrfC = dbFetchRows("SELECT * FROM vrf_lite_cisco WHERE device_id = ? ", array( $device ['device_id'])); - $device['vrf_lite_cisco'] = $tmpVrfC; //Delete all vrf that chaged @@ -129,14 +110,10 @@ if ($config['enable_vrf_lite_cisco']) { } if (!empty($ids)) { foreach ($ids as $id) { - - dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array( - $id)); + dbDelete('vrf_lite_cisco', 'vrf_lite_cisco_id = ? ', array($id)); } } - - unset($ids); unset($tmpVrfC); } // enable_vrf_lite_cisco -?> + diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 26fc9ba28..f930b8fd3 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,10 +1,10 @@ null)); } foreach ($vrfs_lite_cisco as $vrf) { diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index f7762ee98..fb9864020 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -4,7 +4,7 @@ echo 'IPv6 Addresses : '; if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ $vrfs_lite_cisco = $device['vrf_lite_cisco']; } -else{ +else { $vrfs_lite_cisco = array(array('context_name'=>null)); } foreach ($vrfs_lite_cisco as $vrf) { From 0b3493079aef3e018223fcd4bede592261d12bea Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 028/104] Adding sql-schema --- sql-schema/097.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-schema/097.sql b/sql-schema/097.sql index 501e4c583..d35435553 100644 --- a/sql-schema/097.sql +++ b/sql-schema/097.sql @@ -15,4 +15,4 @@ ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); -ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; From 724ad08d765390a98ae812cf7327786a7e5bdd32 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:13:53 +0100 Subject: [PATCH 029/104] discoverying and polling VRF --- includes/defaults.inc.php | 3 +-- includes/discovery/arp-table.inc.php | 1 - includes/discovery/ipv4-addresses.inc.php | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index cadc5ae17..d7fa2eace 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -722,6 +722,7 @@ $config['discovery_modules']['ports-stack'] = 1; $config['discovery_modules']['entity-physical'] = 1; $config['discovery_modules']['processors'] = 1; $config['discovery_modules']['mempools'] = 1; +$config['discovery_modules']['cisco-vrf-lite'] = 1; $config['discovery_modules']['ipv4-addresses'] = 1; $config['discovery_modules']['ipv6-addresses'] = 1; $config['discovery_modules']['sensors'] = 1; @@ -736,8 +737,6 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; -$config['discovery_modules']['cisco-vrf-lite'] = 1; -//$config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; $config['discovery_modules']['libvirt-vminfo'] = 1; diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index a04b9db8a..94a1d7e2b 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -70,7 +70,6 @@ foreach ($vrfs_lite_cisco as $vrf) { 'ipv4_address' => $ip, 'context_name' => $device['context_name'], ); - dbInsert($insert_data, 'ipv4_mac'); }//end if }//end if diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index f930b8fd3..574bb7874 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -5,6 +5,7 @@ if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!= $vrfs_lite_cisco = $device['vrf_lite_cisco']; } else { + $vrfs_lite_cisco = array(array('context_name'=>null)); } foreach ($vrfs_lite_cisco as $vrf) { From f3ae90fe574050eff4c90aa7232df81a25e52619 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 030/104] Adding sql-schema --- sql-schema/095.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 sql-schema/095.sql diff --git a/sql-schema/095.sql b/sql-schema/095.sql new file mode 100644 index 000000000..61aa90432 --- /dev/null +++ b/sql-schema/095.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); +ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv4_mac ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ipv6_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE bgpPeers_cbgp ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_areas DROP INDEX device_area, ADD UNIQUE KEY `device_area` (`device_id`,`ospfAreaId`,`context_name`); +ALTER TABLE ospf_instances ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_instances DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_instance_id`,`context_name`); +ALTER TABLE ospf_nbrs ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_nbr_id`,`context_name`); +ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; +ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); +ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; + From 990a00904a6f1d52b03be8264bac336bd995d2e0 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 031/104] Adding sql-schema --- sql-schema/095.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/sql-schema/095.sql b/sql-schema/095.sql index 61aa90432..d35435553 100644 --- a/sql-schema/095.sql +++ b/sql-schema/095.sql @@ -16,4 +16,3 @@ ALTER TABLE ospf_nbrs DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`d ALTER TABLE ospf_ports ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ospf_ports DROP INDEX device_id, ADD UNIQUE KEY `device_id` (`device_id`,`ospf_port_id`,`context_name`); ALTER TABLE `vlans` CHANGE COLUMN `vlan_name` `vlan_name` VARCHAR(64) DEFAULT NULL; - From f5fde619284e84e76eda3836225495ed431c5c92 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 032/104] Adding sql-schema --- sql-schema/095.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-schema/095.sql b/sql-schema/095.sql index d35435553..00bef74e3 100644 --- a/sql-schema/095.sql +++ b/sql-schema/095.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS `vrf_lite_cisco` ( `vrf_lite_cisco_id` int(11) NOT NULL AUTO_INCREMENT, `device_id` int(11) NOT NULL, `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci not null ,`intance_name` varchar(128) DEFAULT '', `vrf_name` varchar(128) DEFAULT 'Default', PRIMARY KEY (`vrf_lite_cisco_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC); +ALTER TABLE `vrf_lite_cisco` ADD INDEX `vrf` (`vrf_name` ASC), ADD INDEX `context` (`context_name` ASC), ADD INDEX `device` (`device_id` ASC), ADD INDEX `mix` (`device_id` ASC, `context_name` ASC, `vrf_name` ASC) ; ALTER TABLE ipv4_addresses ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ipv4_networks ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; ALTER TABLE ipv4_mac ADD `context_name` varchar(128) CHARACTER SET utf8 collate utf8_general_ci ; From 08658e34ae6512be35e43d9fcd2c20af0e880c44 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Mon, 25 Jan 2016 11:17:06 +0100 Subject: [PATCH 033/104] Syntax update --- includes/defaults.inc.php | 1 + includes/discovery/ipv4-addresses.inc.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index d7fa2eace..f5b9eaa4d 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -737,6 +737,7 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; +//$config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; $config['discovery_modules']['libvirt-vminfo'] = 1; diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index 574bb7874..f930b8fd3 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -5,7 +5,6 @@ if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!= $vrfs_lite_cisco = $device['vrf_lite_cisco']; } else { - $vrfs_lite_cisco = array(array('context_name'=>null)); } foreach ($vrfs_lite_cisco as $vrf) { From e755edfafc8ecfe35ee2db1b99ab0fca95127556 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Tue, 26 Jan 2016 14:54:24 +0100 Subject: [PATCH 034/104] modify order of cisco-vrf-lite --- includes/defaults.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index f5b9eaa4d..a02588729 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -737,7 +737,7 @@ $config['discovery_modules']['vlans'] = 1; $config['discovery_modules']['cisco-mac-accounting'] = 1; $config['discovery_modules']['cisco-pw'] = 1; $config['discovery_modules']['cisco-vrf'] = 1; -//$config['discovery_modules']['cisco-cef'] = 1; +//$config['discovery_modules']['cisco-cef'] = 1; $config['discovery_modules']['cisco-sla'] = 1; $config['discovery_modules']['vmware-vminfo'] = 1; $config['discovery_modules']['libvirt-vminfo'] = 1; From d96e2216a7137a21f4231ee456b4219458035903 Mon Sep 17 00:00:00 2001 From: Aaron Daniels Date: Thu, 28 Jan 2016 07:04:12 +1000 Subject: [PATCH 035/104] - Changed upper case variables to lower case. --- .../graphs/device/cisco-otv-mac.inc.php | 38 ++-- .../graphs/device/cisco-otv-vlan.inc.php | 38 ++-- html/includes/print-menubar.php | 6 +- html/pages/device.inc.php | 6 +- html/pages/device/routing/cisco-otv.inc.php | 40 ++-- includes/discovery/cisco-otv.inc.php | 205 +++++++++--------- includes/polling/cisco-otv.inc.php | 163 +++++++------- includes/snmp.inc.php | 4 +- 8 files changed, 253 insertions(+), 247 deletions(-) diff --git a/html/includes/graphs/device/cisco-otv-mac.inc.php b/html/includes/graphs/device/cisco-otv-mac.inc.php index 5c616869e..691bfd10d 100644 --- a/html/includes/graphs/device/cisco-otv-mac.inc.php +++ b/html/includes/graphs/device/cisco-otv-mac.inc.php @@ -12,44 +12,44 @@ */ require_once "../includes/component.php"; -$COMPONENT = new component(); +$component = new component(); $options['filter']['type'] = array('=','Cisco-OTV'); -$COMPONENTS = $COMPONENT->getComponents($device['device_id'],$options); +$components = $component->getComponents($device['device_id'],$options); // We only care about our device id. -$COMPONENTS = $COMPONENTS[$device['device_id']]; +$components = $components[$device['device_id']]; include "includes/graphs/common.inc.php"; $rrd_options .= " -l 0 -E "; $rrd_options .= " COMMENT:'MAC Addresses Now Min Max\\n'"; $rrd_additions = ""; -$COUNT = 0; -foreach ($COMPONENTS as $ID => $ARRAY) { - if ($ARRAY['otvtype'] == 'endpoint') { - $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("cisco-otv-".$ARRAY['endpoint']."-mac.rrd"); +$count = 0; +foreach ($components as $id => $array) { + if ($array['otvtype'] == 'endpoint') { + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("cisco-otv-".$array['endpoint']."-mac.rrd"); if (file_exists($rrd_filename)) { // Stack the area on the second and subsequent DS's - $STACK = ""; - if ($COUNT != 0) { - $STACK = ":STACK "; + $stack = ""; + if ($count != 0) { + $stack = ":STACK "; } // Grab a color from the array. - if ( isset($config['graph_colours']['mixed'][$COUNT]) ) { - $COLOR = $config['graph_colours']['mixed'][$COUNT]; + if ( isset($config['graph_colours']['mixed'][$count]) ) { + $color = $config['graph_colours']['mixed'][$count]; } else { - $COLOR = $config['graph_colours']['oranges'][$COUNT-7]; + $color = $config['graph_colours']['oranges'][$count-7]; } - $rrd_additions .= " DEF:DS" . $COUNT . "=" . $rrd_filename . ":count:AVERAGE "; - $rrd_additions .= " AREA:DS" . $COUNT . "#" . $COLOR . ":'" . str_pad(substr($COMPONENTS[$ID]['endpoint'],0,15),15) . "'" . $STACK; - $rrd_additions .= " GPRINT:DS" . $COUNT . ":LAST:%4.0lf%s "; - $rrd_additions .= " GPRINT:DS" . $COUNT . ":MIN:%4.0lf%s "; - $rrd_additions .= " GPRINT:DS" . $COUNT . ":MAX:%4.0lf%s\\\l "; - $COUNT++; + $rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":count:AVERAGE "; + $rrd_additions .= " AREA:DS" . $count . "#" . $color . ":'" . str_pad(substr($components[$id]['endpoint'],0,15),15) . "'" . $stack; + $rrd_additions .= " GPRINT:DS" . $count . ":LAST:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $count . ":MIN:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $count . ":MAX:%4.0lf%s\\\l "; + $count++; } } } diff --git a/html/includes/graphs/device/cisco-otv-vlan.inc.php b/html/includes/graphs/device/cisco-otv-vlan.inc.php index 8ee50acf4..1116e056c 100644 --- a/html/includes/graphs/device/cisco-otv-vlan.inc.php +++ b/html/includes/graphs/device/cisco-otv-vlan.inc.php @@ -12,44 +12,44 @@ */ require_once "../includes/component.php"; -$COMPONENT = new component(); +$component = new component(); $options['filter']['type'] = array('=','Cisco-OTV'); -$COMPONENTS = $COMPONENT->getComponents($device['device_id'],$options); +$components = $component->getComponents($device['device_id'],$options); // We only care about our device id. -$COMPONENTS = $COMPONENTS[$device['device_id']]; +$components = $components[$device['device_id']]; include "includes/graphs/common.inc.php"; $rrd_options .= " -l 0 -E "; $rrd_options .= " COMMENT:'VLANs Now Min Max\\n'"; $rrd_additions = ""; -$COUNT = 0; -foreach ($COMPONENTS as $ID => $ARRAY) { - if ($ARRAY['otvtype'] == 'overlay') { - $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("cisco-otv-".$ARRAY['label']."-vlan.rrd"); +$count = 0; +foreach ($components as $id => $array) { + if ($array['otvtype'] == 'overlay') { + $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("cisco-otv-".$array['label']."-vlan.rrd"); if (file_exists($rrd_filename)) { // Stack the area on the second and subsequent DS's - $STACK = ""; - if ($COUNT != 0) { - $STACK = ":STACK "; + $stack = ""; + if ($count != 0) { + $stack = ":STACK "; } // Grab a color from the array. - if ( isset($config['graph_colours']['mixed'][$COUNT]) ) { - $COLOR = $config['graph_colours']['mixed'][$COUNT]; + if ( isset($config['graph_colours']['mixed'][$count]) ) { + $color = $config['graph_colours']['mixed'][$count]; } else { - $COLOR = $config['graph_colours']['oranges'][$COUNT-7]; + $color = $config['graph_colours']['oranges'][$count-7]; } - $rrd_additions .= " DEF:DS" . $COUNT . "=" . $rrd_filename . ":count:AVERAGE "; - $rrd_additions .= " AREA:DS" . $COUNT . "#" . $COLOR . ":'" . str_pad(substr($COMPONENTS[$ID]['label'],0,15),15) . "'" . $STACK; - $rrd_additions .= " GPRINT:DS" . $COUNT . ":LAST:%4.0lf%s "; - $rrd_additions .= " GPRINT:DS" . $COUNT . ":MIN:%4.0lf%s "; - $rrd_additions .= " GPRINT:DS" . $COUNT . ":MAX:%4.0lf%s\\\l "; - $COUNT++; + $rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":count:AVERAGE "; + $rrd_additions .= " AREA:DS" . $count . "#" . $color . ":'" . str_pad(substr($components[$id]['label'],0,15),15) . "'" . $stack; + $rrd_additions .= " GPRINT:DS" . $count . ":LAST:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $count . ":MIN:%4.0lf%s "; + $rrd_additions .= " GPRINT:DS" . $count . ":MAX:%4.0lf%s\\\l "; + $count++; } } } diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 859af924f..4c22ad08b 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -421,10 +421,10 @@ $routing_count['cef'] = dbFetchCell("SELECT COUNT(cef_switching_id) from `cef_s $routing_count['vrf'] = dbFetchCell("SELECT COUNT(vrf_id) from `vrfs`"); require_once "../includes/component.php"; -$COMPONENT = new component(); +$component = new component(); $options['type'] = 'Cisco-OTV'; -$OTV = $COMPONENT->getComponents(null,$options); -$routing_count['cisco-otv'] = count($OTV); +$otv = $component->getComponents(null,$options); +$routing_count['cisco-otv'] = count($otv); if ($_SESSION['userlevel'] >= '5' && ($routing_count['bgp']+$routing_count['ospf']+$routing_count['cef']+$routing_count['vrf']+$routing_count['cisco-otv']) > "0") { diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 3de92da54..fd5900401 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -211,11 +211,11 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) { } require_once "../includes/component.php"; - $COMPONENT = new component(); + $component = new component(); $options['type'] = 'Cisco-OTV'; $options['filter']['device_id'] = array('=',$device['device_id']); - $OTV = $COMPONENT->getComponents(null,$options); - $device_routing_count['cisco-otv'] = count($OTV); + $otv = $component->getComponents(null,$options); + $device_routing_count['cisco-otv'] = count($otv); if ($device_routing_count['cisco-otv'] > 0) { $routing_tabs[] = 'cisco-otv'; } diff --git a/html/pages/device/routing/cisco-otv.inc.php b/html/pages/device/routing/cisco-otv.inc.php index f29a9c9ae..602f67abd 100644 --- a/html/pages/device/routing/cisco-otv.inc.php +++ b/html/pages/device/routing/cisco-otv.inc.php @@ -1,12 +1,12 @@ getComponents($device['device_id'],$options); -$COMPONENTS = $COMPONENTS[$device['device_id']]; +$components = $component->getComponents($device['device_id'],$options); +$components = $components[$device['device_id']]; global $config; ?> @@ -17,32 +17,32 @@ global $config;
    $OVERLAY) { - if ($OVERLAY['otvtype'] == 'overlay') { - if ($OVERLAY['status'] == 1) { - $OVERLAY_STATUS = "Normal"; - $GLI = ""; +foreach ($components as $oid => $overlay) { + if ($overlay['otvtype'] == 'overlay') { + if ($overlay['status'] == 1) { + $overlay_status = "Normal"; + $gli = ""; } else { - $OVERLAY_STATUS = "".$OVERLAY['error']." - Alert"; - $GLI = "list-group-item-danger"; + $overlay_status = "".$overlay['error']." - Alert"; + $gli = "list-group-item-danger"; } ?> - - -
  • https
  • -
  • ssh
  • -
  • telnet
  • '; - - if ($_SESSION['userlevel'] >= '7') { - echo '
  • + echo ''; echo ''; + }//end if if (device_permitted($device['device_id']) || $check_device == $vars['device']) { From 9cd082044525498d51a20139306b28f3b298ef92 Mon Sep 17 00:00:00 2001 From: Arjit Chaudhary Date: Mon, 8 Feb 2016 22:55:18 +0530 Subject: [PATCH 051/104] use bootstraps own pull-right so that the dropdown draws inside the page width --- html/pages/device.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 2d6b4db36..b7583ed67 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -388,7 +388,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) { } - echo ''; + "; if ($config['distributed_poller'] === true) { echo ' From 1b59ae964868397089577c613c49af4ee714df02 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 9 Feb 2016 08:01:41 -0600 Subject: [PATCH 060/104] Use $config['mibdir'] instead of $config['mib_dir'] --- includes/polling/os/netonix.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/polling/os/netonix.inc.php b/includes/polling/os/netonix.inc.php index 50c1782a8..3b58eb81c 100644 --- a/includes/polling/os/netonix.inc.php +++ b/includes/polling/os/netonix.inc.php @@ -1,3 +1,3 @@ Date: Tue, 9 Feb 2016 18:23:31 +0000 Subject: [PATCH 061/104] Updated bgp-peers polling so that an snmpwalk isn't done for each bgp peer --- includes/polling/bgp-peers.inc.php | 572 +++++++++++++++-------------- 1 file changed, 290 insertions(+), 282 deletions(-) diff --git a/includes/polling/bgp-peers.inc.php b/includes/polling/bgp-peers.inc.php index eb91eb935..9b7c9b5e2 100644 --- a/includes/polling/bgp-peers.inc.php +++ b/includes/polling/bgp-peers.inc.php @@ -1,310 +1,318 @@ 0) { - $peer2 = true; - } + $peers = dbFetchRows('SELECT * FROM bgpPeers WHERE device_id = ?', array($device['device_id'])); - if ($peer2 === true) { - if (strstr($peer['bgpPeerIdentifier'], ':')) { - $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); - } - else { - $bgp_peer_ident = $peer['bgpPeerIdentifier']; + if (!empty($peers)) { + + if ($device['os'] != 'junos') { + $peer_data_check = snmpwalk_cache_oid($device, 'cbgpPeer2RemoteAs', array(), 'CISCO-BGP4-MIB', $config['mibdir']); + } + + foreach ($peers as $peer) { + // Poll BGP Peer + $peer2 = false; + echo 'Checking BGP peer '.$peer['bgpPeerIdentifier'].' '; + + if (!empty($peer['bgpPeerIdentifier'])) { + if (!strstr($peer['bgpPeerIdentifier'], ':') || $device['os'] != 'junos') { + // v4 BGP4 MIB + if (count($peer_data_check) > 0) { + $peer2 = true; } - if (strstr($peer['bgpPeerIdentifier'], ':')) { - $ip_type = 2; - $ip_len = 16; - $ip_ver = 'ipv6'; - } - else { - $ip_type = 1; - $ip_len = 4; - $ip_ver = 'ipv4'; - } - - $peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident; - $peer_data_tmp = snmp_get_multi( - $device, - ' cbgpPeer2State.'.$peer_identifier.' cbgpPeer2AdminStatus.'.$peer_identifier.' cbgpPeer2InUpdates.'.$peer_identifier.' cbgpPeer2OutUpdates.'.$peer_identifier.' cbgpPeer2InTotalMessages.'.$peer_identifier.' cbgpPeer2OutTotalMessages.'.$peer_identifier.' cbgpPeer2FsmEstablishedTime.'.$peer_identifier.' cbgpPeer2InUpdateElapsedTime.'.$peer_identifier.' cbgpPeer2LocalAddr.'.$peer_identifier, - '-OQUs', - 'CISCO-BGP4-MIB', - $config['mibdir'] - ); - $ident = "$ip_ver.\"".$bgp_peer_ident.'"'; - unset($peer_data); - $ident_key = array_keys($peer_data_tmp); - foreach ($peer_data_tmp[$ident_key[0]] as $k => $v) { - if (strstr($k, 'cbgpPeer2LocalAddr')) { - if ($ip_ver == 'ipv6') { - $v = str_replace('"', '', $v); - $v = rtrim($v); - $v = preg_replace('/(\S+\s+\S+)\s/', '$1:', $v); - $v = strtolower($v); - } - else { - $v = hex_to_ip($v); - } + if ($peer2 === true) { + if (strstr($peer['bgpPeerIdentifier'], ':')) { + $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); + } + else { + $bgp_peer_ident = $peer['bgpPeerIdentifier']; } - $peer_data .= "$v\n"; - } - } - else { - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; - $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; - $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; - $peer_data = trim(`$peer_cmd`); - }//end if - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); - $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); - } - else if ($device['os'] == 'junos') { - // v6 for JunOS via Juniper MIB - $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); + if (strstr($peer['bgpPeerIdentifier'], ':')) { + $ip_type = 2; + $ip_len = 16; + $ip_ver = 'ipv6'; + } + else { + $ip_type = 1; + $ip_len = 4; + $ip_ver = 'ipv4'; + } - if (!isset($junos_v6)) { - echo "\nCaching Oids..."; - // FIXME - needs moved to function - $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; - foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { - list($peer_oid) = explode(' ', $oid); - $peer_id = explode('.', $peer_oid); - $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); - } - } - - // FIXME - move to function (and clean up, wtf?) - $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); - $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; - $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; - $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; - // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? - $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; - $peer_cmd .= '|grep -v "No Such Instance"'; - d_echo("\n$peer_cmd\n"); - - $peer_data = trim(`$peer_cmd`); - list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); - - d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); - - $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); - if ($bgpLocalAddr == '00000000000000000000000000000000') { - $bgpLocalAddr = ''; - // Unknown? - } - else { - $bgpLocalAddr = strtolower($bgpLocalAddr); - for ($i = 0; $i < 32; $i += 4) { - $bgpLocalAddr6[] = substr($bgpLocalAddr, $i, 4); - } - - $bgpLocalAddr = Net_IPv6::compress(implode(':', $bgpLocalAddr6)); - unset($bgpLocalAddr6); - } - }//end if - }//end if - - if ($bgpPeerFsmEstablishedTime) { - if (!(is_array($config['alerts']['bgp']['whitelist']) && !in_array($peer['bgpPeerRemoteAs'], $config['alerts']['bgp']['whitelist'])) && ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState'])) { - if ($peer['bgpPeerState'] == $bgpPeerState) { - log_event('BGP Session Flap: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); - } - else if ($bgpPeerState == 'established') { - log_event('BGP Session Up: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); - } - else if ($peer['bgpPeerState'] == 'established') { - log_event('BGP Session Down: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); - } - } - } - - $peerrrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('bgp-'.$peer['bgpPeerIdentifier'].'.rrd'); - if (!is_file($peerrrd)) { - $create_rrd = 'DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 - DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 - DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 - DS:bgpPeerInTotal:COUNTER:600:U:100000000000 - DS:bgpPeerEstablished:GAUGE:600:0:U '.$config['rrd_rra']; - - rrdtool_create($peerrrd, $create_rrd); - } - - $fields = array( - 'bgpPeerOutUpdates' => $bgpPeerOutUpdates, - 'bgpPeerInUpdates' => $bgpPeerInUpdates, - 'bgpPeerOutTotal' => $bgpPeerOutTotalMessages, - 'bgpPeerInTotal' => $bgpPeerInTotalMessages, - 'bgpPeerEstablished' => $bgpPeerFsmEstablishedTime, - ); - rrdtool_update("$peerrrd", $fields); - - $tags = array('bgpPeerIdentifier' => $peer['bgpPeerIdentifier']); - influx_update($device,'bgp',$tags,$fields); - - $peer['update']['bgpPeerState'] = $bgpPeerState; - $peer['update']['bgpPeerAdminStatus'] = $bgpPeerAdminStatus; - $peer['update']['bgpPeerFsmEstablishedTime'] = $bgpPeerFsmEstablishedTime; - $peer['update']['bgpPeerInUpdates'] = $bgpPeerInUpdates; - $peer['update']['bgpLocalAddr'] = $bgpLocalAddr; - $peer['update']['bgpPeerOutUpdates'] = $bgpPeerOutUpdates; - - dbUpdate($peer['update'], 'bgpPeers', '`device_id` = ? AND `bgpPeerIdentifier` = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); - - if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { - // Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) - $peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); - foreach ($peer_afis as $peer_afi) { - $afi = $peer_afi['afi']; - $safi = $peer_afi['safi']; - d_echo("$afi $safi\n"); - - if ($device['os_group'] == 'cisco') { - $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); - if (strstr($peer['bgpPeerIdentifier'], ':')) { - $ip_type = 2; - $ip_len = 16; - $ip_ver = 'ipv6'; - } - else { - $ip_type = 1; - $ip_len = 4; - $ip_ver = 'ipv4'; - } - - $ip_cast = 1; - if ($peer_afi['safi'] == 'multicast') { - $ip_cast = 2; - } - else if ($peer_afi['safi'] == 'unicastAndMulticast') { - $ip_cast = 3; - } - else if ($peer_afi['safi'] == 'vpn') { - $ip_cast = 128; - } - - $check = snmp_get($device, 'cbgpPeer2AcceptedPrefixes.'.$ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast, '', 'CISCO-BGP4-MIB', $config['mibdir']); - - if (!empty($check)) { - $cgp_peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast; - $cbgp_data_tmp = snmp_get_multi( + $peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident; + $peer_data_tmp = snmp_get_multi( $device, - ' cbgpPeer2AcceptedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2DeniedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2PrefixAdminLimit.'.$cgp_peer_identifier.' cbgpPeer2PrefixThreshold.'.$cgp_peer_identifier.' cbgpPeer2PrefixClearThreshold.'.$cgp_peer_identifier.' cbgpPeer2AdvertisedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2SuppressedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2WithdrawnPrefixes.'.$cgp_peer_identifier, + ' cbgpPeer2State.'.$peer_identifier.' cbgpPeer2AdminStatus.'.$peer_identifier.' cbgpPeer2InUpdates.'.$peer_identifier.' cbgpPeer2OutUpdates.'.$peer_identifier.' cbgpPeer2InTotalMessages.'.$peer_identifier.' cbgpPeer2OutTotalMessages.'.$peer_identifier.' cbgpPeer2FsmEstablishedTime.'.$peer_identifier.' cbgpPeer2InUpdateElapsedTime.'.$peer_identifier.' cbgpPeer2LocalAddr.'.$peer_identifier, '-OQUs', 'CISCO-BGP4-MIB', $config['mibdir'] ); - $ident = "$ip_ver.\"".$peer['bgpPeerIdentifier'].'"'.'.'.$ip_type.'.'.$ip_cast; - unset($cbgp_data); - $temp_keys = array_keys($cbgp_data_tmp); - unset($temp_data); - $temp_data['cbgpPeer2AcceptedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AcceptedPrefixes']; - $temp_data['cbgpPeer2DeniedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2DeniedPrefixes']; - $temp_data['cbgpPeer2PrefixAdminLimit'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixAdminLimit']; - $temp_data['cbgpPeer2PrefixThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixThreshold']; - $temp_data['cbgpPeer2PrefixClearThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixClearThreshold']; - $temp_data['cbgpPeer2AdvertisedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AdvertisedPrefixes']; - $temp_data['cbgpPeer2SuppressedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2SuppressedPrefixes']; - $temp_data['cbgpPeer2WithdrawnPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2WithdrawnPrefixes']; - foreach ($temp_data as $k => $v) { - $cbgp_data .= "$v\n"; - } + $ident = "$ip_ver.\"".$bgp_peer_ident.'"'; + unset($peer_data); + $ident_key = array_keys($peer_data_tmp); + foreach ($peer_data_tmp[$ident_key[0]] as $k => $v) { + if (strstr($k, 'cbgpPeer2LocalAddr')) { + if ($ip_ver == 'ipv6') { + $v = str_replace('"', '', $v); + $v = rtrim($v); + $v = preg_replace('/(\S+\s+\S+)\s/', '$1:', $v); + $v = strtolower($v); + } + else { + $v = hex_to_ip($v); + } + } - d_echo("$cbgp_data\n"); + $peer_data .= "$v\n"; + } } else { - // FIXME - move to function - $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; - $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; - - d_echo("$cbgp_cmd\n"); - - $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); - $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); - d_echo("$cbgp_data\n"); + $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m BGP4-MIB -OUvq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port'].' '; + $peer_cmd .= 'bgpPeerState.'.$peer['bgpPeerIdentifier'].' bgpPeerAdminStatus.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerOutUpdates.'.$peer['bgpPeerIdentifier'].' bgpPeerInTotalMessages.'.$peer['bgpPeerIdentifier'].' '; + $peer_cmd .= 'bgpPeerOutTotalMessages.'.$peer['bgpPeerIdentifier'].' bgpPeerFsmEstablishedTime.'.$peer['bgpPeerIdentifier'].' bgpPeerInUpdateElapsedTime.'.$peer['bgpPeerIdentifier'].' '; + $peer_cmd .= 'bgpPeerLocalAddr.'.$peer['bgpPeerIdentifier'].''; + $peer_data = trim(`$peer_cmd`); }//end if - list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + } + else if ($device['os'] == 'junos') { + // v6 for JunOS via Juniper MIB + $peer_ip = ipv62snmp($peer['bgpPeerIdentifier']); + + if (!isset($junos_v6)) { + echo "\nCaching Oids..."; + // FIXME - needs moved to function + $peer_cmd = $config['snmpwalk'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUnq -'.$device['snmpver'].' '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6'; + foreach (explode("\n", trim(`$peer_cmd`)) as $oid) { + list($peer_oid) = explode(' ', $oid); + $peer_id = explode('.', $peer_oid); + $junos_v6[implode('.', array_slice($peer_id, 35))] = implode('.', array_slice($peer_id, 18)); + } + } + + // FIXME - move to function (and clean up, wtf?) + $peer_cmd = $config['snmpget'].' -M '.$config['mibdir'].'/junos -m BGP4-V2-MIB-JUNIPER -OUvq '.snmp_gen_auth($device); + $peer_cmd .= ' -M"'.$config['install_dir'].'/mibs/junos"'; + $peer_cmd .= ' '.$device['hostname'].':'.$device['port']; + $peer_cmd .= ' jnxBgpM2PeerState.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerStatus.0.ipv6.'.$junos_v6[$peer_ip]; + // Should be jnxBgpM2CfgPeerAdminStatus but doesn't seem to be implemented? + $peer_cmd .= ' jnxBgpM2PeerInUpdates.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerOutUpdates.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerInTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerOutTotalMessages.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerFsmEstablishedTime.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerInUpdatesElapsedTime.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= ' jnxBgpM2PeerLocalAddr.0.ipv6.'.$junos_v6[$peer_ip]; + $peer_cmd .= '|grep -v "No Such Instance"'; + d_echo("\n$peer_cmd\n"); + + $peer_data = trim(`$peer_cmd`); + list($bgpPeerState, $bgpPeerAdminStatus, $bgpPeerInUpdates, $bgpPeerOutUpdates, $bgpPeerInTotalMessages, $bgpPeerOutTotalMessages, $bgpPeerFsmEstablishedTime, $bgpPeerInUpdateElapsedTime, $bgpLocalAddr) = explode("\n", $peer_data); + + d_echo("State = $bgpPeerState - AdminStatus: $bgpPeerAdminStatus\n"); + + $bgpLocalAddr = str_replace('"', '', str_replace(' ', '', $bgpLocalAddr)); + if ($bgpLocalAddr == '00000000000000000000000000000000') { + $bgpLocalAddr = ''; + // Unknown? + } + else { + $bgpLocalAddr = strtolower($bgpLocalAddr); + for ($i = 0; $i < 32; $i += 4) { + $bgpLocalAddr6[] = substr($bgpLocalAddr, $i, 4); + } + + $bgpLocalAddr = Net_IPv6::compress(implode(':', $bgpLocalAddr6)); + unset($bgpLocalAddr6); + } }//end if + }//end if - // FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! - $update = 'UPDATE bgpPeers_cbgp SET'; - $peer['c_update']['AcceptedPrefixes'] = $cbgpPeerAcceptedPrefixes; - $peer['c_update']['DeniedPrefixes'] = $cbgpPeerDeniedPrefixes; - $peer['c_update']['PrefixAdminLimit'] = $cbgpPeerAdminLimit; - $peer['c_update']['PrefixThreshold'] = $cbgpPeerPrefixThreshold; - $peer['c_update']['PrefixClearThreshold'] = $cbgpPeerPrefixClearThreshold; - $peer['c_update']['AdvertisedPrefixes'] = $cbgpPeerAdvertisedPrefixes; - $peer['c_update']['SuppressedPrefixes'] = $cbgpPeerSuppressedPrefixes; - $peer['c_update']['WithdrawnPrefixes'] = $cbgpPeerWithdrawnPrefixes; - - - $oids = array( - 'AcceptedPrefixes', - 'DeniedPrefixes', - 'AdvertisedPrefixes', - 'SuppressedPrefixes', - 'WithdrawnPrefixes', - ); - - foreach ($oids as $oid) { - $peer['c_update'][$oid.'_delta'] = $peer['c_update'][$oid] - $peer_afi[$oid]; - $peer['c_update'][$oid.'_prev'] = $peer_afi[$oid]; + if ($bgpPeerFsmEstablishedTime) { + if (!(is_array($config['alerts']['bgp']['whitelist']) && !in_array($peer['bgpPeerRemoteAs'], $config['alerts']['bgp']['whitelist'])) && ($bgpPeerFsmEstablishedTime < $peer['bgpPeerFsmEstablishedTime'] || $bgpPeerState != $peer['bgpPeerState'])) { + if ($peer['bgpPeerState'] == $bgpPeerState) { + log_event('BGP Session Flap: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); + } + else if ($bgpPeerState == 'established') { + log_event('BGP Session Up: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); + } + else if ($peer['bgpPeerState'] == 'established') { + log_event('BGP Session Down: '.$peer['bgpPeerIdentifier'].' (AS'.$peer['bgpPeerRemoteAs'].')', $device, 'bgpPeer', $bgpPeer_id); + } } + } - dbUpdate($peer['c_update'], 'bgpPeers_cbgp', '`device_id` = ? AND bgpPeerIdentifier = ? AND afi = ? AND safi = ?', array($device['device_id'], $peer['bgpPeerIdentifier'], $afi, $safi)); + $peerrrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('bgp-'.$peer['bgpPeerIdentifier'].'.rrd'); + if (!is_file($peerrrd)) { + $create_rrd = 'DS:bgpPeerOutUpdates:COUNTER:600:U:100000000000 + DS:bgpPeerInUpdates:COUNTER:600:U:100000000000 + DS:bgpPeerOutTotal:COUNTER:600:U:100000000000 + DS:bgpPeerInTotal:COUNTER:600:U:100000000000 + DS:bgpPeerEstablished:GAUGE:600:0:U '.$config['rrd_rra']; - $cbgp_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('cbgp-'.$peer['bgpPeerIdentifier'].".$afi.$safi.rrd"); - if (!is_file($cbgp_rrd)) { - $rrd_create = 'DS:AcceptedPrefixes:GAUGE:600:U:100000000000 - DS:DeniedPrefixes:GAUGE:600:U:100000000000 - DS:AdvertisedPrefixes:GAUGE:600:U:100000000000 - DS:SuppressedPrefixes:GAUGE:600:U:100000000000 - DS:WithdrawnPrefixes:GAUGE:600:U:100000000000 '.$config['rrd_rra']; - rrdtool_create($cbgp_rrd, $rrd_create); - } + rrdtool_create($peerrrd, $create_rrd); + } - $fields = array( - 'AcceptedPrefixes' => $cbgpPeerAcceptedPrefixes, - 'DeniedPrefixes' => $cbgpPeerDeniedPrefixes, - 'AdvertisedPrefixes' => $cbgpPeerAdvertisedPrefixes, - 'SuppressedPrefixes' => $cbgpPeerSuppressedPrefixes, - 'WithdrawnPrefixes' => $cbgpPeerWithdrawnPrefixes, - ); - rrdtool_update("$cbgp_rrd", $fields); + $fields = array( + 'bgpPeerOutUpdates' => $bgpPeerOutUpdates, + 'bgpPeerInUpdates' => $bgpPeerInUpdates, + 'bgpPeerOutTotal' => $bgpPeerOutTotalMessages, + 'bgpPeerInTotal' => $bgpPeerInTotalMessages, + 'bgpPeerEstablished' => $bgpPeerFsmEstablishedTime, + ); + rrdtool_update("$peerrrd", $fields); - $tags = array('bgpPeerIdentifier' => $peer['bgpPeerIdentifier'], 'afi' => $afi, 'safi' => $safi); - influx_update($device,'cbgp',$tags,$fields); + $tags = array('bgpPeerIdentifier' => $peer['bgpPeerIdentifier']); + influx_update($device,'bgp',$tags,$fields); - } //end foreach - } //end if - echo "\n"; - } //end foreach + $peer['update']['bgpPeerState'] = $bgpPeerState; + $peer['update']['bgpPeerAdminStatus'] = $bgpPeerAdminStatus; + $peer['update']['bgpPeerFsmEstablishedTime'] = $bgpPeerFsmEstablishedTime; + $peer['update']['bgpPeerInUpdates'] = $bgpPeerInUpdates; + $peer['update']['bgpLocalAddr'] = $bgpLocalAddr; + $peer['update']['bgpPeerOutUpdates'] = $bgpPeerOutUpdates; + + dbUpdate($peer['update'], 'bgpPeers', '`device_id` = ? AND `bgpPeerIdentifier` = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); + + if ($device['os_group'] == 'cisco' || $device['os'] == 'junos') { + // Poll each AFI/SAFI for this peer (using CISCO-BGP4-MIB or BGP4-V2-JUNIPER MIB) + $peer_afis = dbFetchRows('SELECT * FROM bgpPeers_cbgp WHERE `device_id` = ? AND bgpPeerIdentifier = ?', array($device['device_id'], $peer['bgpPeerIdentifier'])); + foreach ($peer_afis as $peer_afi) { + $afi = $peer_afi['afi']; + $safi = $peer_afi['safi']; + d_echo("$afi $safi\n"); + + if ($device['os_group'] == 'cisco') { + $bgp_peer_ident = ipv62snmp($peer['bgpPeerIdentifier']); + if (strstr($peer['bgpPeerIdentifier'], ':')) { + $ip_type = 2; + $ip_len = 16; + $ip_ver = 'ipv6'; + } + else { + $ip_type = 1; + $ip_len = 4; + $ip_ver = 'ipv4'; + } + + $ip_cast = 1; + if ($peer_afi['safi'] == 'multicast') { + $ip_cast = 2; + } + else if ($peer_afi['safi'] == 'unicastAndMulticast') { + $ip_cast = 3; + } + else if ($peer_afi['safi'] == 'vpn') { + $ip_cast = 128; + } + + $check = snmp_get($device, 'cbgpPeer2AcceptedPrefixes.'.$ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast, '', 'CISCO-BGP4-MIB', $config['mibdir']); + + if (!empty($check)) { + $cgp_peer_identifier = $ip_type.'.'.$ip_len.'.'.$bgp_peer_ident.'.'.$ip_type.'.'.$ip_cast; + $cbgp_data_tmp = snmp_get_multi( + $device, + ' cbgpPeer2AcceptedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2DeniedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2PrefixAdminLimit.'.$cgp_peer_identifier.' cbgpPeer2PrefixThreshold.'.$cgp_peer_identifier.' cbgpPeer2PrefixClearThreshold.'.$cgp_peer_identifier.' cbgpPeer2AdvertisedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2SuppressedPrefixes.'.$cgp_peer_identifier.' cbgpPeer2WithdrawnPrefixes.'.$cgp_peer_identifier, + '-OQUs', + 'CISCO-BGP4-MIB', + $config['mibdir'] + ); + $ident = "$ip_ver.\"".$peer['bgpPeerIdentifier'].'"'.'.'.$ip_type.'.'.$ip_cast; + unset($cbgp_data); + $temp_keys = array_keys($cbgp_data_tmp); + unset($temp_data); + $temp_data['cbgpPeer2AcceptedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AcceptedPrefixes']; + $temp_data['cbgpPeer2DeniedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2DeniedPrefixes']; + $temp_data['cbgpPeer2PrefixAdminLimit'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixAdminLimit']; + $temp_data['cbgpPeer2PrefixThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixThreshold']; + $temp_data['cbgpPeer2PrefixClearThreshold'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2PrefixClearThreshold']; + $temp_data['cbgpPeer2AdvertisedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2AdvertisedPrefixes']; + $temp_data['cbgpPeer2SuppressedPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2SuppressedPrefixes']; + $temp_data['cbgpPeer2WithdrawnPrefixes'] = $cbgp_data_tmp[$temp_keys[0]]['cbgpPeer2WithdrawnPrefixes']; + foreach ($temp_data as $k => $v) { + $cbgp_data .= "$v\n"; + } + + d_echo("$cbgp_data\n"); + } + else { + // FIXME - move to function + $cbgp_cmd = $config['snmpget'].' -M '.$config['mibdir'].' -m CISCO-BGP4-MIB -Ovq '.snmp_gen_auth($device).' '.$device['hostname'].':'.$device['port']; + $cbgp_cmd .= ' cbgpPeerAcceptedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerDeniedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerPrefixAdminLimit.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerPrefixThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerPrefixClearThreshold.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerAdvertisedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerSuppressedPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + $cbgp_cmd .= ' cbgpPeerWithdrawnPrefixes.'.$peer['bgpPeerIdentifier'].".$afi.$safi"; + + d_echo("$cbgp_cmd\n"); + + $cbgp_data = preg_replace('/^OID.*$/', '', trim(`$cbgp_cmd`)); + $cbgp_data = preg_replace('/No Such Instance currently exists at this OID/', '0', $cbgp_data); + d_echo("$cbgp_data\n"); + }//end if + list($cbgpPeerAcceptedPrefixes,$cbgpPeerDeniedPrefixes,$cbgpPeerPrefixAdminLimit,$cbgpPeerPrefixThreshold,$cbgpPeerPrefixClearThreshold,$cbgpPeerAdvertisedPrefixes,$cbgpPeerSuppressedPrefixes,$cbgpPeerWithdrawnPrefixes) = explode("\n", $cbgp_data); + }//end if + + // FIXME THESE FIELDS DO NOT EXIST IN THE DATABASE! + $update = 'UPDATE bgpPeers_cbgp SET'; + $peer['c_update']['AcceptedPrefixes'] = $cbgpPeerAcceptedPrefixes; + $peer['c_update']['DeniedPrefixes'] = $cbgpPeerDeniedPrefixes; + $peer['c_update']['PrefixAdminLimit'] = $cbgpPeerAdminLimit; + $peer['c_update']['PrefixThreshold'] = $cbgpPeerPrefixThreshold; + $peer['c_update']['PrefixClearThreshold'] = $cbgpPeerPrefixClearThreshold; + $peer['c_update']['AdvertisedPrefixes'] = $cbgpPeerAdvertisedPrefixes; + $peer['c_update']['SuppressedPrefixes'] = $cbgpPeerSuppressedPrefixes; + $peer['c_update']['WithdrawnPrefixes'] = $cbgpPeerWithdrawnPrefixes; + + + $oids = array( + 'AcceptedPrefixes', + 'DeniedPrefixes', + 'AdvertisedPrefixes', + 'SuppressedPrefixes', + 'WithdrawnPrefixes', + ); + + foreach ($oids as $oid) { + $peer['c_update'][$oid.'_delta'] = $peer['c_update'][$oid] - $peer_afi[$oid]; + $peer['c_update'][$oid.'_prev'] = $peer_afi[$oid]; + } + + dbUpdate($peer['c_update'], 'bgpPeers_cbgp', '`device_id` = ? AND bgpPeerIdentifier = ? AND afi = ? AND safi = ?', array($device['device_id'], $peer['bgpPeerIdentifier'], $afi, $safi)); + + $cbgp_rrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('cbgp-'.$peer['bgpPeerIdentifier'].".$afi.$safi.rrd"); + if (!is_file($cbgp_rrd)) { + $rrd_create = 'DS:AcceptedPrefixes:GAUGE:600:U:100000000000 + DS:DeniedPrefixes:GAUGE:600:U:100000000000 + DS:AdvertisedPrefixes:GAUGE:600:U:100000000000 + DS:SuppressedPrefixes:GAUGE:600:U:100000000000 + DS:WithdrawnPrefixes:GAUGE:600:U:100000000000 '.$config['rrd_rra']; + rrdtool_create($cbgp_rrd, $rrd_create); + } + + $fields = array( + 'AcceptedPrefixes' => $cbgpPeerAcceptedPrefixes, + 'DeniedPrefixes' => $cbgpPeerDeniedPrefixes, + 'AdvertisedPrefixes' => $cbgpPeerAdvertisedPrefixes, + 'SuppressedPrefixes' => $cbgpPeerSuppressedPrefixes, + 'WithdrawnPrefixes' => $cbgpPeerWithdrawnPrefixes, + ); + rrdtool_update("$cbgp_rrd", $fields); + + $tags = array('bgpPeerIdentifier' => $peer['bgpPeerIdentifier'], 'afi' => $afi, 'safi' => $safi); + influx_update($device,'cbgp',$tags,$fields); + + } //end foreach + } //end if + echo "\n"; + } //end foreach + } //end if } //end if From 1110836662b8c12f402cd0a96a98bf56e0564da5 Mon Sep 17 00:00:00 2001 From: Daniel Preussker Date: Tue, 9 Feb 2016 20:00:54 +0100 Subject: [PATCH 062/104] Revert "Added location_map_regex" --- AUTHORS.md | 1 - doc/Support/Configuration.md | 7 +------ includes/polling/core.inc.php | 2 +- includes/rewrites.php | 9 --------- 4 files changed, 2 insertions(+), 17 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index ad2afab6e..1aa5c18ff 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -83,7 +83,6 @@ LibreNMS contributors: - Maximilian Wilhelm (BarbarossaTM) - Jameson Finney (JamesonFinney) - John Wells (jbwiv) -- Paul Blasquez (pblasquez) [1]: http://observium.org/ "Observium web site" Observium was written by: diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index 8070df0ce..f37f7bc78 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -379,15 +379,10 @@ NFSen integration support. #### Location mapping -Exact Matching: ```php $config['location_map']['Under the Sink'] = "Under The Sink, The Office, London, UK"; ``` -Regex Matching: -```php -$config['location_map']['/Sink/'] = "Under The Sink, The Office, London, UK"; -``` -The above are examples, these will rewrite device snmp locations so you don't need to configure full location within snmp. +The above is an example, this will rewrite basic snmp locations so you don't need to configure full location within snmp. #### Interfaces to be ignored diff --git a/includes/polling/core.inc.php b/includes/polling/core.inc.php index 1af4e3b58..ec23309a2 100644 --- a/includes/polling/core.inc.php +++ b/includes/polling/core.inc.php @@ -85,7 +85,7 @@ $poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']); $poll_device['sysLocation'] = trim($poll_device['sysLocation'], '\\'); // Rewrite sysLocation if there is a mapping array (database too?) -if (!empty($poll_device['sysLocation']) && (is_array($config['location_map']) || is_array($config['location_map_regex']))) { +if (!empty($poll_device['sysLocation']) && is_array($config['location_map'])) { $poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']); } diff --git a/includes/rewrites.php b/includes/rewrites.php index b4b28cd63..e2516d5c2 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -5,15 +5,6 @@ function rewrite_location($location) { // FIXME -- also check the database for rewrites? global $config, $debug; - if (is_array($config['location_map_regex'])) { - foreach ($config['location_map_regex'] as $reg => $val) { - if (preg_match($reg, $location)) { - $location = $val; - continue; - } - } - } - if (isset($config['location_map'][$location])) { $location = $config['location_map'][$location]; } From f074f25be23422d088d594a14cc2b84c2c83f2c8 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Tue, 9 Feb 2016 19:02:38 +0000 Subject: [PATCH 063/104] Revert "Revert "Added location_map_regex"" --- AUTHORS.md | 1 + doc/Support/Configuration.md | 7 ++++++- includes/polling/core.inc.php | 2 +- includes/rewrites.php | 9 +++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 1aa5c18ff..ad2afab6e 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -83,6 +83,7 @@ LibreNMS contributors: - Maximilian Wilhelm (BarbarossaTM) - Jameson Finney (JamesonFinney) - John Wells (jbwiv) +- Paul Blasquez (pblasquez) [1]: http://observium.org/ "Observium web site" Observium was written by: diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index f37f7bc78..8070df0ce 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -379,10 +379,15 @@ NFSen integration support. #### Location mapping +Exact Matching: ```php $config['location_map']['Under the Sink'] = "Under The Sink, The Office, London, UK"; ``` -The above is an example, this will rewrite basic snmp locations so you don't need to configure full location within snmp. +Regex Matching: +```php +$config['location_map']['/Sink/'] = "Under The Sink, The Office, London, UK"; +``` +The above are examples, these will rewrite device snmp locations so you don't need to configure full location within snmp. #### Interfaces to be ignored diff --git a/includes/polling/core.inc.php b/includes/polling/core.inc.php index ec23309a2..1af4e3b58 100644 --- a/includes/polling/core.inc.php +++ b/includes/polling/core.inc.php @@ -85,7 +85,7 @@ $poll_device['sysLocation'] = str_replace('"', '', $poll_device['sysLocation']); $poll_device['sysLocation'] = trim($poll_device['sysLocation'], '\\'); // Rewrite sysLocation if there is a mapping array (database too?) -if (!empty($poll_device['sysLocation']) && is_array($config['location_map'])) { +if (!empty($poll_device['sysLocation']) && (is_array($config['location_map']) || is_array($config['location_map_regex']))) { $poll_device['sysLocation'] = rewrite_location($poll_device['sysLocation']); } diff --git a/includes/rewrites.php b/includes/rewrites.php index e2516d5c2..b4b28cd63 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -5,6 +5,15 @@ function rewrite_location($location) { // FIXME -- also check the database for rewrites? global $config, $debug; + if (is_array($config['location_map_regex'])) { + foreach ($config['location_map_regex'] as $reg => $val) { + if (preg_match($reg, $location)) { + $location = $val; + continue; + } + } + } + if (isset($config['location_map'][$location])) { $location = $config['location_map'][$location]; } From 6e71661a3a4e8940c3a80caeb73d5fd68b62d981 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 9 Feb 2016 19:04:05 +0000 Subject: [PATCH 064/104] Changed continue to break --- includes/rewrites.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/rewrites.php b/includes/rewrites.php index b4b28cd63..da0623f11 100644 --- a/includes/rewrites.php +++ b/includes/rewrites.php @@ -9,7 +9,7 @@ function rewrite_location($location) { foreach ($config['location_map_regex'] as $reg => $val) { if (preg_match($reg, $location)) { $location = $val; - continue; + break; } } } From 0422d8e58901b08669743cec33851f8c8d52eec3 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 9 Feb 2016 13:31:36 -0600 Subject: [PATCH 065/104] Add fanspeed,temp, and voltage for Netonix switches. --- .../sensors/fanspeeds/netonix.inc.php | 17 +++++++++++++++++ .../sensors/temperatures/netonix.inc.php | 17 +++++++++++++++++ .../discovery/sensors/voltages/netonix.inc.php | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 includes/discovery/sensors/fanspeeds/netonix.inc.php create mode 100644 includes/discovery/sensors/temperatures/netonix.inc.php create mode 100644 includes/discovery/sensors/voltages/netonix.inc.php diff --git a/includes/discovery/sensors/fanspeeds/netonix.inc.php b/includes/discovery/sensors/fanspeeds/netonix.inc.php new file mode 100644 index 000000000..0a4a942d8 --- /dev/null +++ b/includes/discovery/sensors/fanspeeds/netonix.inc.php @@ -0,0 +1,17 @@ + $entry) { + if (is_numeric($entry['fanSpeed']) && is_numeric($index)) { + $descr = $index; + $oid = '.1.3.6.1.4.1.46242.2.1.2.'.$index; + $current = $entry['fanSpeed']; + discover_sensor($valid['sensor'], 'fanspeed', $device, $oid, $index, $device['os'], $descr, '1', '1', null, null, null, null, $current); + } + } + } +}//end if diff --git a/includes/discovery/sensors/temperatures/netonix.inc.php b/includes/discovery/sensors/temperatures/netonix.inc.php new file mode 100644 index 000000000..fbaf910ec --- /dev/null +++ b/includes/discovery/sensors/temperatures/netonix.inc.php @@ -0,0 +1,17 @@ + $entry) { + if (is_numeric($entry['temp']) && is_numeric($index) && $entry['temp'] > '0') { + $descr = $entry['tempDescription']; + $oid = '.1.3.6.1.4.1.46242.3.1.3.'.$index; + $current = $entry['temp']; + discover_sensor($valid['sensor'], 'temperature', $device, $oid, $index, $device['os'], $descr, '1', '1', null, null, null, null, $current); + } + } + } +}//end if diff --git a/includes/discovery/sensors/voltages/netonix.inc.php b/includes/discovery/sensors/voltages/netonix.inc.php new file mode 100644 index 000000000..f800df6e9 --- /dev/null +++ b/includes/discovery/sensors/voltages/netonix.inc.php @@ -0,0 +1,18 @@ + $entry) { + if (is_numeric($entry['voltage']) && is_numeric($index) && $entry['voltage'] > '0') { + $descr = $entry['voltageDescription']; + $oid = '.1.3.6.1.4.1.46242.4.1.3.'.$index; + $current = $entry['voltage']; + $divisor = 100; + discover_sensor($valid['sensor'], 'voltage', $device, $oid, $index, $device['os'], $descr, $divisor, '1', null, null, null, null, $current); + } + } + } +}//end if From f45bceecba55821e6f4dbaea0d593410ea9bfeb6 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 9 Feb 2016 13:36:44 -0600 Subject: [PATCH 066/104] The fanspeed is frequently 0 rpm. --- includes/discovery/sensors/fanspeeds/netonix.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/sensors/fanspeeds/netonix.inc.php b/includes/discovery/sensors/fanspeeds/netonix.inc.php index 0a4a942d8..b2882d0b5 100644 --- a/includes/discovery/sensors/fanspeeds/netonix.inc.php +++ b/includes/discovery/sensors/fanspeeds/netonix.inc.php @@ -10,7 +10,7 @@ if ($device['os'] == 'netonix') { $descr = $index; $oid = '.1.3.6.1.4.1.46242.2.1.2.'.$index; $current = $entry['fanSpeed']; - discover_sensor($valid['sensor'], 'fanspeed', $device, $oid, $index, $device['os'], $descr, '1', '1', null, null, null, null, $current); + discover_sensor($valid['sensor'], 'fanspeed', $device, $oid, $index, $device['os'], $descr, '1', '1', '0', '0', null, null, $current); } } } From e3ec42c06d5aaa4fb632d89c9eff46eda4eca95b Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 9 Feb 2016 14:20:36 -0600 Subject: [PATCH 067/104] Deal with 0 value for sensor data better. Issue #2883 --- html/pages/device/overview/generic/sensor.inc.php | 2 +- includes/polling/functions.inc.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/html/pages/device/overview/generic/sensor.inc.php b/html/pages/device/overview/generic/sensor.inc.php index ef4288e7c..c93660b6f 100644 --- a/html/pages/device/overview/generic/sensor.inc.php +++ b/html/pages/device/overview/generic/sensor.inc.php @@ -12,7 +12,7 @@ if (count($sensors)) { echo ' '; foreach ($sensors as $sensor) { - if (empty($sensor['sensor_current'])) { + if (!isset($sensor['sensor_current'])) { $sensor['sensor_current'] = 'NaN'; } diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index d1fcf196e..fdd9aa3d7 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -83,7 +83,7 @@ function poll_sensor($device, $class, $unit) { $sensor_value = 0; } - if ($sensor['sensor_divisor']) { + if ($sensor['sensor_divisor'] && $sensor_value !== 0) { $sensor_value = ($sensor_value / $sensor['sensor_divisor']); } From 8849cee3f4d0f444190f30f8ec2df84d65c62326 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 9 Feb 2016 15:42:46 -0600 Subject: [PATCH 068/104] Missed this while fixing sensor data with 0 values. --- html/includes/table/sensors.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/includes/table/sensors.inc.php b/html/includes/table/sensors.inc.php index 62fd73b64..5bf964193 100644 --- a/html/includes/table/sensors.inc.php +++ b/html/includes/table/sensors.inc.php @@ -47,7 +47,7 @@ if ($rowCount != -1) { $sql = "SELECT * $sql"; foreach (dbFetchRows($sql, $param) as $sensor) { - if (empty($sensor['sensor_current'])) { + if (!isset($sensor['sensor_current'])) { $sensor['sensor_current'] = 'NaN'; } else { From 37dccb3932a5341ff93abb42216eb453fedff631 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 13:42:55 +0000 Subject: [PATCH 069/104] First effort in bringing some sanity --- html/includes/vars.inc.php | 10 +++++----- html/index.php | 8 -------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index 369a13a74..8d3c3b6c2 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -7,7 +7,7 @@ foreach ($_GET as $key => $get_var) { $value = 'yes'; } - $vars[$name] = $value; + $vars[$name] = htmlentities($value); } } @@ -23,7 +23,7 @@ else { foreach ($segments as $pos => $segment) { $segment = urldecode($segment); if ($pos == '0') { - $vars['page'] = $segment; + $vars['page'] =htmlentities( $segment); } else { list($name, $value) = explode('=', $segment); @@ -31,15 +31,15 @@ foreach ($segments as $pos => $segment) { $vars[$name] = yes; } else { - $vars[$name] = $value; + $vars[$name] = htmlentities($value); } } } foreach ($_GET as $name => $value) { - $vars[$name] = $value; + $vars[$name] = htmlentities($value); } foreach ($_POST as $name => $value) { - $vars[$name] = $value; + $vars[$name] = htmlentities($value); } diff --git a/html/index.php b/html/index.php index 46164c663..494d6c3de 100644 --- a/html/index.php +++ b/html/index.php @@ -214,14 +214,6 @@ else {
    "); - print_r($_GET); - print_r($vars); - echo(""); -} - if ($_SESSION['authenticated']) { // Authenticated. Print a page. if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) { From a6bca987bf927d36c91df980c42a777e643cee72 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 13:52:43 +0000 Subject: [PATCH 070/104] Enforce sanity before returning from database --- html/includes/vars.inc.php | 2 +- includes/common.php | 10 ++++++++++ includes/dbFacile.mysql.php | 2 ++ includes/dbFacile.mysqli.php | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index 8d3c3b6c2..a633cef72 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -23,7 +23,7 @@ else { foreach ($segments as $pos => $segment) { $segment = urldecode($segment); if ($pos == '0') { - $vars['page'] =htmlentities( $segment); + $vars['page'] = htmlentities($segment); } else { list($name, $value) = explode('=', $segment); diff --git a/includes/common.php b/includes/common.php index 8b59ba774..1162b819a 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1255,3 +1255,13 @@ function get_port_id ($ports_mapped, $port, $port_association_mode) { return $port_id; } + +/** + * Sanitize + * @param mixed $item Reference to Item + * @param mixed $key Key + * @return void + */ +function sanitize_array(&$item, $key) { + $item = htmlentities($item); +} diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php index f2bb56c0b..d9372cbb6 100644 --- a/includes/dbFacile.mysql.php +++ b/includes/dbFacile.mysql.php @@ -266,6 +266,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); } + array_walk_recursive($rows,'sanitize_array'); return $rows; } @@ -333,6 +334,7 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); } + array_walk_recursive($row,'sanitize_array'); return $row; } else { diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php index 15a48962c..70c4651e7 100644 --- a/includes/dbFacile.mysqli.php +++ b/includes/dbFacile.mysqli.php @@ -267,6 +267,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); } + array_walk_recursive($rows,'sanitize_array'); return $rows; } @@ -334,6 +335,7 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); } + array_walk_recursive($row,'sanitize_array'); return $row; } else { From 8d9b522bdbb6f7664f42051037ff52fe1bc8a168 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 13:54:22 +0000 Subject: [PATCH 071/104] Remove redundant calls --- html/includes/vars.inc.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index a633cef72..c9008d217 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -7,7 +7,7 @@ foreach ($_GET as $key => $get_var) { $value = 'yes'; } - $vars[$name] = htmlentities($value); + $vars[$name] = $value; } } @@ -23,7 +23,7 @@ else { foreach ($segments as $pos => $segment) { $segment = urldecode($segment); if ($pos == '0') { - $vars['page'] = htmlentities($segment); + $vars['page'] = $segment; } else { list($name, $value) = explode('=', $segment); @@ -31,15 +31,17 @@ foreach ($segments as $pos => $segment) { $vars[$name] = yes; } else { - $vars[$name] = htmlentities($value); + $vars[$name] = $value; } } } foreach ($_GET as $name => $value) { - $vars[$name] = htmlentities($value); + $vars[$name] = $value; } foreach ($_POST as $name => $value) { - $vars[$name] = htmlentities($value); + $vars[$name] = $value; } + +array_walk_recursive($vars,'sanitize_array'); From 2b55c06d9e58f65f3a4184473e6cf6fd0869e029 Mon Sep 17 00:00:00 2001 From: Daniel Preussker Date: Wed, 10 Feb 2016 14:31:16 +0000 Subject: [PATCH 072/104] Revert "Variable/Environment sanity" --- html/includes/vars.inc.php | 2 -- html/index.php | 8 ++++++++ includes/common.php | 10 ---------- includes/dbFacile.mysql.php | 2 -- includes/dbFacile.mysqli.php | 2 -- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index c9008d217..369a13a74 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -43,5 +43,3 @@ foreach ($_GET as $name => $value) { foreach ($_POST as $name => $value) { $vars[$name] = $value; } - -array_walk_recursive($vars,'sanitize_array'); diff --git a/html/index.php b/html/index.php index 494d6c3de..46164c663 100644 --- a/html/index.php +++ b/html/index.php @@ -214,6 +214,14 @@ else {
    "); + print_r($_GET); + print_r($vars); + echo(""); +} + if ($_SESSION['authenticated']) { // Authenticated. Print a page. if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) { diff --git a/includes/common.php b/includes/common.php index 1162b819a..8b59ba774 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1255,13 +1255,3 @@ function get_port_id ($ports_mapped, $port, $port_association_mode) { return $port_id; } - -/** - * Sanitize - * @param mixed $item Reference to Item - * @param mixed $key Key - * @return void - */ -function sanitize_array(&$item, $key) { - $item = htmlentities($item); -} diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php index d9372cbb6..f2bb56c0b 100644 --- a/includes/dbFacile.mysql.php +++ b/includes/dbFacile.mysql.php @@ -266,7 +266,6 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); } - array_walk_recursive($rows,'sanitize_array'); return $rows; } @@ -334,7 +333,6 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); } - array_walk_recursive($row,'sanitize_array'); return $row; } else { diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php index 70c4651e7..15a48962c 100644 --- a/includes/dbFacile.mysqli.php +++ b/includes/dbFacile.mysqli.php @@ -267,7 +267,6 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); } - array_walk_recursive($rows,'sanitize_array'); return $rows; } @@ -335,7 +334,6 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); } - array_walk_recursive($row,'sanitize_array'); return $row; } else { From 21e94b3e3a799ecd0f9f6717b272aab8ae58bd85 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 15:20:32 +0000 Subject: [PATCH 073/104] Sanity! --- alerts.php | 4 ++-- html/ajax_dash.php | 2 +- html/includes/vars.inc.php | 2 ++ html/index.php | 8 -------- includes/alerts.inc.php | 1 + includes/common.php | 13 +++++++++++++ includes/dbFacile.mysql.php | 2 ++ includes/dbFacile.mysqli.php | 2 ++ 8 files changed, 23 insertions(+), 11 deletions(-) diff --git a/alerts.php b/alerts.php index 6d791d213..1035214c0 100755 --- a/alerts.php +++ b/alerts.php @@ -182,7 +182,7 @@ function RunFollowUp() { } $alert['details'] = json_decode(gzuncompress($alert['details']), true); - $rextra = json_decode($alert['extra'], true); + $rextra = json_decode(htmlspecialchars_decode($alert['extra']), true); if ($rextra['invert']) { continue; } @@ -237,7 +237,7 @@ function RunAlerts() { $noiss = false; $noacc = false; $updet = false; - $rextra = json_decode($alert['extra'], true); + $rextra = json_decode(htmlspecialchars_decode($alert['extra']), true); $chk = dbFetchRow('SELECT alerts.alerted,devices.ignore,devices.disabled FROM alerts,devices WHERE alerts.device_id = ? && devices.device_id = alerts.device_id && alerts.rule_id = ?', array($alert['device_id'], $alert['rule_id'])); if ($chk['alerted'] == $alert['state']) { $noiss = true; diff --git a/html/ajax_dash.php b/html/ajax_dash.php index 0ffc58067..e5622c732 100644 --- a/html/ajax_dash.php +++ b/html/ajax_dash.php @@ -39,7 +39,7 @@ elseif (is_file('includes/common/'.$type.'.inc.php')) { $title = ucfirst($type); $unique_id = str_replace(array("-","."),"_",uniqid($type,true)); $widget_id = mres($_POST['id']); - $widget_settings = json_decode(dbFetchCell('select settings from users_widgets where user_widget_id = ?',array($widget_id)),true); + $widget_settings = json_decode(htmlspecialchars_decode(dbFetchCell('select settings from users_widgets where user_widget_id = ?',array($widget_id))),true); $widget_dimensions = $_POST['dimensions']; if( !empty($_POST['settings']) ) { define('show_settings',true); diff --git a/html/includes/vars.inc.php b/html/includes/vars.inc.php index 369a13a74..c9008d217 100644 --- a/html/includes/vars.inc.php +++ b/html/includes/vars.inc.php @@ -43,3 +43,5 @@ foreach ($_GET as $name => $value) { foreach ($_POST as $name => $value) { $vars[$name] = $value; } + +array_walk_recursive($vars,'sanitize_array'); diff --git a/html/index.php b/html/index.php index 46164c663..494d6c3de 100644 --- a/html/index.php +++ b/html/index.php @@ -214,14 +214,6 @@ else {
    "); - print_r($_GET); - print_r($vars); - echo(""); -} - if ($_SESSION['authenticated']) { // Authenticated. Print a page. if (isset($vars['page']) && !strstr("..", $vars['page']) && is_file("pages/" . $vars['page'] . ".inc.php")) { diff --git a/includes/alerts.inc.php b/includes/alerts.inc.php index 23a56932d..3747c9f12 100644 --- a/includes/alerts.inc.php +++ b/includes/alerts.inc.php @@ -31,6 +31,7 @@ include_once($config['install_dir'].'/html/includes/authentication/'.$config['au * @return string|boolean */ function GenSQL($rule) { + $rule = htmlspecialchars_decode($rule); $rule = RunMacros($rule); if( empty($rule) ) { //Cannot resolve Macros due to recursion. Rule is invalid. diff --git a/includes/common.php b/includes/common.php index 8b59ba774..feb34b154 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1255,3 +1255,16 @@ function get_port_id ($ports_mapped, $port, $port_association_mode) { return $port_id; } + +/** + * Sanitize + * @param mixed $item Reference to Item + * @param mixed $key Key + * @return void + */ +function sanitize_array(&$item, $key) { + $tmp = htmlspecialchars($item); + if( !empty($tmp) ){ + $item = $tmp; + } +} diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php index f2bb56c0b..d9372cbb6 100644 --- a/includes/dbFacile.mysql.php +++ b/includes/dbFacile.mysql.php @@ -266,6 +266,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); } + array_walk_recursive($rows,'sanitize_array'); return $rows; } @@ -333,6 +334,7 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); } + array_walk_recursive($row,'sanitize_array'); return $row; } else { diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php index 15a48962c..70c4651e7 100644 --- a/includes/dbFacile.mysqli.php +++ b/includes/dbFacile.mysqli.php @@ -267,6 +267,7 @@ function dbFetchRows($sql, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$rows,$config['memcached']['ttl']); } + array_walk_recursive($rows,'sanitize_array'); return $rows; } @@ -334,6 +335,7 @@ function dbFetchRow($sql=null, $parameters=array(), $nocache=false) { if ($config['memcached']['enable'] && $nocache === false) { $config['memcached']['resource']->set(hash('sha512',$sql.'|'.serialize($parameters)),$row,$config['memcached']['ttl']); } + array_walk_recursive($row,'sanitize_array'); return $row; } else { From 375d7ca4af04c1431a318fab3a1fc9d2164ab447 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 15:26:17 +0000 Subject: [PATCH 074/104] Cosmetic fix on Alert-Rules --- html/includes/print-alert-rules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/includes/print-alert-rules.php b/html/includes/print-alert-rules.php index eac1ae6fd..4a198d9a1 100644 --- a/html/includes/print-alert-rules.php +++ b/html/includes/print-alert-rules.php @@ -205,7 +205,7 @@ foreach (dbFetchRows($full_query, $param) as $rule) { echo 'Inverted '; } - echo ''.htmlentities($rule['rule']).''; + echo ''.$rule['rule'].''; echo '
    '; echo " + echo $entry['link'].' '.$entry['message'].''; diff --git a/html/includes/print-event.inc.php b/html/includes/print-event.inc.php index d8afd6bfa..14b6764d8 100644 --- a/html/includes/print-event.inc.php +++ b/html/includes/print-event.inc.php @@ -31,5 +31,5 @@ else { echo ''; -echo ' +echo ''; From f60636930957e1ae65020422da7951824c1fb90e Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 15:40:50 +0000 Subject: [PATCH 076/104] Bulk cosmetic fixes --- html/includes/dev-overview-data.inc.php | 4 ++-- html/includes/print-alerts.inc.php | 2 +- html/includes/print-syslog.inc.php | 4 ++-- html/includes/reports/alert-log.pdf.inc.php | 2 +- html/includes/table/alertlog.inc.php | 2 +- html/includes/table/eventlog.inc.php | 2 +- html/includes/table/syslog.inc.php | 2 +- html/pages/devices.inc.php | 2 +- html/pages/syslog.inc.php | 8 ++++---- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/html/includes/dev-overview-data.inc.php b/html/includes/dev-overview-data.inc.php index 04c4de3dd..defeb6d44 100644 --- a/html/includes/dev-overview-data.inc.php +++ b/html/includes/dev-overview-data.inc.php @@ -68,14 +68,14 @@ if ($device['sysContact']) { '; if (get_dev_attrib($device, 'override_sysContact_bool')) { echo ' - + '; } echo ' - + '; } diff --git a/html/includes/print-alerts.inc.php b/html/includes/print-alerts.inc.php index d9758a0f3..ac75278fb 100644 --- a/html/includes/print-alerts.inc.php +++ b/html/includes/print-alerts.inc.php @@ -15,7 +15,7 @@ if (!isset($alert_entry['device'])) { '; } -echo ''; +echo ''; if ($alert_state != '') { if ($alert_state == '0') { diff --git a/html/includes/print-syslog.inc.php b/html/includes/print-syslog.inc.php index 0f1c1c669..26a0d5b62 100644 --- a/html/includes/print-syslog.inc.php +++ b/html/includes/print-syslog.inc.php @@ -8,10 +8,10 @@ if (device_permitted($entry['device_id'])) { if ($vars['page'] != 'device') { $syslog_output .= ' - '; + '; } else { - $syslog_output .= ''; + $syslog_output .= ''; } $syslog_output .= ''; diff --git a/html/includes/reports/alert-log.pdf.inc.php b/html/includes/reports/alert-log.pdf.inc.php index d293b474b..13b13526d 100644 --- a/html/includes/reports/alert-log.pdf.inc.php +++ b/html/includes/reports/alert-log.pdf.inc.php @@ -66,7 +66,7 @@ foreach (dbFetchRows($full_query, $param) as $alert_entry) { $data[] = array( $alert_entry['time_logged'], $hostname, - htmlspecialchars($alert_entry['name']), + $alert_entry['name'], $text, ); }//end if diff --git a/html/includes/table/alertlog.inc.php b/html/includes/table/alertlog.inc.php index 8b4d94d3e..3c41acb78 100644 --- a/html/includes/table/alertlog.inc.php +++ b/html/includes/table/alertlog.inc.php @@ -77,7 +77,7 @@ foreach (dbFetchRows($sql, $param) as $alertlog) { 'time_logged' => $alertlog['humandate'], 'details' => '', 'hostname' => '
    '.generate_device_link($dev, shorthost($dev['hostname'])).'
    '.$fault_detail.'
    ', - 'alert' => htmlspecialchars($alertlog['alert']), + 'alert' => $alertlog['alert'], 'status' => " $text", ); }//end foreach diff --git a/html/includes/table/eventlog.inc.php b/html/includes/table/eventlog.inc.php index 62edbbefd..6390b0d0f 100644 --- a/html/includes/table/eventlog.inc.php +++ b/html/includes/table/eventlog.inc.php @@ -66,7 +66,7 @@ foreach (dbFetchRows($sql, $param) as $eventlog) { 'datetime' => $eventlog['humandate'], 'hostname' => generate_device_link($dev, shorthost($dev['hostname'])), 'type' => $type, - 'message' => htmlspecialchars($eventlog['message']), + 'message' => $eventlog['message'], ); } diff --git a/html/includes/table/syslog.inc.php b/html/includes/table/syslog.inc.php index 987aac65a..bd80e7b5f 100644 --- a/html/includes/table/syslog.inc.php +++ b/html/includes/table/syslog.inc.php @@ -66,7 +66,7 @@ foreach (dbFetchRows($sql, $param) as $syslog) { 'timestamp' => $syslog['date'], 'device_id' => generate_device_link($dev, shorthost($dev['hostname'])), 'program' => $syslog['program'], - 'msg' => htmlspecialchars($syslog['msg']), + 'msg' => $syslog['msg'], ); } diff --git a/html/pages/devices.inc.php b/html/pages/devices.inc.php index 6d446d5c1..eb98e18ef 100644 --- a/html/pages/devices.inc.php +++ b/html/pages/devices.inc.php @@ -466,7 +466,7 @@ var grid = $("#devices").bootgrid({ return { id: "devices", format: '', - hostname: '', + hostname: '', os: '', version: '', hardware: '', diff --git a/html/pages/syslog.inc.php b/html/pages/syslog.inc.php index bd708c175..d0a8f905d 100644 --- a/html/pages/syslog.inc.php +++ b/html/pages/syslog.inc.php @@ -81,10 +81,10 @@ var grid = $("#syslog").bootgrid({ { return { id: "syslog", - device: '', - program: '', - to: '', - from: '', + device: '', + program: '', + to: '', + from: '', }; }, url: "ajax_table.php" From c767a26732f4c9245397cb5c565f794f09ba5277 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 16:02:13 +0000 Subject: [PATCH 077/104] more bulk sanity --- html/pages/adduser.inc.php | 2 +- html/pages/alert-log.inc.php | 6 +-- html/pages/api-access.inc.php | 8 ++-- html/pages/bills/search.inc.php | 2 +- html/pages/delhost.inc.php | 12 ++--- html/pages/device/edit.inc.php | 2 +- html/pages/device/logs/eventlog.inc.php | 2 +- html/pages/device/logs/syslog.inc.php | 2 +- html/pages/inventory.inc.php | 16 +++---- html/pages/routing/vrf.inc.php | 62 ++++++++++++------------- html/pages/search.inc.php | 2 +- html/pages/search/arp.inc.php | 8 ++-- html/pages/search/ipv4.inc.php | 8 ++-- html/pages/search/ipv6.inc.php | 8 ++-- html/pages/search/mac.inc.php | 8 ++-- html/pages/search/packages.inc.php | 30 ++++++------ 16 files changed, 89 insertions(+), 89 deletions(-) diff --git a/html/pages/adduser.inc.php b/html/pages/adduser.inc.php index 791d4d03d..7bb5c4838 100644 --- a/html/pages/adduser.inc.php +++ b/html/pages/adduser.inc.php @@ -27,7 +27,7 @@ else { // FIXME: missing email field here on the form if (adduser($_POST['new_username'], $_POST['new_password'], $_POST['new_level'], $_POST['new_email'], $_POST['new_realname'], $_POST['can_modify_passwd'])) { - echo 'User '.$_POST['username'].' added!'; + echo 'User '.$vars['username'].' added!'; } } else { diff --git a/html/pages/alert-log.inc.php b/html/pages/alert-log.inc.php index 752be46ce..4042b2e3d 100644 --- a/html/pages/alert-log.inc.php +++ b/html/pages/alert-log.inc.php @@ -51,7 +51,7 @@ foreach (get_all_devices() as $hostname) { $device_id = getidbyname($hostname); if (device_permitted($device_id)) { echo '""; - echo "'; + echo "'; echo ''; // echo(""); echo '
    '.$rule['severity'].' "; if ($rule_extra['mute'] === true) { From 2e59ada075c6ce8fce5db2f74ce8b8d11fa3a1e5 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 10 Feb 2016 15:31:37 +0000 Subject: [PATCH 075/104] Eventlog cosmetic fixes --- html/includes/print-event-short.inc.php | 2 +- html/includes/print-event.inc.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/html/includes/print-event-short.inc.php b/html/includes/print-event-short.inc.php index 42fc75768..2c02b7727 100644 --- a/html/includes/print-event-short.inc.php +++ b/html/includes/print-event-short.inc.php @@ -25,6 +25,6 @@ if ($entry['type'] == 'interface') { $entry['link'] = ''.generate_port_link(getifbyid($entry['reference'])).''; } - echo $entry['link'].' '.htmlspecialchars($entry['message']).'
    '.$entry['link'].''.htmlspecialchars($entry['message']).''.$entry['message'].'
    Contact'.htmlspecialchars(get_dev_attrib($device, 'override_sysContact_string')).''.get_dev_attrib($device, 'override_sysContact_string').'
    SNMP Contact'.htmlspecialchars($device['sysContact']).''.$device['sysContact'].'
    '.htmlspecialchars($alert_entry['name']).''.$alert_entry['name'].''.$entry['date'].' '.generate_device_link($entry).''.$entry['program'].' : '.htmlspecialchars($entry['msg']).''.$entry['program'].' : '.$entry['msg'].''.$entry['date'].'   '.$entry['program'].'   '.htmlspecialchars($entry['msg']).''.$entry['date'].'   '.$entry['program'].'   '.$entry['msg'].'
    ".$vrf['vrf_name'].'
    '.$vrf['mplsVpnVrfDescription'].'
    ".$vrf['vrf_name'].'
    '.$vrf['mplsVpnVrfDescription'].'
    '.$vrf['mplsVpnVrfRouteDistinguisher'].'" . $vrf['mplsVpnVrfDescription'] . "'; @@ -158,7 +158,7 @@ if ($_SESSION['userlevel'] >= '5') { foreach ($ports[$device['vrf_id']][$device['device_id']] as $port) { $port = array_merge($device, $port); - switch ($_GET['optc']) { + switch ($vars['optc']) { case 'bits': case 'upkts': case 'nupkts': @@ -168,7 +168,7 @@ if ($_SESSION['userlevel'] >= '5') { $port['from'] = $config['time']['day']; $port['to'] = $config['time']['now']; $port['bg'] = '#'.$bg; - $port['graph_type'] = 'port_'.$_GET['optc']; + $port['graph_type'] = 'port_'.$vars['optc']; echo "
    ".makeshortif($port['ifDescr']).'
    '; @@ -196,9 +196,9 @@ if ($_SESSION['userlevel'] >= '5') { } else { echo "
    "; - $vrf = dbFetchRow('SELECT * FROM `vrfs` WHERE mplsVpnVrfRouteDistinguisher = ?', array($_GET['optb'])); + $vrf = dbFetchRow('SELECT * FROM `vrfs` WHERE mplsVpnVrfRouteDistinguisher = ?', array($vars['optb'])); echo ""; - echo "'; + echo "'; echo ''; echo ''; echo '
    ".$vrf['vrf_name'].'".$vrf['vrf_name'].''.$vrf['mplsVpnVrfRouteDistinguisher'].''.$vrf['mplsVpnVrfDescription'].'
    '; diff --git a/html/pages/search.inc.php b/html/pages/search.inc.php index f6dcd9951..6e24c4ce2 100644 --- a/html/pages/search.inc.php +++ b/html/pages/search.inc.php @@ -28,7 +28,7 @@ foreach ($sections as $type => $texttype) { echo ""; } - // echo('' . $texttype .''); + // echo('' . $texttype .''); echo generate_link($texttype, array('page' => 'search', 'search' => $type)); if ($vars['search'] == $type) { diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php index f6c6492d6..451d7f579 100644 --- a/html/pages/search/arp.inc.php +++ b/html/pages/search/arp.inc.php @@ -73,7 +73,7 @@ if ($_POST['searchby'] == 'ip') { "
    "+ " "\" class=\"form-control input-sm\" placeholder=\"Address\" />"+ @@ -86,9 +86,9 @@ echo '"'.$_POST['searchPhrase'].'"+'; { return { id: "arp-search", - device_id: '', - searchby: '', - searchPhrase: '' + device_id: '', + searchby: '', + searchPhrase: '' }; }, url: "ajax_table.php" diff --git a/html/pages/search/ipv4.inc.php b/html/pages/search/ipv4.inc.php index 3d4393ff8..9ad59b1ae 100644 --- a/html/pages/search/ipv4.inc.php +++ b/html/pages/search/ipv4.inc.php @@ -70,7 +70,7 @@ if ($_POST['interface'] == 'Vlan%') { ""+ "
     "+ "
    "+ - "\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+ + "\" class=\"form-control input-sm\" placeholder=\"IPv4 Address\"/>"+ "
     "+ ""+ "
    "+ @@ -81,9 +81,9 @@ if ($_POST['interface'] == 'Vlan%') { return { id: "address-search", search_type: "ipv4", - device_id: '', - interface: '', - address: '' + device_id: '', + interface: '', + address: '' }; }, url: "ajax_table.php" diff --git a/html/pages/search/ipv6.inc.php b/html/pages/search/ipv6.inc.php index 2ce8900b2..84ac7f7e4 100644 --- a/html/pages/search/ipv6.inc.php +++ b/html/pages/search/ipv6.inc.php @@ -71,7 +71,7 @@ if ($_POST['interface'] == 'Vlan%') { ""+ ""+ "
    "+ - "\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+ + "\" class=\"form-control input-sm\" placeholder=\"IPv6 Address\"/>"+ "
    "+ ""+ ""+ @@ -82,9 +82,9 @@ if ($_POST['interface'] == 'Vlan%') { return { id: "address-search", search_type: "ipv6", - device_id: '', - interface: '', - address: '' + device_id: '', + interface: '', + address: '' }; }, url: "ajax_table.php" diff --git a/html/pages/search/mac.inc.php b/html/pages/search/mac.inc.php index a73e132b4..2638e2e68 100644 --- a/html/pages/search/mac.inc.php +++ b/html/pages/search/mac.inc.php @@ -69,7 +69,7 @@ if ($_POST['interface'] == 'Vlan%') { "
    "+ " "\" class=\"form-control input-sm\" placeholder=\"Mac Address\"/>"+ @@ -83,9 +83,9 @@ echo '"'.$_POST['address'].'"+'; return { id: "address-search", search_type: "mac", - device_id: '', - interface: '', - address: '' + device_id: '', + interface: '', + address: '' }; }, url: "ajax_table.php" diff --git a/html/pages/search/packages.inc.php b/html/pages/search/packages.inc.php index 0848fc372..d7d428a9b 100644 --- a/html/pages/search/packages.inc.php +++ b/html/pages/search/packages.inc.php @@ -28,23 +28,23 @@ print_optionbar_start(28);
    - +
    - +
    - +
    0) { - $results = $_POST['results']; +if(isset($vars['results_amount']) && $vars['results_amount'] > 0) { + $results = $vars['results']; } else { $results = 50; @@ -81,15 +81,15 @@ if (is_admin() === FALSE && is_read() === FALSE) { $param[] = $_SESSION['user_id']; } -$query .= " WHERE packages.device_id = devices.device_id AND packages.name LIKE '%".mres($_POST['package'])."%' $sql_where GROUP BY packages.name"; +$query .= " WHERE packages.device_id = devices.device_id AND packages.name LIKE '%".mres($vars['package'])."%' $sql_where GROUP BY packages.name"; $where = ''; $ver = ""; $opt = ""; -if( !empty($_POST['arch']) ) { +if( !empty($vars['arch']) ) { $where .= ' AND packages.arch = ?'; - $param[] = mres($_POST['arch']); + $param[] = mres($vars['arch']); } if( is_numeric($_REQUEST['device_id']) ) { @@ -102,11 +102,11 @@ $count_query .= $query." ) sub"; $query .= $where." ORDER BY packages.name, packages.arch, packages.version"; $count = dbFetchCell($count_query,$param); -if( !isset($_POST['page_number']) && $_POST['page_number'] < 1 ) { +if( !isset($vars['page_number']) && $vars['page_number'] < 1 ) { $page_number = 1; } else { - $page_number = $_POST['page_number']; + $page_number = $vars['page_number']; } $start = ($page_number - 1) * $results; @@ -134,8 +134,8 @@ foreach( dbFetchRows($full_query, $param) as $entry ) { } } -if( !empty($_POST['version']) ) { - list($opt, $ver) = explode(" ",$_POST['version']); +if( !empty($vars['version']) ) { + list($opt, $ver) = explode(" ",$vars['version']); } foreach( $ordered as $name=>$entry ) { @@ -178,9 +178,9 @@ if( (int) ($count / $results) > 0 && $count != $results ) {
    - - - + + +