From faf2b84083ffe822d9bb0e8955c82e41c5e75426 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 01/37] 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 000000000000..d35435553406 --- /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 02/37] 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 000000000000..68e9ddb9c964 --- /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 000000000000..94451564d8c0 --- /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 03/37] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 136 +++--- includes/discovery/bgp-peers.inc.php | 352 +++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 104 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 127 +++-- includes/polling/ospf.inc.php | 534 ++++++++++++---------- includes/snmp.inc.php | 8 +- 11 files changed, 922 insertions(+), 647 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index f80583a83f97..d1ce8b4e823a 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 4b6dc05bcd01..8dc38b4be259 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ function set_debug($debug) { // 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 @@ function set_debug($debug) { $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 69b0d9b750f6..c60d4ca95bce 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ 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)); +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)); -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)); + 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"; + 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; + $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 (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"); + 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']); - } + 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, - ); + 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'); + dbInsert($insert_data, 'ipv4_mac'); + }//end if }//end if - }//end if -}//end foreach + }//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']); + $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 '-'; + } } + echo "\n"; + unset($mac); + unset($device['context_name']); } - -echo "\n"; -unset($mac); +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf554..dd341715d497 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'])); - - 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); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + 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 '; } - 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 (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'); + 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); + + // 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, + ); + } } - - echo '+'; } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; } + } - 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); + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); - 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']); + 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'); } - d_echo('afi data :: '); - d_echo($af_data); + 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); - 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"); - - $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=?', 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'); + d_echo('afi data :: '); + d_echo($af_data); + + 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 ($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'); + 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"); + 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; + $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"); + 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; + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - 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; + 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'); + 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)); + $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'])); + } } } } + + 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); + unset($peerlist); - echo "\n"; + echo "\n"; + unset($device['context_name']); + } + 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 000000000000..ae2aff0e482b --- /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 b03ac9048b3b..e8055e63c0ca 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 53cf3ad5765e..26fc9ba28f10 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$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; - - 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'; - } + $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; - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); + 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_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 '+'; - } + 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 '.'; - } + echo '!'; + }//end if + }//end foreach - $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'])); + $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($valid_v4); + 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 562428b6bbaf..f7762ee988bc 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 (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'])); + 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 56863ec103b4..40ff425a07c5 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 @@ } } 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 (!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 @@ } // 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 @@ } 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 @@ } //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 8fec222a260c..60225525802f 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ '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 @@ '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 @@ 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,73 +62,231 @@ '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; +$ospf_nbr_oids_db = array( + 'ospfNbrIpAddr', + 'ospfNbrAddressLessIndex', + 'ospfNbrRtrId', + 'ospfNbrOptions', + 'ospfNbrPriority', + 'ospfNbrState', + 'ospfNbrEvents', + 'ospfNbrLsRetransQLen', + 'ospfNbmaNbrStatus', + 'ospfNbmaNbrPermanence', + 'ospfNbrHelloSuppressed', +); + + + +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_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -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)); + $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_ports_poll); - echo 'Database: '; - print_r($ospf_ports_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_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 ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - 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'])); - } + // 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 + } + } - 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_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 { + 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); + + + + 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_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); + 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_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; + } - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; + // 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_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 + } + + 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 @@ -264,98 +299,89 @@ // 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: '; + echo ' Neighbours: '; -$ospf_nbr_oids_db = array( - 'ospfNbrIpAddr', - 'ospfNbrAddressLessIndex', - 'ospfNbrRtrId', - 'ospfNbrOptions', - 'ospfNbrPriority', - 'ospfNbrState', - 'ospfNbrEvents', - 'ospfNbrLsRetransQLen', - 'ospfNbmaNbrStatus', - 'ospfNbmaNbrPermanence', - 'ospfNbrHelloSuppressed', -); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + $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; -} + // 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'); + // 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])) { - 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; + 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"; -} + 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']]; + // 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')); + } + } - $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'])); + 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['port_id'] != $ospf_nbr_poll['port_id']) { - if ($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')); + 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 + } } - } - 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 + 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 '.'; } - } - 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); + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; } else { - echo '.'; - } - - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; - } - 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 - + 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 6d1c32238006..72e3b17a5121 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 04/37] 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 000000000000..5dfced746435 --- /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 05/37] 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 000000000000..68e9ddb9c964 --- /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 000000000000..94451564d8c0 --- /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 06/37] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 136 +++--- includes/discovery/bgp-peers.inc.php | 352 +++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 104 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 127 +++-- includes/polling/ospf.inc.php | 534 ++++++++++++---------- includes/snmp.inc.php | 8 +- 11 files changed, 922 insertions(+), 647 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index 79fd3ee07882..be78f254f885 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 2e9282b35b0d..f91369c4af1b 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ function set_debug($debug) { // 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 @@ function set_debug($debug) { $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 69b0d9b750f6..c60d4ca95bce 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ 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)); +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)); -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)); + 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"; + 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; + $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 (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"); + 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']); - } + 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, - ); + 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'); + dbInsert($insert_data, 'ipv4_mac'); + }//end if }//end if - }//end if -}//end foreach + }//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']); + $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 '-'; + } } + echo "\n"; + unset($mac); + unset($device['context_name']); } - -echo "\n"; -unset($mac); +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf554..dd341715d497 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'])); - - 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); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + 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 '; } - 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 (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'); + 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); + + // 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, + ); + } } - - echo '+'; } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; } + } - 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); + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); - 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']); + 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'); } - d_echo('afi data :: '); - d_echo($af_data); + 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); - 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"); - - $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=?', 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'); + d_echo('afi data :: '); + d_echo($af_data); + + 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 ($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'); + 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"); + 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; + $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"); + 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; + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - 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; + 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'); + 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)); + $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'])); + } } } } + + 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); + unset($peerlist); - echo "\n"; + echo "\n"; + unset($device['context_name']); + } + 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 000000000000..ae2aff0e482b --- /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 b03ac9048b3b..e8055e63c0ca 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 53cf3ad5765e..26fc9ba28f10 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$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; - - 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'; - } + $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; - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); + 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_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 '+'; - } + 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 '.'; - } + echo '!'; + }//end if + }//end foreach - $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'])); + $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($valid_v4); + 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 562428b6bbaf..f7762ee988bc 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 (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'])); + 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 56863ec103b4..40ff425a07c5 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 @@ } } 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 (!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 @@ } // 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 @@ } 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 @@ } //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 8fec222a260c..60225525802f 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ '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 @@ '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 @@ 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,73 +62,231 @@ '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; +$ospf_nbr_oids_db = array( + 'ospfNbrIpAddr', + 'ospfNbrAddressLessIndex', + 'ospfNbrRtrId', + 'ospfNbrOptions', + 'ospfNbrPriority', + 'ospfNbrState', + 'ospfNbrEvents', + 'ospfNbrLsRetransQLen', + 'ospfNbmaNbrStatus', + 'ospfNbmaNbrPermanence', + 'ospfNbrHelloSuppressed', +); + + + +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_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -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)); + $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_ports_poll); - echo 'Database: '; - print_r($ospf_ports_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_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 ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - 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'])); - } + // 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 + } + } - 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_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 { + 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); + + + + 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_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); + 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_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; + } - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; + // 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_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 + } + + 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 @@ -264,98 +299,89 @@ // 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: '; + echo ' Neighbours: '; -$ospf_nbr_oids_db = array( - 'ospfNbrIpAddr', - 'ospfNbrAddressLessIndex', - 'ospfNbrRtrId', - 'ospfNbrOptions', - 'ospfNbrPriority', - 'ospfNbrState', - 'ospfNbrEvents', - 'ospfNbrLsRetransQLen', - 'ospfNbmaNbrStatus', - 'ospfNbmaNbrPermanence', - 'ospfNbrHelloSuppressed', -); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + $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; -} + // 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'); + // 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])) { - 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; + 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"; -} + 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']]; + // 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')); + } + } - $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'])); + 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['port_id'] != $ospf_nbr_poll['port_id']) { - if ($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')); + 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 + } } - } - 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 + 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 '.'; } - } - 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); + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; } else { - echo '.'; - } - - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; - } - 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 - + 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 4f15260aa84e..a9ad78226839 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 255eb9c0cefa30d3c07ed819bfa6bc10b5b63320 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 20 Jan 2016 15:04:37 +0100 Subject: [PATCH 07/37] 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 000000000000..5dfced746435 --- /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 08/37] 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 000000000000..68e9ddb9c964 --- /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 000000000000..94451564d8c0 --- /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 09/37] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 136 +++--- includes/discovery/bgp-peers.inc.php | 352 +++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 104 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 127 +++-- includes/polling/ospf.inc.php | 534 ++++++++++++---------- includes/snmp.inc.php | 8 +- 11 files changed, 922 insertions(+), 647 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index 63e16789936d..5b2c3f71ce66 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 328ae2ce0436..a418f747723a 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ function set_debug($debug) { // 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 @@ function set_debug($debug) { $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 69b0d9b750f6..c60d4ca95bce 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ 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)); +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)); -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)); + 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"; + 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; + $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 (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"); + 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']); - } + 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, - ); + 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'); + dbInsert($insert_data, 'ipv4_mac'); + }//end if }//end if - }//end if -}//end foreach + }//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']); + $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 '-'; + } } + echo "\n"; + unset($mac); + unset($device['context_name']); } - -echo "\n"; -unset($mac); +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf554..dd341715d497 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'])); - - 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); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + 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 '; } - 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 (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'); + 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); + + // 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, + ); + } } - - echo '+'; } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; } + } - 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); + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); - 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']); + 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'); } - d_echo('afi data :: '); - d_echo($af_data); + 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); - 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"); - - $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=?', 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'); + d_echo('afi data :: '); + d_echo($af_data); + + 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 ($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'); + 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"); + 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; + $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"); + 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; + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - 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; + 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'); + 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)); + $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'])); + } } } } + + 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); + unset($peerlist); - echo "\n"; + echo "\n"; + unset($device['context_name']); + } + 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 000000000000..ae2aff0e482b --- /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 b03ac9048b3b..e8055e63c0ca 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 53cf3ad5765e..26fc9ba28f10 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$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; - - 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'; - } + $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; - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); + 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_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 '+'; - } + 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 '.'; - } + echo '!'; + }//end if + }//end foreach - $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'])); + $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($valid_v4); + 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 562428b6bbaf..f7762ee988bc 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 (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'])); + 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 56863ec103b4..40ff425a07c5 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 @@ } } 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 (!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 @@ } // 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 @@ } 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 @@ } //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 8fec222a260c..60225525802f 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ '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 @@ '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 @@ 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,73 +62,231 @@ '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; +$ospf_nbr_oids_db = array( + 'ospfNbrIpAddr', + 'ospfNbrAddressLessIndex', + 'ospfNbrRtrId', + 'ospfNbrOptions', + 'ospfNbrPriority', + 'ospfNbrState', + 'ospfNbrEvents', + 'ospfNbrLsRetransQLen', + 'ospfNbmaNbrStatus', + 'ospfNbmaNbrPermanence', + 'ospfNbrHelloSuppressed', +); + + + +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_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -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)); + $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_ports_poll); - echo 'Database: '; - print_r($ospf_ports_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_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 ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - 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'])); - } + // 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 + } + } - 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_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 { + 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); + + + + 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_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); + 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_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; + } - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; + // 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_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 + } + + 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 @@ -264,98 +299,89 @@ // 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: '; + echo ' Neighbours: '; -$ospf_nbr_oids_db = array( - 'ospfNbrIpAddr', - 'ospfNbrAddressLessIndex', - 'ospfNbrRtrId', - 'ospfNbrOptions', - 'ospfNbrPriority', - 'ospfNbrState', - 'ospfNbrEvents', - 'ospfNbrLsRetransQLen', - 'ospfNbmaNbrStatus', - 'ospfNbmaNbrPermanence', - 'ospfNbrHelloSuppressed', -); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + $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; -} + // 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'); + // 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])) { - 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; + 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"; -} + 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']]; + // 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')); + } + } - $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'])); + 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['port_id'] != $ospf_nbr_poll['port_id']) { - if ($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')); + 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 + } } - } - 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 + 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 '.'; } - } - 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); + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; } else { - echo '.'; - } - - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; - } - 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 - + 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 e2d4bac01859..c27b2989f728 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 10/37] 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 5dfced746435..da527fcd08c6 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 11/37] 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 a418f747723a..cadc5ae174a6 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -736,8 +736,8 @@ function set_debug($debug) { $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 c60d4ca95bce..a04b9db8af4e 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -7,9 +7,10 @@ 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 @@ 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 dd341715d497..0d82f83edb14 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -7,7 +7,7 @@ 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 @@ echo '-'; } } - unset($peerlist); echo "\n"; diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php index ae2aff0e482b..b079e618cb8a 100644 --- a/includes/discovery/cisco-vrf-lite.inc.php +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -24,10 +24,8 @@ // 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 @@ $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 @@ $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 @@ } } 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 @@ $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 @@ )); } } 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 (!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 26fc9ba28f10..f930b8fd3c0c 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 f7762ee988bc..fb9864020844 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -4,7 +4,7 @@ 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 12/37] 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 000000000000..6caaecf4e4ec --- /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 13/37] 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 000000000000..68e9ddb9c964 --- /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 000000000000..94451564d8c0 --- /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 14/37] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 136 +++--- includes/discovery/bgp-peers.inc.php | 352 +++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 104 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 127 +++-- includes/polling/ospf.inc.php | 534 ++++++++++++---------- includes/snmp.inc.php | 8 +- 11 files changed, 922 insertions(+), 647 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index 9fe13efe5b52..0db9dad862af 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 328ae2ce0436..a418f747723a 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ function set_debug($debug) { // 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 @@ function set_debug($debug) { $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 69b0d9b750f6..c60d4ca95bce 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ 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)); +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)); -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)); + 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"; + 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; + $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 (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"); + 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']); - } + 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, - ); + 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'); + dbInsert($insert_data, 'ipv4_mac'); + }//end if }//end if - }//end if -}//end foreach + }//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']); + $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 '-'; + } } + echo "\n"; + unset($mac); + unset($device['context_name']); } - -echo "\n"; -unset($mac); +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf554..dd341715d497 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'])); - - 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); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + 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 '; } - 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 (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'); + 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); + + // 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, + ); + } } - - echo '+'; } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; } + } - 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); + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); - 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']); + 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'); } - d_echo('afi data :: '); - d_echo($af_data); + 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); - 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"); - - $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=?', 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'); + d_echo('afi data :: '); + d_echo($af_data); + + 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 ($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'); + 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"); + 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; + $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"); + 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; + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - 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; + 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'); + 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)); + $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'])); + } } } } + + 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); + unset($peerlist); - echo "\n"; + echo "\n"; + unset($device['context_name']); + } + 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 000000000000..ae2aff0e482b --- /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 b03ac9048b3b..e8055e63c0ca 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 53cf3ad5765e..26fc9ba28f10 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$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; - - 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'; - } + $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; - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); + 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_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 '+'; - } + 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 '.'; - } + echo '!'; + }//end if + }//end foreach - $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'])); + $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($valid_v4); + 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 562428b6bbaf..f7762ee988bc 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 (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'])); + 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 56863ec103b4..40ff425a07c5 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 @@ } } 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 (!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 @@ } // 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 @@ } 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 @@ } //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 8fec222a260c..60225525802f 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ '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 @@ '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 @@ 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,73 +62,231 @@ '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; +$ospf_nbr_oids_db = array( + 'ospfNbrIpAddr', + 'ospfNbrAddressLessIndex', + 'ospfNbrRtrId', + 'ospfNbrOptions', + 'ospfNbrPriority', + 'ospfNbrState', + 'ospfNbrEvents', + 'ospfNbrLsRetransQLen', + 'ospfNbmaNbrStatus', + 'ospfNbmaNbrPermanence', + 'ospfNbrHelloSuppressed', +); + + + +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_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -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)); + $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_ports_poll); - echo 'Database: '; - print_r($ospf_ports_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_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 ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - 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'])); - } + // 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 + } + } - 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_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 { + 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); + + + + 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_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); + 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_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; + } - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; + // 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_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 + } + + 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 @@ -264,98 +299,89 @@ // 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: '; + echo ' Neighbours: '; -$ospf_nbr_oids_db = array( - 'ospfNbrIpAddr', - 'ospfNbrAddressLessIndex', - 'ospfNbrRtrId', - 'ospfNbrOptions', - 'ospfNbrPriority', - 'ospfNbrState', - 'ospfNbrEvents', - 'ospfNbrLsRetransQLen', - 'ospfNbmaNbrStatus', - 'ospfNbmaNbrPermanence', - 'ospfNbrHelloSuppressed', -); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + $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; -} + // 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'); + // 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])) { - 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; + 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"; -} + 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']]; + // 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')); + } + } - $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'])); + 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['port_id'] != $ospf_nbr_poll['port_id']) { - if ($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')); + 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 + } } - } - 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 + 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 '.'; } - } - 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); + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; } else { - echo '.'; - } - - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; - } - 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 - + 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 e2d4bac01859..c27b2989f728 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 15/37] 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 000000000000..61aa90432fa5 --- /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 16/37] 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 61aa90432fa5..d35435553406 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 17/37] 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 d35435553406..00bef74e326d 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 18/37] 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 a418f747723a..cadc5ae174a6 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -736,8 +736,8 @@ function set_debug($debug) { $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 c60d4ca95bce..a04b9db8af4e 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -7,9 +7,10 @@ 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 @@ 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 dd341715d497..0d82f83edb14 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -7,7 +7,7 @@ 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 @@ echo '-'; } } - unset($peerlist); echo "\n"; diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php index ae2aff0e482b..b079e618cb8a 100644 --- a/includes/discovery/cisco-vrf-lite.inc.php +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -24,10 +24,8 @@ // 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 @@ $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 @@ $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 @@ } } 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 @@ $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 @@ )); } } 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 (!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 26fc9ba28f10..f930b8fd3c0c 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 f7762ee988bc..fb9864020844 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -4,7 +4,7 @@ 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 19/37] 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 cadc5ae174a6..a02588729757 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -722,6 +722,7 @@ function set_debug($debug) { $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 @@ function set_debug($debug) { $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 20/37] 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 000000000000..d35435553406 --- /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 21/37] 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 000000000000..68e9ddb9c964 --- /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 000000000000..94451564d8c0 --- /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 22/37] discoverying and polling VRF --- includes/common.php | 10 + includes/defaults.inc.php | 3 + includes/discovery/arp-table.inc.php | 136 +++--- includes/discovery/bgp-peers.inc.php | 352 +++++++------- includes/discovery/cisco-vrf-lite.inc.php | 142 ++++++ includes/discovery/functions.inc.php | 18 +- includes/discovery/ipv4-addresses.inc.php | 104 +++-- includes/discovery/ipv6-addresses.inc.php | 135 +++--- includes/polling/bgp-peers.inc.php | 127 +++-- includes/polling/ospf.inc.php | 534 ++++++++++++---------- includes/snmp.inc.php | 8 +- 11 files changed, 922 insertions(+), 647 deletions(-) create mode 100644 includes/discovery/cisco-vrf-lite.inc.php diff --git a/includes/common.php b/includes/common.php index d32f836ab728..0b7a63573826 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 328ae2ce0436..a418f747723a 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -438,6 +438,8 @@ function set_debug($debug) { // 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 @@ function set_debug($debug) { $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 69b0d9b750f6..c60d4ca95bce 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -4,78 +4,90 @@ 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)); +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)); -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)); + 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"; + 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; + $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 (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"); + 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']); - } + 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, - ); + 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'); + dbInsert($insert_data, 'ipv4_mac'); + }//end if }//end if - }//end if -}//end foreach + }//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']); + $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 '-'; + } } + echo "\n"; + unset($mac); + unset($device['context_name']); } - -echo "\n"; -unset($mac); +unset($vrfs_c); diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 1b87eaecf554..dd341715d497 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'])); - - 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); + + foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name'] = $vrf['context_name']; + + 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 '; } - 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 (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'); + 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); + + // 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, + ); + } } - - echo '+'; } - else { - $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext)), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); - echo '.'; + } + else { + echo 'No BGP on host'; + if ($device['bgpLocalAs']) { + dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); + echo ' (Removed ASN) '; } + } - 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); + // Process disovered peers + if (isset($peerlist)) { + foreach ($peerlist as $peer) { + $astext = get_astext($peer['as']); - 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']); + 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'); } - d_echo('afi data :: '); - d_echo($af_data); + 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); - 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"); - - $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=?', 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'); + d_echo('afi data :: '); + d_echo($af_data); + + 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 ($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'); + 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"); + 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; + $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"); + 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; + $j_peerIndexes[$ip6] = $entry['jnxBgpM2PeerIndex']; + break; - default: - echo "HALP? Don't know RemoteAddrType ".$entry['jnxBgpM2PeerRemoteAddrType']."!\n"; - 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; + 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'); + 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)); + $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'])); + } } } } + + 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); + unset($peerlist); - echo "\n"; + echo "\n"; + unset($device['context_name']); + } + 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 000000000000..ae2aff0e482b --- /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 b03ac9048b3b..e8055e63c0ca 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 53cf3ad5765e..26fc9ba28f10 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -1,58 +1,68 @@ null)); +} +foreach ($vrfs_lite_cisco as $vrf) { + $device['context_name']=$vrf['context_name']; -$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; - - 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'; - } + $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; - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)); + 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_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 '+'; - } + 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 '.'; - } + echo '!'; + }//end if + }//end foreach - $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'])); + $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($valid_v4); + 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 562428b6bbaf..f7762ee988bc 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 (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'])); + 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 56863ec103b4..40ff425a07c5 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 @@ } } 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 (!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 @@ } // 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 @@ } 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 @@ } //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 8fec222a260c..60225525802f 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -8,6 +8,7 @@ $ospf_area_count = 0; $ospf_neighbour_count = 0; + $ospf_oids_db = array( 'ospfRouterId', 'ospfAdminStat', @@ -25,64 +26,6 @@ '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 @@ '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 @@ 'ospfIfRtrPriority', 'ospfIfTransitDelay', 'ospfIfRetransInterval', - 'ospfIfHelloInterval', + 'ospfIfHelloInterval', 'ospfIfRtrDeadInterval', 'ospfIfPollInterval', 'ospfIfState', @@ -185,73 +62,231 @@ '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; +$ospf_nbr_oids_db = array( + 'ospfNbrIpAddr', + 'ospfNbrAddressLessIndex', + 'ospfNbrRtrId', + 'ospfNbrOptions', + 'ospfNbrPriority', + 'ospfNbrState', + 'ospfNbrEvents', + 'ospfNbrLsRetransQLen', + 'ospfNbmaNbrStatus', + 'ospfNbmaNbrPermanence', + 'ospfNbrHelloSuppressed', +); + + + +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_ports_poll = snmpwalk_cache_oid($device, 'OSPF-MIB::ospfIfEntry', array(), 'OSPF-MIB'); +foreach ($vrfs_lite_cisco as $vrf_lite) { -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)); + $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_ports_poll); - echo 'Database: '; - print_r($ospf_ports_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_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 ($debug) { + echo "\nPolled: "; + print_r($ospf_instances_poll); + echo 'Database: '; + print_r($ospf_instances_db); + echo "\n"; + } - 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'])); - } + // 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 + } + } - 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_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 { + 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); + + + + 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_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); + 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_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; + } - unset($ospf_port_poll); - unset($ospf_port_db); - $ospf_port_count++; + // 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_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 + } + + 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 @@ -264,98 +299,89 @@ // 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: '; + echo ' Neighbours: '; -$ospf_nbr_oids_db = array( - 'ospfNbrIpAddr', - 'ospfNbrAddressLessIndex', - 'ospfNbrRtrId', - 'ospfNbrOptions', - 'ospfNbrPriority', - 'ospfNbrState', - 'ospfNbrEvents', - 'ospfNbrLsRetransQLen', - 'ospfNbmaNbrStatus', - 'ospfNbmaNbrPermanence', - 'ospfNbrHelloSuppressed', -); -$ospf_nbr_oids_rrd = array(); -$ospf_nbr_oids = array_merge($ospf_nbr_oids_db, $ospf_nbr_oids_rrd); + $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; -} + // 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'); + // 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])) { - 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; + 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"; -} + 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']]; + // 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')); + } + } - $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'])); + 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['port_id'] != $ospf_nbr_poll['port_id']) { - if ($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')); + 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 + } } - } - 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 + 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 '.'; } - } - 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); + unset($ospf_nbr_poll); + unset($ospf_nbr_db); + $ospf_nbr_count++; } else { - echo '.'; - } - - unset($ospf_nbr_poll); - unset($ospf_nbr_db); - $ospf_nbr_count++; - } - 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 - + 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 3c7abd018935..635346a37933 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 23/37] 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 d35435553406..501e4c583e76 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 24/37] 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 501e4c583e76..d35435553406 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 25/37] 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 d35435553406..501e4c583e76 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 26/37] 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 a418f747723a..cadc5ae174a6 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -736,8 +736,8 @@ function set_debug($debug) { $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 c60d4ca95bce..a04b9db8af4e 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -7,9 +7,10 @@ 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 @@ 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 dd341715d497..0d82f83edb14 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -7,7 +7,7 @@ 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 @@ echo '-'; } } - unset($peerlist); echo "\n"; diff --git a/includes/discovery/cisco-vrf-lite.inc.php b/includes/discovery/cisco-vrf-lite.inc.php index ae2aff0e482b..b079e618cb8a 100644 --- a/includes/discovery/cisco-vrf-lite.inc.php +++ b/includes/discovery/cisco-vrf-lite.inc.php @@ -24,10 +24,8 @@ // 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 @@ $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 @@ $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 @@ } } 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 @@ $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 @@ )); } } 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 (!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 26fc9ba28f10..f930b8fd3c0c 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 f7762ee988bc..fb9864020844 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -4,7 +4,7 @@ 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 27/37] 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 501e4c583e76..d35435553406 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 28/37] 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 cadc5ae174a6..d7fa2eacec81 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -722,6 +722,7 @@ function set_debug($debug) { $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 @@ function set_debug($debug) { $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 a04b9db8af4e..94a1d7e2b38a 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -70,7 +70,6 @@ '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 f930b8fd3c0c..574bb7874eec 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -5,6 +5,7 @@ $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 29/37] 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 000000000000..61aa90432fa5 --- /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 30/37] 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 61aa90432fa5..d35435553406 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 31/37] 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 d35435553406..00bef74e326d 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 32/37] 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 d7fa2eacec81..f5b9eaa4d550 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -737,6 +737,7 @@ function set_debug($debug) { $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 574bb7874eec..f930b8fd3c0c 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -5,7 +5,6 @@ $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 33/37] 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 f5b9eaa4d550..a02588729757 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -737,7 +737,7 @@ function set_debug($debug) { $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 47c830a15c76d26a1fb06277fc1d08454de28c53 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Thu, 28 Jan 2016 11:00:24 +0100 Subject: [PATCH 34/37] bug correction on ospf polling module --- includes/polling/ospf.inc.php | 46 +++++++++++++++-------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/includes/polling/ospf.inc.php b/includes/polling/ospf.inc.php index 60225525802f..11b45feec019 100644 --- a/includes/polling/ospf.inc.php +++ b/includes/polling/ospf.inc.php @@ -1,14 +1,11 @@ null)); } foreach ($vrfs_lite_cisco as $vrf_lite) { - $device['context_name'] = $vrf_lite['context_name']; - + echo 'Processes: '; + // 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; @@ -101,8 +100,8 @@ 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; + $entry = 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[$ospf_instance_id][$device['context_name']] = $entry; } } @@ -129,7 +128,7 @@ } 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'])); + 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); } @@ -148,12 +147,10 @@ unset($ospf_instances_poll); unset($ospf_instances_db); - - 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) { + 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; } @@ -162,7 +159,7 @@ 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']])) { + if (empty($ospf_areas_db[$ospf_area_id][$device['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'])); @@ -180,12 +177,12 @@ // Loop array of entries and update if (is_array($ospf_areas_db)) { - foreach ($ospf_areas_db as $$ospf_area_id => $ospf_area_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 ($ospf_area_db[$device['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 @@ -229,10 +226,10 @@ 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']])) { + if (empty($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'])); + $ospf_ports_db[$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'])); } } @@ -301,8 +298,7 @@ // 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) { @@ -333,10 +329,10 @@ // 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 (is_array($ospf_nbrs_poll[$ospf_nbr_id])) { + $ospf_nbr_poll = $ospf_nbrs_poll[$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'])); + $ospf_nbr_poll['port_id'] = @dbFetchCell('SELECT A.`port_id` FROM ipv4_addresses AS A, ospf_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'])) { @@ -379,6 +375,7 @@ }//end if unset($ospf_nbrs_db); unset($ospf_nbrs_poll); + echo "\n"; } unset($device['context_name']); unset($vrfs_lite_cisco); @@ -407,7 +404,4 @@ $tags = array(); influx_update($device,'ospf-statistics',$tags,$fields); -unset($ospf_ports_db); -unset($ospf_ports_poll); - echo "\n"; From 8a3d14f9e2667af9c932d1b274198bd67dcd1b99 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Tue, 2 Feb 2016 12:21:45 +0100 Subject: [PATCH 35/37] Correct data duplication on discovering cisco vrf lite --- includes/discovery/arp-table.inc.php | 10 +- includes/discovery/bgp-peers.inc.php | 98 ++--- includes/discovery/functions.inc.php | 467 ++++++++++------------ includes/discovery/ipv4-addresses.inc.php | 17 +- includes/discovery/ipv6-addresses.inc.php | 2 +- 5 files changed, 288 insertions(+), 306 deletions(-) diff --git a/includes/discovery/arp-table.inc.php b/includes/discovery/arp-table.inc.php index 94a1d7e2b38a..5bc214e04661 100644 --- a/includes/discovery/arp-table.inc.php +++ b/includes/discovery/arp-table.inc.php @@ -47,10 +47,10 @@ $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']))) { + 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=? AND `context_name`= ?', array($ip, $interface['port_id']), $device['context_name']); + $old_mac = dbFetchCell('SELECT mac_address from ipv4_mac WHERE ipv4_address=?', 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"); @@ -58,7 +58,7 @@ 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'])); + dbUpdate(array('mac_address' => $clean_mac, 'context_name' => $device['context_name']), 'ipv4_mac', 'port_id=? AND ipv4_address=?', array($interface['port_id'], $ip)); echo '.'; } elseif (isset($interface['port_id'])) { @@ -75,12 +75,12 @@ }//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'] ."'"; + $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` = ? AND `context_name`= ?', array($entry_if, $entry_mac, $device['context_name'])); + dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address` = ?', array($entry_if, $entry_mac)); d_echo("Removing MAC $entry_mac from interface ".$interface['ifName']); echo '-'; diff --git a/includes/discovery/bgp-peers.inc.php b/includes/discovery/bgp-peers.inc.php index 0d82f83edb14..8b38f44b2bbb 100644 --- a/includes/discovery/bgp-peers.inc.php +++ b/includes/discovery/bgp-peers.inc.php @@ -3,19 +3,18 @@ if ($config['enable_bgp']) { // Discover BGP peers echo 'BGP Sessions : '; - - if( key_exists('vrf_lite_cisco', $device) && (count($device['vrf_lite_cisco'])!=0) ){ + + 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)); } - 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 "; @@ -24,12 +23,11 @@ echo 'Updated AS '; } - $peer2 = false; + $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 { + } else { $peer2 = true; } @@ -46,16 +44,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)); + $peer_ip = preg_replace('/(\S+\s+\S+)\s/', '$1:', $peer_ip_snmp); + $peer_ip = str_replace('"', '', str_replace(' ', '', $peer_ip)); } 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, ); } @@ -65,8 +63,8 @@ // 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)); + $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); @@ -83,8 +81,7 @@ } } } - } - else { + } else { echo 'No BGP on host'; if ($device['bgpLocalAs']) { dbUpdate(array('bgpLocalAs' => 'NULL'), 'devices', 'device_id=?', array($device['device_id'])); @@ -97,17 +94,17 @@ 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 (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'], 'context_name' => $device['context_name']), 'bgpPeers'); if ($config['autodiscovery']['bgp'] === true) { - $name = gethostbyaddr($peer['ip']); + $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'])); + } else { + $update = dbUpdate(array('bgpPeerRemoteAs' => $peer['as'], 'astext' => mres($astext), 'context_name' => $device['context_name']), 'bgpPeers', 'device_id=? AND bgpPeerIdentifier=?', array($device['device_id'], $peer['ip'])); echo '.'; } @@ -118,8 +115,7 @@ if ($peer2 === true) { $af_data = snmpwalk_cache_oid($device, 'cbgpPeer2AddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); - } - else { + } else { $af_data = snmpwalk_cache_oid($device, 'cbgpPeerAddrFamilyEntry', $cbgp, 'CISCO-BGP4-MIB', $config['mibdir']); } @@ -128,22 +124,26 @@ foreach ($af_data as $k => $v) { if ($peer2 === true) { - list(,$k) = explode('.', $k, 2); + 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)); + $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) { + 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, 'context_name' => $device['context_name']), 'bgpPeers_cbgp'); + } + else { + //Update Context + dbUpdate(array('context_name' => $device['context_name']), 'bgpPeers_cbgp', 'device_id = ? AND bgpPeerIdentifier = ? AND afi=? AND safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); } } } @@ -154,44 +154,44 @@ $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'); + $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"); + 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 = 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"); + 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"; + 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'); + $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; + 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]; + 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'); @@ -199,12 +199,12 @@ } } - $af_query = "SELECT * FROM bgpPeers_cbgp WHERE `device_id` = '".$device['device_id']."' AND bgpPeerIdentifier = '".$peer['ip']."' AND `context_name` = '" . $device['context_name'] . "'"; + $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']; + $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'])); + dbDelete('bgpPeers_cbgp', '`device_id` = ? AND `bgpPeerIdentifier` = ?, afi=?, safi=?', array($device['device_id'], $peer['ip'], $afi, $safi)); } } } @@ -217,7 +217,7 @@ } // 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'] . "'"; + $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'] . "'"; foreach (dbFetchRows($sql) as $entry) { unset($exists); diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index e8055e63c0ca..7bffc5c2fda4 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -12,14 +12,12 @@ * See COPYING for more details. */ - -function discover_new_device($hostname, $device='', $method='', $interface='') { +function discover_new_device($hostname, $device = '', $method = '', $interface = '') { global $config; - if (!empty($config['mydomain']) && isDomainResolves($hostname.'.'.$config['mydomain'])) { - $dst_host = $hostname.'.'.$config['mydomain']; - } - else { + if (!empty($config['mydomain']) && isDomainResolves($hostname . '.' . $config['mydomain'])) { + $dst_host = $hostname . '.' . $config['mydomain']; + } else { $dst_host = $hostname; } @@ -33,8 +31,7 @@ function discover_new_device($hostname, $device='', $method='', $interface='') { return false; } - } - elseif (filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true){ + } elseif (filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === true || filter_var($dst_host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === true) { // gethostbyname returned a valid $ip, was $dst_host an IP? if ($config['discovery_by_ip'] === false) { d_echo('Discovery by IP disabled, skipping ' . $dst_host); @@ -56,33 +53,31 @@ function discover_new_device($hostname, $device='', $method='', $interface='') { $remote_device_id = addHost($dst_host, '', '161', 'udp', '0', $config['distributed_poller_group']); if ($remote_device_id) { $remote_device = device_by_id_cache($remote_device_id, 1); - echo '+['.$remote_device['hostname'].'('.$remote_device['device_id'].')]'; + echo '+[' . $remote_device['hostname'] . '(' . $remote_device['device_id'] . ')]'; discover_device($remote_device); device_by_id_cache($remote_device_id, 1); if ($remote_device_id && is_array($device) && !empty($method)) { $extra_log = ''; - $int = ifNameDescr($interface); + $int = ifNameDescr($interface); if (is_array($int)) { - $extra_log = ' (port '.$int['label'].') '; + $extra_log = ' (port ' . $int['label'] . ') '; } - log_event('Device $'.$remote_device['hostname']." ($ip) $extra_log autodiscovered through $method on ".$device['hostname'], $remote_device_id, 'discovery'); - } - else { - log_event("$method discovery of ".$remote_device['hostname']." ($ip) failed - check ping and SNMP access", $device['device_id'], 'discovery'); + log_event('Device $' . $remote_device['hostname'] . " ($ip) $extra_log autodiscovered through $method on " . $device['hostname'], $remote_device_id, 'discovery'); + } else { + log_event("$method discovery of " . $remote_device['hostname'] . " ($ip) failed - check ping and SNMP access", $device['device_id'], 'discovery'); } return $remote_device_id; } - } - else { + } else { d_echo("$ip not in a matched network - skipping\n"); }//end if +} -}//end discover_new_device() - +//end discover_new_device() -function discover_device($device, $options=null) { +function discover_device($device, $options = null) { global $config, $valid; $valid = array(); @@ -91,20 +86,20 @@ function discover_device($device, $options=null) { $device_start = microtime(true); // Start counting device poll time - echo $device['hostname'].' '.$device['device_id'].' '.$device['os'].' '; + echo $device['hostname'] . ' ' . $device['device_id'] . ' ' . $device['os'] . ' '; if ($device['os'] == 'generic') { // verify if OS has changed from generic $device['os'] = getHostOS($device); if ($device['os'] != 'generic') { - echo "\nDevice os was updated to ".$device['os'].'!'; + echo "\nDevice os was updated to " . $device['os'] . '!'; dbUpdate(array('os' => $device['os']), 'devices', '`device_id` = ?', array($device['device_id'])); } } if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; - echo ' ('.$device['os_group'].')'; + echo ' (' . $device['os_group'] . ')'; } echo "\n"; @@ -116,19 +111,16 @@ function discover_device($device, $options=null) { include "includes/discovery/$module.inc.php"; } } - } - else { + } else { foreach ($config['discovery_modules'] as $module => $module_status) { - if ($attribs['discover_'.$module] || ( $module_status && !isset($attribs['discover_'.$module]))) { + if ($attribs['discover_' . $module] || ( $module_status && !isset($attribs['discover_' . $module]))) { $module_start = microtime(true); - include 'includes/discovery/'.$module.'.inc.php'; + include 'includes/discovery/' . $module . '.inc.php'; $module_time = microtime(true) - $module_start; echo "Runtime for discovery module '$module': $module_time\n"; - } - else if (isset($attribs['discover_'.$module]) && $attribs['discover_'.$module] == '0') { + } else if (isset($attribs['discover_' . $module]) && $attribs['discover_' . $module] == '0') { echo "Module [ $module ] disabled on host.\n"; - } - else { + } else { echo "Module [ $module ] disabled globally.\n"; } } @@ -146,8 +138,8 @@ function discover_device($device, $options=null) { } } - $device_end = microtime(true); - $device_run = ($device_end - $device_start); + $device_end = microtime(true); + $device_run = ($device_end - $device_start); $device_time = substr($device_run, 0, 5); dbUpdate(array('last_discovered' => array('NOW()'), 'type' => $device['type'], 'last_discovered_timetaken' => $device_time), 'devices', '`device_id` = ?', array($device['device_id'])); @@ -158,14 +150,13 @@ function discover_device($device, $options=null) { echo "\n"; $discovered_devices++; +} -}//end discover_device() - - +//end discover_device() // Discover sensors -function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor='1', $multiplier='1', $low_limit=null, $low_warn_limit=null, $warn_limit=null, $high_limit=null, $current=null, $poller_type='snmp', $entPhysicalIndex=null, $entPhysicalIndex_measured=null) { +function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = null, $low_warn_limit = null, $warn_limit = null, $high_limit = null, $current = null, $poller_type = 'snmp', $entPhysicalIndex = null, $entPhysicalIndex_measured = null) { global $config; d_echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $precision, $entPhysicalIndex\n"); @@ -173,9 +164,8 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, if (is_null($low_warn_limit) && !is_null($warn_limit)) { // Warn limits only make sense when we have both a high and a low limit $low_warn_limit = null; - $warn_limit = null; - } - else if ($low_warn_limit > $warn_limit) { + $warn_limit = null; + } else if ($low_warn_limit > $warn_limit) { // Fix high/low thresholds (i.e. on negative numbers) list($warn_limit, $low_warn_limit) = array($low_warn_limit, $warn_limit); } @@ -195,21 +185,21 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, } $insert = array( - 'poller_type' => $poller_type, - 'sensor_class' => $class, - 'device_id' => $device['device_id'], - 'sensor_oid' => $oid, - 'sensor_index' => $index, - 'sensor_type' => $type, - 'sensor_descr' => $descr, - 'sensor_divisor' => $divisor, - 'sensor_multiplier' => $multiplier, - 'sensor_limit' => $high_limit, - 'sensor_limit_warn' => $warn_limit, - 'sensor_limit_low' => $low_limit, - 'sensor_limit_low_warn' => $low_warn_limit, - 'sensor_current' => $current, - 'entPhysicalIndex' => $entPhysicalIndex, + 'poller_type' => $poller_type, + 'sensor_class' => $class, + 'device_id' => $device['device_id'], + 'sensor_oid' => $oid, + 'sensor_index' => $index, + 'sensor_type' => $type, + 'sensor_descr' => $descr, + 'sensor_divisor' => $divisor, + 'sensor_multiplier' => $multiplier, + 'sensor_limit' => $high_limit, + 'sensor_limit_warn' => $warn_limit, + 'sensor_limit_low' => $low_limit, + 'sensor_limit_low_warn' => $low_warn_limit, + 'sensor_current' => $current, + 'entPhysicalIndex' => $entPhysicalIndex, 'entPhysicalIndex_measured' => $entPhysicalIndex_measured, ); @@ -224,17 +214,15 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, d_echo("( $inserted inserted )\n"); echo '+'; - log_event('Sensor Added: '.mres($class).' '.mres($type).' '.mres($index).' '.mres($descr), $device, 'sensor', $inserted); - } - else { + log_event('Sensor Added: ' . mres($class) . ' ' . mres($type) . ' ' . mres($index) . ' ' . mres($descr), $device, 'sensor', $inserted); + } else { $sensor_entry = dbFetchRow('SELECT * FROM `sensors` WHERE `sensor_class` = ? AND `device_id` = ? AND `sensor_type` = ? AND `sensor_index` = ?', array($class, $device['device_id'], $type, $index)); if (!isset($high_limit)) { if (!$sensor_entry['sensor_limit']) { // Calculate a reasonable limit $high_limit = sensor_limit($class, $current); - } - else { + } else { // Use existing limit $high_limit = $sensor_entry['sensor_limit']; } @@ -244,8 +232,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, if (!$sensor_entry['sensor_limit_low']) { // Calculate a reasonable limit $low_limit = sensor_low_limit($class, $current); - } - else { + } else { // Use existing limit $low_limit = $sensor_entry['sensor_limit_low']; } @@ -257,172 +244,169 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, } if ($high_limit != $sensor_entry['sensor_limit'] && $sensor_entry['sensor_custom'] == 'No') { - $update = array('sensor_limit' => ($high_limit == null ? array('NULL') : $high_limit)); + $update = array('sensor_limit' => ($high_limit == null ? array('NULL') : $high_limit)); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); d_echo("( $updated updated )\n"); echo 'H'; - log_event('Sensor High Limit Updated: '.mres($class).' '.mres($type).' '.mres($index).' '.mres($descr).' ('.$high_limit.')', $device, 'sensor', $sensor_id); + log_event('Sensor High Limit Updated: ' . mres($class) . ' ' . mres($type) . ' ' . mres($index) . ' ' . mres($descr) . ' (' . $high_limit . ')', $device, 'sensor', $sensor_id); } if ($sensor_entry['sensor_limit_low'] != $low_limit && $sensor_entry['sensor_custom'] == 'No') { - $update = array('sensor_limit_low' => ($low_limit == null ? array('NULL') : $low_limit)); + $update = array('sensor_limit_low' => ($low_limit == null ? array('NULL') : $low_limit)); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); d_echo("( $updated updated )\n"); echo 'L'; - log_event('Sensor Low Limit Updated: '.mres($class).' '.mres($type).' '.mres($index).' '.mres($descr).' ('.$low_limit.')', $device, 'sensor', $sensor_id); + log_event('Sensor Low Limit Updated: ' . mres($class) . ' ' . mres($type) . ' ' . mres($index) . ' ' . mres($descr) . ' (' . $low_limit . ')', $device, 'sensor', $sensor_id); } if ($warn_limit != $sensor_entry['sensor_limit_warn'] && $sensor_entry['sensor_custom'] == 'No') { - $update = array('sensor_limit_warn' => ($warn_limit == null ? array('NULL') : $warn_limit)); + $update = array('sensor_limit_warn' => ($warn_limit == null ? array('NULL') : $warn_limit)); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); d_echo("( $updated updated )\n"); echo 'WH'; - log_event('Sensor Warn High Limit Updated: '.mres($class).' '.mres($type).' '.mres($index).' '.mres($descr).' ('.$warn_limit.')', $device, 'sensor', $sensor_id); + log_event('Sensor Warn High Limit Updated: ' . mres($class) . ' ' . mres($type) . ' ' . mres($index) . ' ' . mres($descr) . ' (' . $warn_limit . ')', $device, 'sensor', $sensor_id); } if ($sensor_entry['sensor_limit_low_warn'] != $low_warn_limit && $sensor_entry['sensor_custom'] == 'No') { - $update = array('sensor_limit_low_warn' => ($low_warn_limit == null ? array('NULL') : $low_warn_limit)); + $update = array('sensor_limit_low_warn' => ($low_warn_limit == null ? array('NULL') : $low_warn_limit)); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); d_echo("( $updated updated )\n"); echo 'WL'; - log_event('Sensor Warn Low Limit Updated: '.mres($class).' '.mres($type).' '.mres($index).' '.mres($descr).' ('.$low_warn_limit.')', $device, 'sensor', $sensor_id); + log_event('Sensor Warn Low Limit Updated: ' . mres($class) . ' ' . mres($type) . ' ' . mres($index) . ' ' . mres($descr) . ' (' . $low_warn_limit . ')', $device, 'sensor', $sensor_id); } if ($oid == $sensor_entry['sensor_oid'] && $descr == $sensor_entry['sensor_descr'] && $multiplier == $sensor_entry['sensor_multiplier'] && $divisor == $sensor_entry['sensor_divisor'] && $entPhysicalIndex_measured == $sensor_entry['entPhysicalIndex_measured'] && $entPhysicalIndex == $sensor_entry['entPhysicalIndex']) { echo '.'; - } - else { - $update = array( - 'sensor_oid' => $oid, - 'sensor_descr' => $descr, - 'sensor_multiplier' => $multiplier, - 'sensor_divisor' => $divisor, - 'entPhysicalIndex' => $entPhysicalIndex, + } else { + $update = array( + 'sensor_oid' => $oid, + 'sensor_descr' => $descr, + 'sensor_multiplier' => $multiplier, + 'sensor_divisor' => $divisor, + 'entPhysicalIndex' => $entPhysicalIndex, 'entPhysicalIndex_measured' => $entPhysicalIndex_measured, ); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); echo 'U'; - log_event('Sensor Updated: '.mres($class).' '.mres($type).' '.mres($index).' '.mres($descr), $device, 'sensor', $sensor_id); + log_event('Sensor Updated: ' . mres($class) . ' ' . mres($type) . ' ' . mres($index) . ' ' . mres($descr), $device, 'sensor', $sensor_id); d_echo("( $updated updated )\n"); } }//end if $valid[$class][$type][$index] = 1; +} -}//end discover_sensor() - +//end discover_sensor() function sensor_low_limit($class, $current) { $limit = null; switch ($class) { - case 'temperature': - $limit = ($current * 0.7); - break; - - case 'voltage': - if ($current < 0) { - $limit = ($current * (1 + (sgn($current) * 0.15))); - } - else { - $limit = ($current * (1 - (sgn($current) * 0.15))); - } - break; + case 'temperature': + $limit = ($current * 0.7); + break; + + case 'voltage': + if ($current < 0) { + $limit = ($current * (1 + (sgn($current) * 0.15))); + } else { + $limit = ($current * (1 - (sgn($current) * 0.15))); + } + break; - case 'humidity': - $limit = '70'; - break; + case 'humidity': + $limit = '70'; + break; - case 'frequency': - $limit = ($current * 0.95); - break; + case 'frequency': + $limit = ($current * 0.95); + break; - case 'current': - $limit = null; - break; + case 'current': + $limit = null; + break; - case 'fanspeed': - $limit = ($current * 0.80); - break; + case 'fanspeed': + $limit = ($current * 0.80); + break; - case 'power': - $limit = null; - break; + case 'power': + $limit = null; + break; }//end switch return $limit; +} -}//end sensor_low_limit() - +//end sensor_low_limit() function sensor_limit($class, $current) { $limit = null; switch ($class) { - case 'temperature': - $limit = ($current * 1.60); - break; - - case 'voltage': - if ($current < 0) { - $limit = ($current * (1 - (sgn($current) * 0.15))); - } - else { - $limit = ($current * (1 + (sgn($current) * 0.15))); - } - break; + case 'temperature': + $limit = ($current * 1.60); + break; + + case 'voltage': + if ($current < 0) { + $limit = ($current * (1 - (sgn($current) * 0.15))); + } else { + $limit = ($current * (1 + (sgn($current) * 0.15))); + } + break; - case 'humidity': - $limit = '70'; - break; + case 'humidity': + $limit = '70'; + break; - case 'frequency': - $limit = ($current * 1.05); - break; + case 'frequency': + $limit = ($current * 1.05); + break; - case 'current': - $limit = ($current * 1.50); - break; + case 'current': + $limit = ($current * 1.50); + break; - case 'fanspeed': - $limit = ($current * 1.80); - break; + case 'fanspeed': + $limit = ($current * 1.80); + break; - case 'power': - $limit = ($current * 1.50); - break; + case 'power': + $limit = ($current * 1.50); + break; }//end switch return $limit; +} -}//end sensor_limit() - +//end sensor_limit() -function check_valid_sensors($device, $class, $valid, $poller_type='snmp') { +function check_valid_sensors($device, $class, $valid, $poller_type = 'snmp') { $entries = dbFetchRows('SELECT * FROM sensors AS S, devices AS D WHERE S.sensor_class=? AND S.device_id = D.device_id AND D.device_id = ? AND S.poller_type = ?', array($class, $device['device_id'], $poller_type)); if (count($entries)) { foreach ($entries as $entry) { $index = $entry['sensor_index']; - $type = $entry['sensor_type']; - d_echo($index.' -> '.$type."\n"); + $type = $entry['sensor_type']; + d_echo($index . ' -> ' . $type . "\n"); if (!$valid[$class][$type][$index]) { echo '-'; dbDelete('sensors', '`sensor_id` = ?', array($entry['sensor_id'])); - log_event('Sensor Deleted: '.$entry['sensor_class'].' '.$entry['sensor_type'].' '.$entry['sensor_index'].' '.$entry['sensor_descr'], $device, 'sensor', $sensor_id); + log_event('Sensor Deleted: ' . $entry['sensor_class'] . ' ' . $entry['sensor_type'] . ' ' . $entry['sensor_index'] . ' ' . $entry['sensor_descr'], $device, 'sensor', $sensor_id); } unset($oid); unset($type); } } +} -}//end check_valid_sensors() - +//end check_valid_sensors() function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr) { global $config; @@ -432,16 +416,15 @@ function discover_juniAtmVp(&$valid, $port_id, $vp_id, $vp_descr) { d_echo("( $inserted inserted )\n"); // FIXME vv no $device! - log_event('Juniper ATM VP Added: port '.mres($port_id).' vp '.mres($vp_id).' descr'.mres($vp_descr), 'juniAtmVp', $inserted); - } - else { + log_event('Juniper ATM VP Added: port ' . mres($port_id) . ' vp ' . mres($vp_id) . ' descr' . mres($vp_descr), 'juniAtmVp', $inserted); + } else { echo '.'; } $valid[$port_id][$vp_id] = 1; +} -}//end discover_juniAtmVp() - +//end discover_juniAtmVp() function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version, $local_device_id, $remote_device_id) { global $config, $link_exists; @@ -449,23 +432,22 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn d_echo("$local_port_id, $protocol, $remote_port_id, $remote_hostname, $remote_port, $remote_platform, $remote_version"); if (dbFetchCell( - 'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?', - array( - $remote_hostname, - $local_port_id, - $protocol, - $remote_port, - ) - ) == '0') { + 'SELECT COUNT(*) FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?', array( + $remote_hostname, + $local_port_id, + $protocol, + $remote_port, + ) + ) == '0') { $insert_data = array( - 'local_port_id' => $local_port_id, - 'local_device_id' => $local_device_id, - 'protocol' => $protocol, - 'remote_hostname' => $remote_hostname, + 'local_port_id' => $local_port_id, + 'local_device_id' => $local_device_id, + 'protocol' => $protocol, + 'remote_hostname' => $remote_hostname, 'remote_device_id' => $remote_device_id, - 'remote_port' => $remote_port, - 'remote_platform' => $remote_platform, - 'remote_version' => $remote_version, + 'remote_port' => $remote_port, + 'remote_platform' => $remote_platform, + 'remote_version' => $remote_version, ); if (!empty($remote_port_id)) { @@ -476,18 +458,16 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn echo '+'; d_echo("( $inserted inserted )"); - } - else { + } else { $data = dbFetchRow('SELECT * FROM `links` WHERE `remote_hostname` = ? AND `local_port_id` = ? AND `protocol` = ? AND `remote_port` = ?', array($remote_hostname, $local_port_id, $protocol, $remote_port)); if ($data['remote_port_id'] == $remote_port_id && $data['remote_platform'] == $remote_platform && $remote_version == $remote_version && $data['local_device_id'] > 0 && $data['remote_device_id'] > 0) { echo '.'; - } - else { + } else { $update_data = array( - 'remote_platform' => $remote_platform, - 'remote_version' => $remote_version, - 'remote_version' => $remote_version, - 'local_device_id' => $local_device_id, + 'remote_platform' => $remote_platform, + 'remote_version' => $remote_version, + 'remote_version' => $remote_version, + 'local_device_id' => $local_device_id, 'remote_device_id' => $remote_device_id, ); @@ -501,11 +481,11 @@ function discover_link($local_port_id, $protocol, $remote_port_id, $remote_hostn }//end if }//end if $link_exists[$local_port_id][$remote_hostname][$remote_port] = 1; +} -}//end discover_link() - +//end discover_link() -function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, $units, $used=null) { +function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, $units, $used = null) { global $config; d_echo("$device, $index, $type, $mib, $descr, $units, $used, $size\n"); @@ -514,38 +494,35 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, $storage = dbFetchRow('SELECT * FROM `storage` WHERE `storage_index` = ? AND `device_id` = ? AND `storage_mib` = ?', array($index, $device['device_id'], $mib)); if ($storage === false || !count($storage)) { $insert = dbInsert( - array( - 'device_id' => $device['device_id'], - 'storage_descr' => $descr, - 'storage_index' => $index, - 'storage_mib' => $mib, - 'storage_type' => $type, - 'storage_units' => $units, - 'storage_size' => $size, - 'storage_used' => $used, - ), - 'storage' + array( + 'device_id' => $device['device_id'], + 'storage_descr' => $descr, + 'storage_index' => $index, + 'storage_mib' => $mib, + 'storage_type' => $type, + 'storage_units' => $units, + 'storage_size' => $size, + 'storage_used' => $used, + ), 'storage' ); echo '+'; - } - else { + } else { $updated = dbUpdate(array('storage_descr' => $descr, 'storage_type' => $type, 'storage_units' => $units, 'storage_size' => $size), 'storage', '`device_id` = ? AND `storage_index` = ? AND `storage_mib` = ?', array($device['device_id'], $index, $mib)); if ($updated) { echo 'U'; - } - else { + } else { echo '.'; } }//end if $valid[$mib][$index] = 1; }//end if +} -}//end discover_storage() - +//end discover_storage() -function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $precision='1', $current=null, $entPhysicalIndex=null, $hrDeviceIndex=null) { +function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $precision = '1', $current = null, $entPhysicalIndex = null, $hrDeviceIndex = null) { global $config; d_echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); @@ -554,12 +531,12 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec $descr = trim(str_replace('"', '', $descr)); if (dbFetchCell('SELECT COUNT(processor_id) FROM `processors` WHERE `processor_index` = ? AND `device_id` = ? AND `processor_type` = ?', array($index, $device['device_id'], $type)) == '0') { $insert_data = array( - 'device_id' => $device['device_id'], - 'processor_descr' => $descr, - 'processor_index' => $index, - 'processor_oid' => $oid, - 'processor_usage' => $current, - 'processor_type' => $type, + 'device_id' => $device['device_id'], + 'processor_descr' => $descr, + 'processor_index' => $index, + 'processor_oid' => $oid, + 'processor_usage' => $current, + 'processor_type' => $type, 'processor_precision' => $precision, ); if (!empty($hrDeviceIndex)) { @@ -572,25 +549,24 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec $inserted = dbInsert($insert_data, 'processors'); echo '+'; - log_event('Processor added: type '.mres($type).' index '.mres($index).' descr '.mres($descr), $device, 'processor', $inserted); - } - else { + log_event('Processor added: type ' . mres($type) . ' index ' . mres($index) . ' descr ' . mres($descr), $device, 'processor', $inserted); + } else { echo '.'; $update_data = array( - 'processor_descr' => $descr, - 'processor_oid' => $oid, - 'processor_usage' => $current, + 'processor_descr' => $descr, + 'processor_oid' => $oid, + 'processor_usage' => $current, 'processor_precision' => $precision, ); dbUpdate($update_data, 'processors', '`device_id`=? AND `processor_index`=? AND `processor_type`=?', array($device['device_id'], $index, $type)); }//end if $valid[$type][$index] = 1; }//end if +} -}//end discover_processor() - +//end discover_processor() -function discover_mempool(&$valid, $device, $index, $type, $descr, $precision='1', $entPhysicalIndex=null, $hrDeviceIndex=null) { +function discover_mempool(&$valid, $device, $index, $type, $descr, $precision = '1', $entPhysicalIndex = null, $hrDeviceIndex = null) { global $config; d_echo("$device, $oid, $index, $type, $descr, $precision, $current, $entPhysicalIndex, $hrDeviceIndex\n"); @@ -599,15 +575,15 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision='1 if ($descr) { if (dbFetchCell('SELECT COUNT(mempool_id) FROM `mempools` WHERE `mempool_index` = ? AND `device_id` = ? AND `mempool_type` = ?', array($index, $device['device_id'], $type)) == '0') { $insert_data = array( - 'device_id' => $device['device_id'], - 'mempool_descr' => $descr, - 'mempool_index' => $index, - 'mempool_type' => $type, + 'device_id' => $device['device_id'], + 'mempool_descr' => $descr, + 'mempool_index' => $index, + 'mempool_type' => $type, 'mempool_precision' => $precision, - 'mempool_perc' => 0, - 'mempool_used' => 0, - 'mempool_free' => 0, - 'mempool_total' => 0, + 'mempool_perc' => 0, + 'mempool_used' => 0, + 'mempool_free' => 0, + 'mempool_total' => 0, ); if (!empty($entPhysicalIndex)) { @@ -620,9 +596,8 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision='1 $inserted = dbInsert($insert_data, 'mempools'); echo '+'; - log_event('Memory pool added: type '.mres($type).' index '.mres($index).' descr '.mres($descr), $device, 'mempool', $inserted); - } - else { + log_event('Memory pool added: type ' . mres($type) . ' index ' . mres($index) . ' descr ' . mres($descr), $device, 'mempool', $inserted); + } else { echo '.'; $update_data = array( 'mempool_descr' => $descr, @@ -640,11 +615,11 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision='1 }//end if $valid[$type][$index] = 1; }//end if +} -}//end discover_mempool() - +//end discover_mempool() -function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity_oid=null, $capacity=null, $current=null) { +function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity_oid = null, $capacity = null, $current = null) { global $config; d_echo("$oid, $index, $type, $descr, $capacity, $capacity_oid\n"); @@ -652,28 +627,26 @@ function discover_toner(&$valid, $device, $oid, $index, $type, $descr, $capacity if (dbFetchCell('SELECT COUNT(toner_id) FROM `toner` WHERE device_id = ? AND toner_type = ? AND `toner_index` = ? AND `toner_capacity_oid` =?', array($device['device_id'], $type, $index, $capacity_oid)) == '0') { $inserted = dbInsert(array('device_id' => $device['device_id'], 'toner_oid' => $oid, 'toner_capacity_oid' => $capacity_oid, 'toner_index' => $index, 'toner_type' => $type, 'toner_descr' => $descr, 'toner_capacity' => $capacity, 'toner_current' => $current), 'toner'); echo '+'; - log_event('Toner added: type '.mres($type).' index '.mres($index).' descr '.mres($descr), $device, 'toner', $inserted); - } - else { + log_event('Toner added: type ' . mres($type) . ' index ' . mres($index) . ' descr ' . mres($descr), $device, 'toner', $inserted); + } else { $toner_entry = dbFetchRow('SELECT * FROM `toner` WHERE `device_id` = ? AND `toner_type` = ? AND `toner_index` =?', array($device['device_id'], $type, $index)); if ($oid == $toner_entry['toner_oid'] && $descr == $toner_entry['toner_descr'] && $capacity == $toner_entry['toner_capacity'] && $capacity_oid == $toner_entry['toner_capacity_oid']) { echo '.'; - } - else { + } else { dbUpdate(array('toner_descr' => $descr, 'toner_oid' => $oid, 'toner_capacity_oid' => $capacity_oid, 'toner_capacity' => $capacity), 'toner', 'device_id=? AND toner_type=? AND `toner_index`=?', array($device['device_id'], $type, $index)); echo 'U'; } } $valid[$type][$index] = 1; +} -}//end discover_toner() +//end discover_toner() - -function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name='') { - global $device,$config; +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; + $ipv6_network = Net_IPv6::getNetmask("$ipv6_address/$ipv6_prefixlen") . '/' . $ipv6_prefixlen; $ipv6_compressed = Net_IPv6::compress($ipv6_address); if (Net_IPv6::getAddressType($ipv6_address) == NET_IPV6_LOCAL_LINK) { @@ -683,30 +656,32 @@ 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` = ? 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` = ? AND `context_name` = ?', array($ipv6_network, $context_name)) < '1') { + if (dbFetchCell('SELECT COUNT(*) FROM `ipv6_networks` WHERE `ipv6_network` = ?', array($ipv6_network)) < '1') { dbInsert(array('ipv6_network' => $ipv6_network, 'context_name' => $context_name), 'ipv6_networks'); echo 'N'; + } else { + //Update Context + dbUpdate(array('context_name' => $device['context_name']), 'ipv6_network', '`ipv6_network` = ?', array($ipv6_network)); + echo 'n'; } + $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` = ? 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'); + 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, 'context_name' => $context_name), 'ipv6_addresses'); echo '+'; - } - else { + } else { + //Update Context + dbUpdate(array('context_name' => $device['context_name']), 'ipv6_address', '`ipv6_address` = ? AND `ipv6_prefixlen` = ? AND `port_id` = ?', array($ipv6_address, $ipv6_prefixlen, $port_id)); echo '.'; } - $full_address = "$ipv6_address/$ipv6_prefixlen"; - $valid_address = $full_address.'-'.$port_id; + $full_address = "$ipv6_address/$ipv6_prefixlen"; + $valid_address = $full_address . '-' . $port_id; $valid['ipv6'][$valid_address] = 1; }//end if +} -}//end discover_process_ipv6() +//end discover_process_ipv6() diff --git a/includes/discovery/ipv4-addresses.inc.php b/includes/discovery/ipv4-addresses.inc.php index f930b8fd3c0c..441b82874735 100644 --- a/includes/discovery/ipv4-addresses.inc.php +++ b/includes/discovery/ipv4-addresses.inc.php @@ -23,20 +23,27 @@ 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') { + if (dbFetchCell('SELECT COUNT(*) FROM `ipv4_networks` WHERE `ipv4_network` = ?', array($network)) < '1') { dbInsert(array('ipv4_network' => $network,'context_name' => $device['context_name']), 'ipv4_networks'); // echo("Create Subnet $network\n"); echo 'S'; } + else { + //Update Context + dbUpdate(array('context_name' => $device['context_name']), 'ipv4_networks', '`ipv4_network` = ?', array($network) ); + echo 's'; + } - $ipv4_network_id = dbFetchCell('SELECT `ipv4_network_id` FROM `ipv4_networks` WHERE `ipv4_network` = ? and `context_name`= ?', array($network, $device['context_name'])); + $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` = ? 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'); + 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, 'context_name' => $device['context_name']), 'ipv4_addresses'); // echo("Added $oid/$cidr to $port_id ( $hostname $ifIndex )\n $i_query\n"); echo '+'; } else { + //Update Context + dbUpdate(array('context_name' => $device['context_name']), 'ipv4_addresses', 'ipv4_address` = ? AND `ipv4_prefixlen` = ? AND `port_id` = ?',array($oid, $cidr, $port_id) ); echo '.'; } @@ -48,7 +55,7 @@ }//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'] . "'"; + $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']; diff --git a/includes/discovery/ipv6-addresses.inc.php b/includes/discovery/ipv6-addresses.inc.php index fb9864020844..617c003e19e9 100644 --- a/includes/discovery/ipv6-addresses.inc.php +++ b/includes/discovery/ipv6-addresses.inc.php @@ -68,7 +68,7 @@ } //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'] . "'"; + $sql = "SELECT * FROM ipv6_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['ipv6_address'].'/'.$row['ipv6_prefixlen']; From cfee15f5a4de138dc22f0a01cebec53c0cd43942 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Tue, 2 Feb 2016 12:58:34 +0100 Subject: [PATCH 36/37] update Authors --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 1aa5c18ff900..e2316ae41e37 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -83,6 +83,7 @@ LibreNMS contributors: - Maximilian Wilhelm (BarbarossaTM) - Jameson Finney (JamesonFinney) - John Wells (jbwiv) +- Henoc Khouilla (henocKA) [1]: http://observium.org/ "Observium web site" Observium was written by: From 6a51746bb7b3a2ad4a65b2b0f2f9c8e2f478d0d3 Mon Sep 17 00:00:00 2001 From: HenocKA Date: Wed, 10 Feb 2016 17:45:05 +0100 Subject: [PATCH 37/37] bug correction --- includes/discovery/functions.inc.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 4848dd94f0fb..c7fcfb874a92 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -682,7 +682,6 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen $valid_address = $full_address . '-' . $port_id; $valid['ipv6'][$valid_address] = 1; }//end if -} }//end discover_process_ipv6()