예제 #1
0
        /// <inheritdoc />
        public override bool IsApplicableSnmp(ISnmpLowerLayer snmpLowerLayer, IQuerierOptions options)
        {
            var description = snmpLowerLayer?.SystemData?.Description;

            if (string.IsNullOrWhiteSpace(description))
            {
                var info = $"Description in system data of device '{snmpLowerLayer.Address}' is null, empty or white-space-only: Assuming the device is not a Ubiquiti device";
                log.Warn(info);
                this.CollectException("UbntSnmp: No device description", new HamnetSnmpException(info));
                return(false);
            }

            if (!description.Contains(PossiblyUbiquitiDetectionDescriptionString))
            {
                var info = $"Description in system data of device '{snmpLowerLayer.Address}' doesn't contain string '{PossiblyUbiquitiDetectionDescriptionString}': Assuming the device is not a Ubiquiti device";
                log.Info(info);
                this.CollectException("UbntSnmp: No UBNT-like string in device description", new HamnetSnmpException(info));
                return(false);
            }

            var ubntManufacturer = snmpLowerLayer?.DoWalk(UbntManufacturerDetectionOid);

            if ((ubntManufacturer == null) || (ubntManufacturer.Count == 0))
            {
                var info = $"UBNT Manufacturer ID string of device '{snmpLowerLayer.Address}' is null or empty: The device could still be AirFiber";
                log.Warn(info);
                this.CollectException("UbntSnmp: No UBNT manufacturer detection OID", new HamnetSnmpException(info));
                return(this.DetectAirFiber(snmpLowerLayer));
            }

            var manufacturer = ubntManufacturer.FirstOrDefault(m => m.Value.ToString().Contains(UbiquitiManufactorerDetectionString));

            if (manufacturer == null)
            {
                var info = $"UBNT Manufacturer ID string of device '{snmpLowerLayer.Address}' doesn't contain string '{UbiquitiManufactorerDetectionString}': Assuming the device is not a Ubiquiti device";
                log.Info(info);
                this.CollectException("UbntSnmp: No UBNT manufacturer", new HamnetSnmpException(info));
                return(false);
            }

            this.detectionId = manufacturer.Oid[manufacturer.Oid.Length - 1];

            log.Info($"Device '{snmpLowerLayer.Address}' seems to be a Ubiquiti device (detection ID {this.detectionId})");

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Detects an AirFiber device which does not really provide any manufacturer ID or similar
        /// </summary>
        /// <param name="snmpLowerLayer">The lower communication layer to user.</param>
        /// <returns><c>true</c> if an AirFiber device has been detected and the class fields have been set accordingly.</returns>
        private bool DetectAirFiber(ISnmpLowerLayer snmpLowerLayer)
        {
            var mibInfo41112 = snmpLowerLayer.DoWalk(AirFiberDetectionWalkRootOid);

            if (mibInfo41112.Count == 0)
            {
                // it's also not an AirFiber device
                log.Info($"Reading of OS version of device '{snmpLowerLayer.Address}' via AirFiber OID {AirFiberDetectionWalkRootOid} didn't reveal anything: Assuming the device is not an Ubiquiti AirFiber device");
                return(false);
            }

            // never seen AirFiber returning more than one
            var firstValue = mibInfo41112.First();

            this.osDetectedVersion = firstValue.Value.ToString();
            this.detectionId       = firstValue.Oid.Last();
            this.detectedModel     = AirFiberFakeModelString;

            return(true);
        }