예제 #1
0
        public IEnumerable <AgentInfo> GetAgentsByNodesFilter(
            int engineId,
            string nodesWhereClause)
        {
            List <AgentInfo> agentInfoList = new List <AgentInfo>();

            using (InformationServiceConnection systemConnectionV3 = InformationServiceConnectionProvider.CreateSystemConnectionV3())
            {
                using (InformationServiceCommand command = systemConnectionV3.CreateCommand())
                {
                    ((DbCommand)command).CommandText = string.Format("SELECT agents.AgentId, \r\n                            agents.AgentGuid, \r\n                            agents.NodeId, \r\n                            nodes.ObjectSubType,\r\n                            agents.Uri,\r\n                            agents.Name, \r\n                            agents.Hostname, \r\n                            agents.IP, \r\n                            agents.PollingEngineId,\r\n                            agents.AgentStatus, \r\n                            agents.AgentStatusMessage, \r\n                            agents.ConnectionStatus, \r\n                            agents.ConnectionStatusMessage,\r\n                            agents.OSType,\r\n                            agents.OSDistro,\r\n                            agents.OSVersion,\r\n                            p.PluginId, \r\n                            p.Status, \r\n                            p.StatusMessage\r\n                    FROM Orion.AgentManagement.Agent agents\r\n                    INNER JOIN Orion.Nodes Nodes ON Nodes.NodeID = agents.NodeID\r\n                    LEFT JOIN Orion.AgentManagement.AgentPlugin p ON agents.AgentId = p.AgentId \r\n                    WHERE agents.PollingEngineId=@engineId AND agents.ConnectionStatus = @connectionStatus {0}\r\n                    ORDER BY agents.AgentId", !string.IsNullOrWhiteSpace(nodesWhereClause) ? (object)(" AND " + nodesWhereClause) : (object)string.Empty);
                    command.get_Parameters().AddWithValue("connectionStatus", (object)1);
                    command.get_Parameters().AddWithValue(nameof(engineId), (object)engineId);
                    using (IDataReader reader = (IDataReader)command.ExecuteReader())
                        agentInfoList = this.GetAgentsFromReader(reader);
                }
            }
            return(((IEnumerable <AgentInfo>)agentInfoList).Where <AgentInfo>((Func <AgentInfo, bool>)(x => x.get_NodeID().HasValue&& x.get_NodeSubType() == "Agent")));
        }
예제 #2
0
 public bool IsUniqueAgentName(string agentName)
 {
     using (InformationServiceConnection systemConnectionV3 = InformationServiceConnectionProvider.CreateSystemConnectionV3())
     {
         using (InformationServiceCommand command = systemConnectionV3.CreateCommand())
         {
             ((DbCommand)command).CommandText = "SELECT COUNT(AgentId) AS Cnt FROM Orion.AgentManagement.Agent WHERE Name = @Name";
             command.get_Parameters().AddWithValue("Name", (object)agentName);
             using (InformationServiceDataReader serviceDataReader = command.ExecuteReader())
                 return(!((DbDataReader)serviceDataReader).Read() || (int)((DbDataReader)serviceDataReader)[0] == 0);
         }
     }
 }
예제 #3
0
        private IEnumerable <AgentInfo> GetAgentsInfo(
            string whereClause,
            IDictionary <string, object> parameters)
        {
            List <AgentInfo> agentInfoList = new List <AgentInfo>();

            using (InformationServiceConnection systemConnectionV3 = InformationServiceConnectionProvider.CreateSystemConnectionV3())
            {
                using (InformationServiceCommand command = systemConnectionV3.CreateCommand())
                {
                    ((DbCommand)command).CommandText = string.Format("SELECT a.AgentId, \r\n                            a.AgentGuid, \r\n                            a.NodeId, \r\n                            n.ObjectSubType,\r\n                            a.Uri,\r\n                            a.Name, \r\n                            a.Hostname, \r\n                            a.IP, \r\n                            a.PollingEngineId,\r\n                            a.AgentStatus, \r\n                            a.AgentStatusMessage, \r\n                            a.ConnectionStatus, \r\n                            a.ConnectionStatusMessage,\r\n                            p.PluginId, \r\n                            p.Status, \r\n                            p.StatusMessage,\r\n                            a.OSType,\r\n                            a.OSDistro,\r\n                            a.OSVersion\r\n                    FROM Orion.AgentManagement.Agent a\r\n                    LEFT JOIN Orion.Nodes n ON n.NodeID = a.NodeID\r\n                    LEFT JOIN Orion.AgentManagement.AgentPlugin p ON a.AgentId = p.AgentId \r\n                    {0}\r\n                    ORDER BY a.AgentId", !string.IsNullOrEmpty(whereClause) ? (object)("WHERE " + whereClause) : (object)string.Empty);
                    if (parameters != null)
                    {
                        foreach (KeyValuePair <string, object> parameter in (IEnumerable <KeyValuePair <string, object> >)parameters)
                        {
                            command.get_Parameters().AddWithValue(parameter.Key, parameter.Value);
                        }
                    }
                    using (IDataReader reader = (IDataReader)command.ExecuteReader())
                        return((IEnumerable <AgentInfo>) this.GetAgentsFromReader(reader));
                }
            }
        }