/// <summary> /// If we don't have a regex that combines Model and Version, we use this routine to check various other models /// Including Fixed, Regex and SNMP methods for fetching valid Model/Version /// </summary> /// <param name="modelCheck"></param> /// <param name="address"></param> /// <param name="config"></param> /// <returns></returns> private (string model, string version) altSysVersionChecks(ModelCheck modelCheck, IPAddressValue address, Configuration config) { var model = ""; var version = ""; // Use a fixed model (worst case) if (modelCheck.ModelFixed != "") { model = modelCheck.ModelFixed; } // Use a fixed Version (why would we want to, but oh well) if (modelCheck.VersionFixed != "") { model = modelCheck.VersionFixed; } // Use a custom regex of sysVersion to grab Version if (modelCheck.ModelRegex != "") { Regex r = new Regex(modelCheck.ModelRegex, RegexOptions.IgnoreCase); var mR = r.Matches(SysVersion); if (mR.Count > 0) { model = mR[0].Groups["Model"].Value; } } // Use a custom regex of sysVersion to grab Version if (modelCheck.VersionRegex != "") { Regex r = new Regex(modelCheck.VersionRegex, RegexOptions.IgnoreCase); var mR = r.Matches(SysVersion); if (mR.Count > 0) { version = mR[0].Groups["Version"].Value; } } // Fetch Model/Version from SNMP directly if it's set if (modelCheck.ModelSnmp != "" || modelCheck.VersionSnmp != "") { var snmp = new SnmpTools(config); // Grab Model from SNMP if it's supplied if (modelCheck.ModelSnmp != "") { model = snmp.GetSnmpStringWithFallback(address, modelCheck.ModelSnmp); } // Grab Version from SNMP if it's supplied if (modelCheck.VersionSnmp != "") { version = snmp.GetSnmpStringWithFallback(address, modelCheck.VersionSnmp); } } return(model, version); }
/// <summary> /// Fetch all active ip's snmp and return a an array of Device[] /// with progress indicators for CLI mode /// </summary> /// <param name="ActiveIPs"></param> /// <returns></returns> private static Device[] fetchSNMPWithProgress(IPAddressValue[] ActiveIPs) { Device[] DeviceResults; using (var progress = new ProgressBar()) { Console.WriteLine("Checking SNMP for Active IPs... "); var snmp = new SnmpTools(_config); DeviceResults = snmp.GetSnmpDevicesParallel(ActiveIPs, progress); } Console.WriteLine($"Total valid SNMP Responses: {DeviceResults.Where(r => String.IsNullOrWhiteSpace(r.Errors)).ToArray<Device>().Count()}"); Console.WriteLine(); return(DeviceResults); }