예제 #1
0
        private static string GetAuditSwql(
            bool isNodeId,
            bool isDeviceType,
            bool isVendor,
            bool isIp_address,
            bool isHostname,
            bool isSiteId,
            OrionMessagesFilter filter)
        {
            StringBuilder stringBuilder1 = new StringBuilder("\r\nSELECT TOP {1}\r\n    TOSTRING(a.AuditEventID) AS MsgID,\r\n    a.TimeLoggedUtc AS DateTime,\r\n    '{0}' AS MessageType,\r\n    '' AS Icon, \r\n    a.AuditEventMessage AS Message, \r\n\ta.NetObjectType AS ObjectType, \r\n\tTOSTRING(a.NetObjectID) AS ObjectID, \r\n    '' AS ObjectID2, \r\n    '' AS NetObjectValue,\r\n    '' AS IPAddress, \r\n    '' AS Caption,\r\n    0 AS BackColor,\r\n    0 AS Acknowledged,\r\n\tTOSTRING(a.NetObjectID) AS ActiveNetObject,\r\n\ta.NetObjectType AS NetObjectPrefix,\r\n    a.InstanceSiteId AS SiteId,\r\n    s.Name AS SiteName\r\nFROM Orion.AuditingEvents (nolock=true) AS a\r\n{3}\r\nLEFT JOIN Orion.Sites (nolock=true) AS s ON a.InstanceSiteId = s.SiteID\r\nWHERE \r\n    a.TimeLoggedUtc >= @fromDate AND a.TimeLoggedUtc <= @toDate\r\n    {2} \r\n ORDER BY a.TimeLoggedUtc DESC");
            bool          flag           = false;
            StringBuilder stringBuilder2 = new StringBuilder();

            if (isNodeId)
            {
                stringBuilder2.Append(" AND a.NetworkNode = @nodeId ");
            }
            if (isDeviceType)
            {
                stringBuilder2.Append(" AND n.MachineType Like @deviceType ");
                flag = true;
            }
            if (isVendor)
            {
                stringBuilder2.Append(" AND n.Vendor = @vendor ");
                flag = true;
            }
            if (isIp_address)
            {
                stringBuilder2.Append(" AND n.IP_Address Like @ip_address ");
                flag = true;
            }
            if (isHostname)
            {
                stringBuilder2.Append(" AND (n.SysName Like @hostname OR n.Caption Like @hostname) ");
                flag = true;
            }
            if (!string.IsNullOrWhiteSpace(filter.get_AuditType()))
            {
                stringBuilder2.Append(" AND a.ActionTypeID = @actionTypeId ");
            }
            if (!string.IsNullOrWhiteSpace(filter.get_Audituser()))
            {
                stringBuilder2.Append(" AND a.AccountID LIKE @accountId ");
            }
            if (!string.IsNullOrWhiteSpace(filter.get_SearchString()))
            {
                stringBuilder2.Append(" AND a.AuditEventMessage LIKE @search_str ");
            }
            if (isSiteId)
            {
                stringBuilder2.Append(" AND a.InstanceSiteId = @siteId");
            }
            return(string.Format(stringBuilder1.ToString(), (object)OrionMessagesHelper.GetMessageTypeString((OrionMessageType)5), (object)filter.get_Count(), (object)stringBuilder2, flag ? (object)" LEFT JOIN Orion.Nodes (nolock=true) AS n ON a.NetworkNode = n.NodeID AND a.InstanceSiteId = n.InstanceSiteId " : (object)string.Empty));
        }
예제 #2
0
        public static DataTable GetOrionMessagesTable(OrionMessagesFilter filter)
        {
            if (!filter.get_IncludeAlerts() && !filter.get_IncludeEvents() && (!filter.get_IncludeSyslogs() && !filter.get_IncludeTraps()) && !filter.get_IncludeAudits())
            {
                return((DataTable)null);
            }
            string        str           = "SELECT MsgID, DateTime, MessageType, Icon, Message, ObjectType,\r\nObjectID, ObjectID2, NetObjectValue, IPAddress, Caption, BackColor, \r\nAcknowledged, ActiveNetObject, NetObjectPrefix, SiteId, SiteName FROM";
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("SELECT TOP {0}\r\nMsgID, DateTime, MessageType, Icon, Message, ObjectType,\r\nObjectID, ObjectID2, NetObjectValue, IPAddress, Caption, BackColor, \r\nAcknowledged, ActiveNetObject, NetObjectPrefix, SiteId, SiteName FROM (", (object)filter.get_Count());
            string format       = " {1} ( {0} )";
            bool   isNodeId     = false;
            bool   isDeviceType = false;
            bool   isVendor     = false;
            bool   isIp_address = false;
            bool   isHostname   = false;
            bool   isSiteId     = false;
            int    num          = 0;

            if (!string.IsNullOrEmpty(filter.get_AlertType()))
            {
                string s = filter.get_AlertType();
                if (s.StartsWith("AA-"))
                {
                    s = s.Substring("AA-".Length);
                }
                int result;
                if (int.TryParse(s, out result))
                {
                    num = result;
                }
            }
            if (filter.get_NodeId().HasValue)
            {
                isNodeId = true;
            }
            else if (!string.IsNullOrEmpty(filter.get_DeviceType()))
            {
                isDeviceType = true;
            }
            else if (!string.IsNullOrEmpty(filter.get_Vendor()))
            {
                isVendor = true;
            }
            else if (!string.IsNullOrEmpty(filter.get_IpAddress()))
            {
                isIp_address = true;
            }
            else if (!string.IsNullOrEmpty(filter.get_Hostname()))
            {
                isHostname = true;
            }
            if (filter.get_SiteID().HasValue)
            {
                isSiteId = true;
            }
            if (filter.get_IncludeAlerts())
            {
                stringBuilder.AppendFormat(format, (object)OrionMessagesDAL.GetNewAlertsSwql(isNodeId, isDeviceType, isVendor, isIp_address, isHostname, isSiteId, num > 0, !string.IsNullOrEmpty(filter.get_SearchString()), filter.get_ShowAcknowledged(), filter.get_AlertCategoryLimitation(), filter.get_Count()), (object)str);
                format = " UNION ( {1} ( {0} ) ) ";
            }
            if (filter.get_IncludeAudits())
            {
                stringBuilder.AppendFormat(format, (object)OrionMessagesDAL.GetAuditSwql(isNodeId, isDeviceType, isVendor, isIp_address, isHostname, isSiteId, filter), (object)str);
                format = " UNION ( {1} ( {0} ) ) ";
            }
            if (filter.get_IncludeEvents())
            {
                stringBuilder.AppendFormat(format, (object)OrionMessagesDAL.GetEventsSwql(isNodeId, isDeviceType, isVendor, isIp_address, isHostname, isSiteId, !string.IsNullOrEmpty(filter.get_EventType()), !string.IsNullOrEmpty(filter.get_SearchString()), filter.get_ShowAcknowledged(), filter.get_Count()), (object)str);
                format = " UNION ( {1} ( {0} ) ) ";
            }
            if (filter.get_IncludeSyslogs())
            {
                stringBuilder.AppendFormat(format, (object)OrionMessagesDAL.GetSyslogSwql(isNodeId, isDeviceType, isVendor, isIp_address, isHostname, isSiteId, filter.get_SyslogSeverity() < byte.MaxValue, filter.get_SyslogFacility() < byte.MaxValue, !string.IsNullOrEmpty(filter.get_SearchString()), filter.get_ShowAcknowledged(), filter.get_Count()), (object)str);
                format = " UNION ( {1} ( {0} ) ) ";
            }
            if (filter.get_IncludeTraps())
            {
                stringBuilder.AppendFormat(format, (object)OrionMessagesDAL.GetTrapsSwql(isNodeId, isDeviceType, isVendor, isIp_address, isHostname, isSiteId, !string.IsNullOrEmpty(filter.get_TrapType()), !string.IsNullOrEmpty(filter.get_TrapCommunity()), !string.IsNullOrEmpty(filter.get_SearchString()), filter.get_ShowAcknowledged(), filter.get_Count()), (object)str);
            }
            stringBuilder.AppendLine(")a ORDER BY a.DateTime DESC");
            using (IInformationServiceProxy2 iinformationServiceProxy2 = OrionMessagesDAL.creator.Create())
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                dictionary.Add("fromDate", (object)filter.get_FromDate());
                dictionary.Add("toDate", (object)filter.get_ToDate());
                if (isNodeId)
                {
                    dictionary.Add("nodeId", (object)filter.get_NodeId());
                }
                if (isDeviceType)
                {
                    dictionary.Add("deviceType", (object)filter.get_DeviceType());
                }
                if (isVendor)
                {
                    dictionary.Add("vendor", (object)filter.get_Vendor());
                }
                if (isIp_address)
                {
                    dictionary.Add("ip_address", (object)string.Format("%{0}%", (object)CommonHelper.FormatFilter(IPAddressHelper.ToStringIp(filter.get_IpAddress()))));
                }
                if (isHostname)
                {
                    dictionary.Add("hostname", (object)string.Format("%{0}%", (object)CommonHelper.FormatFilter(filter.get_Hostname())));
                }
                if (isSiteId)
                {
                    dictionary.Add("siteId", (object)filter.get_SiteID());
                }
                if (!string.IsNullOrEmpty(filter.get_EventType()))
                {
                    dictionary.Add("event_type", (object)filter.get_EventType());
                }
                if (filter.get_SyslogSeverity() < byte.MaxValue)
                {
                    dictionary.Add("syslog_severity", (object)filter.get_SyslogSeverity());
                }
                if (filter.get_SyslogFacility() < byte.MaxValue)
                {
                    dictionary.Add("syslog_facility", (object)filter.get_SyslogFacility());
                }
                if (!string.IsNullOrEmpty(filter.get_TrapType()))
                {
                    dictionary.Add("trap_type", (object)filter.get_TrapType());
                }
                if (!string.IsNullOrEmpty(filter.get_TrapCommunity()))
                {
                    dictionary.Add("trap_community", (object)filter.get_TrapCommunity());
                }
                if (filter.get_IncludeAlerts() && num > 0)
                {
                    dictionary.Add("newAlert_id", (object)num);
                }
                if (filter.get_IncludeAlerts() && !string.IsNullOrEmpty(filter.get_AlertCategoryLimitation()))
                {
                    dictionary.Add("alertCategoryLimitation", (object)filter.get_AlertCategoryLimitation());
                }
                if (!string.IsNullOrWhiteSpace(filter.get_AuditType()))
                {
                    dictionary.Add("actionTypeId", (object)int.Parse(filter.get_AuditType()));
                }
                if (!string.IsNullOrWhiteSpace(filter.get_Audituser()))
                {
                    dictionary.Add("accountId", (object)filter.get_Audituser());
                }
                if (!string.IsNullOrEmpty(filter.get_SearchString()))
                {
                    dictionary.Add("search_str", (object)string.Format("%{0}%", (object)filter.get_SearchString()));
                }
                DataTable dataTable = InformationServiceProxyExtensions.QueryWithAppendedErrors((IInformationServiceProxy)iinformationServiceProxy2, stringBuilder.ToString(), dictionary, SwisFederationInfo.get_IsFederationEnabled());
                dataTable.TableName = "OrionMessages";
                IEnumerableExtensions.Iterate <DataRow>((IEnumerable <M0>)dataTable.Rows.OfType <DataRow>(), (Action <M0>)(r => r["DateTime"] = (object)((DateTime)r["DateTime"]).ToLocalTime()));
                return(dataTable);
            }
        }