// Token: 0x06000242 RID: 578 RVA: 0x0000FD17 File Offset: 0x0000DF17
 internal void InsertDetectedPollers(BackgroundInventoryManager.InventoryTask task, List <string> detectedPollers)
 {
     if (detectedPollers.Count > 0)
     {
         this.pollersDAL.UpdateNetObjectPollers("N", task.NodeID, detectedPollers.ToArray());
     }
 }
Esempio n. 2
0
        internal void DoInventory(BackgroundInventoryManager.InventoryTask task)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            Node      node      = NodeBLDAL.GetNode(task.NodeID);

            if (node == null || node.get_PolledStatus() != 1)
            {
                BackgroundInventoryManager.log.InfoFormat("Skipping inventorying of Node {0}, status is not UP.", (object)task.NodeID);
            }
            else
            {
                SnmpSettings snmpSettings = new SnmpSettings();
                snmpSettings.set_AgentPort((int)node.get_SNMPPort());
                snmpSettings.set_ProtocolVersion((SNMPVersion)node.get_SNMPVersion());
                snmpSettings.set_TargetIP(IPAddress.Parse(node.get_IpAddress()));
                SnmpSettings          nodeSettings        = snmpSettings;
                SnmpInventorySettings inventorySettings   = new SnmpInventorySettings(node.get_SysObjectID());
                SnmpCredentials       credentialsFromNode = CredentialHelper.ParseCredentialsFromNode(node) as SnmpCredentials;
                List <string>         detectedPollers     = new List <string>();
                if (BackgroundInventoryManager.log.get_IsInfoEnabled())
                {
                    BackgroundInventoryManager.log.InfoFormat("Starting inventorying of Node {0}, NeedsInventory = '{1}'", (object)task.NodeID, (object)task.Settings);
                }
                string[]      array          = ((IEnumerable <string>)task.Settings.Split(':')).Distinct <string>().ToArray <string>();
                List <string> failedTasks    = new List <string>();
                List <string> completedTasks = new List <string>();
                foreach (string key in array)
                {
                    if (!this.inventories.ContainsKey(key))
                    {
                        failedTasks.Add(key);
                        if (BackgroundInventoryManager.log.get_IsErrorEnabled())
                        {
                            BackgroundInventoryManager.log.ErrorFormat("Unable to inventory '{0}' on Node {1}", (object)key, (object)task.NodeID);
                        }
                    }
                    else
                    {
                        if (this.scheduler.IsTaskCanceled)
                        {
                            if (BackgroundInventoryManager.log.get_IsInfoEnabled())
                            {
                                BackgroundInventoryManager.log.InfoFormat("Inventorying of Node {0} was canceled. ElapsedTime = {1}", (object)task.NodeID, (object)stopwatch.ElapsedMilliseconds);
                            }
                            stopwatch.Stop();
                            return;
                        }
                        InventoryPollersResult inventoryPollersResult = this.inventories[key](nodeSettings, inventorySettings, credentialsFromNode);
                        if (inventoryPollersResult == null)
                        {
                            failedTasks.Add(key);
                            if (BackgroundInventoryManager.log.get_IsErrorEnabled())
                            {
                                BackgroundInventoryManager.log.ErrorFormat("Inventory '{0}' on Node {1} returned null result", (object)key, (object)task.NodeID);
                            }
                        }
                        else if (((InventoryResultBase)inventoryPollersResult).get_Outcome() == 1)
                        {
                            completedTasks.Add(key);
                            detectedPollers.AddRange((IEnumerable <string>)inventoryPollersResult.get_PollerTypes());
                        }
                        else
                        {
                            failedTasks.Add(key);
                            if (((InventoryResultBase)inventoryPollersResult).get_Error() != null)
                            {
                                if (BackgroundInventoryManager.log.get_IsWarnEnabled())
                                {
                                    BackgroundInventoryManager.log.WarnFormat("Inventory '{0}' on Node {1} failed with code {2}", (object)key, (object)task.NodeID, (object)((InventoryResultBase)inventoryPollersResult).get_Error().get_ErrorCode());
                                }
                                if (((InventoryResultBase)inventoryPollersResult).get_Error().get_ErrorCode() != 31002U)
                                {
                                    List <string> list = ((IEnumerable <string>)array).Where <string>((Func <string, bool>)(n => !completedTasks.Contains(n) && !failedTasks.Contains(n))).ToList <string>();
                                    if (list.Count > 0)
                                    {
                                        failedTasks.AddRange((IEnumerable <string>)list);
                                        if (BackgroundInventoryManager.log.get_IsWarnEnabled())
                                        {
                                            BackgroundInventoryManager.log.WarnFormat("Skipping inventory for '{0}' on Node {1}", (object)string.Join(":", list.ToArray()), (object)task.NodeID);
                                            break;
                                        }
                                        break;
                                    }
                                }
                            }
                            else if (BackgroundInventoryManager.log.get_IsWarnEnabled())
                            {
                                BackgroundInventoryManager.log.WarnFormat("Inventory '{0}' on Node {1} failed on unknown error", (object)key, (object)task.NodeID);
                            }
                        }
                    }
                }
                string lastNodeSettings = NodeSettingsDAL.GetLastNodeSettings(task.NodeID, (string)CoreConstants.NeedsInventoryFlag);
                if ((string.IsNullOrEmpty(lastNodeSettings) || !lastNodeSettings.Equals(task.Settings, StringComparison.OrdinalIgnoreCase)) && BackgroundInventoryManager.log.get_IsInfoEnabled())
                {
                    BackgroundInventoryManager.log.InfoFormat("Skipping inventory result processing for Node {0}, NeedsInventory flag changed. OldValue = '{1}', NewValue = '{2}'.", (object)task.NodeID, (object)task.Settings, (object)lastNodeSettings);
                }
                else
                {
                    this.InsertDetectedPollers(task, detectedPollers);
                    if (failedTasks.Count == 0)
                    {
                        NodeSettingsDAL.DeleteSpecificSettingForNode(task.NodeID, (string)CoreConstants.NeedsInventoryFlag);
                        if (BackgroundInventoryManager.log.get_IsInfoEnabled())
                        {
                            BackgroundInventoryManager.log.InfoFormat("Inventorying of Node {0} completed in {1}ms.", (object)task.NodeID, (object)stopwatch.ElapsedMilliseconds);
                        }
                    }
                    else if (failedTasks.Count < array.Length)
                    {
                        string str = string.Join(":", failedTasks.ToArray());
                        NodeSettingsDAL.SafeInsertNodeSetting(task.NodeID, (string)CoreConstants.NeedsInventoryFlag, (object)str);
                        if (BackgroundInventoryManager.log.get_IsInfoEnabled())
                        {
                            BackgroundInventoryManager.log.InfoFormat("Inventorying of Node {0} partially completed in {1}ms. NeedsInventory updated to '{2}'", (object)task.NodeID, (object)stopwatch.ElapsedMilliseconds, (object)str);
                        }
                    }
                    else if (BackgroundInventoryManager.log.get_IsInfoEnabled())
                    {
                        BackgroundInventoryManager.log.InfoFormat("Inventorying of Node {0} failed. Elapsed time {1}ms.", (object)task.NodeID, (object)stopwatch.ElapsedMilliseconds);
                    }
                    stopwatch.Stop();
                }
            }
        }
        // Token: 0x06000241 RID: 577 RVA: 0x0000F870 File Offset: 0x0000DA70
        internal void DoInventory(BackgroundInventoryManager.InventoryTask task)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            Node      node      = NodeBLDAL.GetNode(task.NodeID);

            if (node == null || node.PolledStatus != 1)
            {
                BackgroundInventoryManager.log.InfoFormat("Skipping inventorying of Node {0}, status is not UP.", task.NodeID);
                return;
            }
            SnmpSettings nodeSettings = new SnmpSettings
            {
                AgentPort       = (int)node.SNMPPort,
                ProtocolVersion = node.SNMPVersion,
                TargetIP        = IPAddress.Parse(node.IpAddress)
            };
            SnmpInventorySettings inventorySettings = new SnmpInventorySettings(node.SysObjectID);
            SnmpCredentials       credentials       = CredentialHelper.ParseCredentialsFromNode(node) as SnmpCredentials;
            List <string>         list = new List <string>();

            if (BackgroundInventoryManager.log.IsInfoEnabled)
            {
                BackgroundInventoryManager.log.InfoFormat("Starting inventorying of Node {0}, NeedsInventory = '{1}'", task.NodeID, task.Settings);
            }
            string[] array = task.Settings.Split(new char[]
            {
                ':'
            }).Distinct <string>().ToArray <string>();
            List <string> failedTasks    = new List <string>();
            List <string> completedTasks = new List <string>();

            Func <string, bool> < > 9__0;
            foreach (string text in array)
            {
                if (!this.inventories.ContainsKey(text))
                {
                    failedTasks.Add(text);
                    if (BackgroundInventoryManager.log.IsErrorEnabled)
                    {
                        BackgroundInventoryManager.log.ErrorFormat("Unable to inventory '{0}' on Node {1}", text, task.NodeID);
                    }
                }
                else
                {
                    if (this.scheduler.IsTaskCanceled)
                    {
                        if (BackgroundInventoryManager.log.IsInfoEnabled)
                        {
                            BackgroundInventoryManager.log.InfoFormat("Inventorying of Node {0} was canceled. ElapsedTime = {1}", task.NodeID, stopwatch.ElapsedMilliseconds);
                        }
                        stopwatch.Stop();
                        return;
                    }
                    InventoryPollersResult inventoryPollersResult = this.inventories[text](nodeSettings, inventorySettings, credentials);
                    if (inventoryPollersResult == null)
                    {
                        failedTasks.Add(text);
                        if (BackgroundInventoryManager.log.IsErrorEnabled)
                        {
                            BackgroundInventoryManager.log.ErrorFormat("Inventory '{0}' on Node {1} returned null result", text, task.NodeID);
                        }
                    }
                    else if (inventoryPollersResult.Outcome == 1)
                    {
                        completedTasks.Add(text);
                        list.AddRange(inventoryPollersResult.PollerTypes);
                    }
                    else
                    {
                        failedTasks.Add(text);
                        if (inventoryPollersResult.Error != null)
                        {
                            if (BackgroundInventoryManager.log.IsWarnEnabled)
                            {
                                BackgroundInventoryManager.log.WarnFormat("Inventory '{0}' on Node {1} failed with code {2}", text, task.NodeID, inventoryPollersResult.Error.ErrorCode);
                            }
                            if (inventoryPollersResult.Error.ErrorCode != 31002U)
                            {
                                IEnumerable <string> source = array;
                                Func <string, bool>  predicate;
                                if ((predicate = < > 9__0) == null)
                                {
                                    predicate = (< > 9__0 = ((string n) => !completedTasks.Contains(n) && !failedTasks.Contains(n)));
                                }
                                List <string> list2 = source.Where(predicate).ToList <string>();
                                if (list2.Count > 0)
                                {
                                    failedTasks.AddRange(list2);
                                    if (BackgroundInventoryManager.log.IsWarnEnabled)
                                    {
                                        BackgroundInventoryManager.log.WarnFormat("Skipping inventory for '{0}' on Node {1}", string.Join(":", list2.ToArray()), task.NodeID);
                                        break;
                                    }
                                    break;
                                }
                            }
                        }
                        else if (BackgroundInventoryManager.log.IsWarnEnabled)
                        {
                            BackgroundInventoryManager.log.WarnFormat("Inventory '{0}' on Node {1} failed on unknown error", text, task.NodeID);
                        }
                    }
                }
            }
            string lastNodeSettings = NodeSettingsDAL.GetLastNodeSettings(task.NodeID, CoreConstants.NeedsInventoryFlag);

            if ((string.IsNullOrEmpty(lastNodeSettings) || !lastNodeSettings.Equals(task.Settings, StringComparison.OrdinalIgnoreCase)) && BackgroundInventoryManager.log.IsInfoEnabled)
            {
                BackgroundInventoryManager.log.InfoFormat("Skipping inventory result processing for Node {0}, NeedsInventory flag changed. OldValue = '{1}', NewValue = '{2}'.", task.NodeID, task.Settings, lastNodeSettings);
                return;
            }
            this.InsertDetectedPollers(task, list);
            if (failedTasks.Count == 0)
            {
                NodeSettingsDAL.DeleteSpecificSettingForNode(task.NodeID, CoreConstants.NeedsInventoryFlag);
                if (BackgroundInventoryManager.log.IsInfoEnabled)
                {
                    BackgroundInventoryManager.log.InfoFormat("Inventorying of Node {0} completed in {1}ms.", task.NodeID, stopwatch.ElapsedMilliseconds);
                }
            }
            else if (failedTasks.Count < array.Length)
            {
                string text2 = string.Join(":", failedTasks.ToArray());
                NodeSettingsDAL.SafeInsertNodeSetting(task.NodeID, CoreConstants.NeedsInventoryFlag, text2);
                if (BackgroundInventoryManager.log.IsInfoEnabled)
                {
                    BackgroundInventoryManager.log.InfoFormat("Inventorying of Node {0} partially completed in {1}ms. NeedsInventory updated to '{2}'", task.NodeID, stopwatch.ElapsedMilliseconds, text2);
                }
            }
            else if (BackgroundInventoryManager.log.IsInfoEnabled)
            {
                BackgroundInventoryManager.log.InfoFormat("Inventorying of Node {0} failed. Elapsed time {1}ms.", task.NodeID, stopwatch.ElapsedMilliseconds);
            }
            stopwatch.Stop();
        }