示例#1
0
            public void FullTraceSIPSwitchUnitTest()
            {
                Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

                SIPMonitorFilter filter = new SIPMonitorFilter("event full and regex :test@");

                Console.WriteLine(filter.GetFilterDescription());

                Assert.IsTrue(filter != null, "The filter was not correctly instantiated.");
                //Assert.AreEqual(filter.Username, "test", "The filter username was not correctly set.");
                Assert.AreEqual(filter.EventFilterDescr, "full", "The filter event full was not correctly set.");
                Assert.AreEqual(filter.RegexFilter, ":test@", "The regex was not correctly set.");

                string inviteRequest =
                    "INVITE sip:213.200.94.181 SIP/2.0" + m_CRLF +
                    "Via: SIP/2.0/UDP 192.168.1.32:10254;branch=z9hG4bK-d87543-eb7c9f44883c5955-1--d87543-;rport;received=89.100.104.191" + m_CRLF +
                    "To: aaronxten <sip:[email protected]>" + m_CRLF +
                    "From: test <sip:[email protected]>;tag=774d2561" + m_CRLF +
                    "Call-ID: MTBhNGZjZmQ2OTc3MWU5MTZjNWUxMDYxOTk1MjdmYzk." + m_CRLF +
                    "CSeq: 2 REGISTER" + m_CRLF +
                    "Contact: <sip:[email protected]:10254;rinstance=6d2bbd8014ca7a76>;expires=0" + m_CRLF +
                    "Max-Forwards: 69" + m_CRLF +
                    "User-Agent: X-Lite release 1006e stamp 34025" + m_CRLF +
                    "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO" + m_CRLF + m_CRLF;

                SIPMonitorEvent monitorEvent    = new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.FullSIPTrace, inviteRequest, null);
                bool            showEventResult = filter.ShowSIPMonitorEvent(monitorEvent);

                Assert.IsTrue(showEventResult, "The filter should have shown this event.");
            }
示例#2
0
        public static SIPMonitorConsoleEvent ParseClientControlEventCSV(string eventCSV)
        {
            try
            {
                SIPMonitorConsoleEvent monitorEvent = new SIPMonitorConsoleEvent();

                if (eventCSV.IndexOf(END_MESSAGE_DELIMITER) != -1)
                {
                    eventCSV.Remove(eventCSV.Length - 2, 2);
                }

                string[] eventFields = eventCSV.Split(new char[] { '|' });

                monitorEvent.SessionID       = eventFields[1];
                monitorEvent.MonitorServerID = eventFields[2];
                monitorEvent.ServerType      = SIPMonitorServerTypes.GetProxyServerType(eventFields[3]);
                monitorEvent.EventType       = SIPMonitorEventTypes.GetProxyEventType(eventFields[4]);
                monitorEvent.Created         = DateTimeOffset.ParseExact(eventFields[5], SERIALISATION_DATETIME_FORMAT, CultureInfo.InvariantCulture);

                string serverEndPointStr = eventFields[6];
                if (serverEndPointStr != null && serverEndPointStr.Trim().Length > 0)
                {
                    monitorEvent.ServerEndPoint = SIPEndPoint.ParseSIPEndPoint(serverEndPointStr);
                }

                string remoteEndPointStr = eventFields[7];
                if (remoteEndPointStr != null && remoteEndPointStr.Trim().Length > 0)
                {
                    monitorEvent.RemoteEndPoint = SIPEndPoint.ParseSIPEndPoint(remoteEndPointStr);
                }

                string dstEndPointStr = eventFields[8];
                if (dstEndPointStr != null && dstEndPointStr.Trim().Length > 0)
                {
                    monitorEvent.DestinationEndPoint = SIPEndPoint.ParseSIPEndPoint(dstEndPointStr);
                }

                monitorEvent.Username = eventFields[9];
                Int32.TryParse(eventFields[10], out monitorEvent.ProcessID);
                monitorEvent.Message = eventFields[11].Trim('#');

                return(monitorEvent);
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPMonitorConsoleEvent ParseEventCSV. " + excp.Message);
                return(null);
            }
        }
示例#3
0
            public void BlockIPAddressUnitTest()
            {
                Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

                SIPMonitorFilter filter = new SIPMonitorFilter("ipaddress 127.0.0.1 and event full");

                Console.WriteLine(filter.GetFilterDescription());

                Assert.IsTrue(filter != null, "The filter was not correctly instantiated.");
                Assert.AreEqual(filter.IPAddress, "127.0.0.1", "The filter ip address was not correctly set.");

                SIPMonitorEvent monitorEvent    = new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.AppServer, SIPMonitorEventTypesEnum.FullSIPTrace, "blah blah", String.Empty, SIPEndPoint.ParseSIPEndPoint("127.0.0.2"), null);
                bool            showEventResult = filter.ShowSIPMonitorEvent(monitorEvent);

                Assert.IsFalse(showEventResult, "The filter should not have shown this event.");
            }
 public static SIPMonitorEvent ParseEventCSV(string eventCSV)
 {
     if (eventCSV == null || eventCSV.Trim().Length == 0)
     {
         return(null);
     }
     else if (eventCSV.Trim().StartsWith(SIPMonitorConsoleEvent.SERIALISATION_PREFIX))
     {
         return(SIPMonitorConsoleEvent.ParseClientControlEventCSV(eventCSV));
     }
     else if (eventCSV.Trim().StartsWith(SIPMonitorMachineEvent.SERIALISATION_PREFIX))
     {
         return(SIPMonitorMachineEvent.ParseMachineEventCSV(eventCSV));
     }
     else
     {
         logger.Warn("The monitor event prefix of " + eventCSV.Trim().Substring(0, 1) + " was not recognised. " + eventCSV);
         return(null);
     }
 }
示例#5
0
        /// <summary>
        /// Rules for displaying events.
        ///  1. The event type is checked to see if it matches. If no event type has been specified than all events EXCEPT FullSIPTrace are
        ///     matched,
        ///  2. If the event type is FullSIPTrace then the messages can be filtered on the request type. If the request type is not set all
        ///     SIP trace messages are matched otherwise only those pertaining to the request type specified,
        ///  3. The server type is checked, if it's not set all events are matched,
        ///  4. If the event has matched up until this point a decision is now made as to whether to display or reject it:
        ///     a. If the IPAddress filter is set is checked, if it matches the event is displayed otherwise it's rejected,
        ///     b. If the username AND server IP AND request type AND regex filters all match the vent is displayed otherwise rejected.
        /// </summary>
        /// <param name="proxyEvent"></param>
        /// <returns></returns>
        public bool ShowSIPMonitorEvent(SIPMonitorEvent proxyEvent)
        {
            if (proxyEvent is SIPMonitorMachineEvent)
            {
                #region Machine event filtering.

                if (BaseType == MACHINE_BASE_TYPE)
                {
                    if (EventFilterDescr == WILDCARD)
                    {
                        return(ShowUsername(proxyEvent.Username));
                    }
                    else
                    {
                        SIPMonitorMachineEvent machineEvent = proxyEvent as SIPMonitorMachineEvent;

                        if ((machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPDialogueCreated ||
                             machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPDialogueRemoved ||
                             machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPDialogueUpdated ||
                             machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPDialogueTransfer) && SIPEventDialogURI != null)
                        {
                            if (SIPEventDialogURI.User == WILDCARD)
                            {
                                return(ShowUsername(proxyEvent.Username) && ShowMachineEvent(machineEvent.MachineEventType));
                            }
                            else
                            {
                                return(proxyEvent.Username == Username && machineEvent.ResourceURI != null &&
                                       machineEvent.ResourceURI.User == SIPEventDialogURI.User && machineEvent.ResourceURI.Host == SIPEventDialogURI.Host);
                            }
                        }
                        else if ((machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPRegistrarBindingRemoval ||
                                  machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPRegistrarBindingUpdate) && SIPEventPresenceURI != null)
                        {
                            if (SIPEventPresenceURI.User == WILDCARD)
                            {
                                return(ShowUsername(proxyEvent.Username));
                            }
                            else
                            {
                                return(proxyEvent.Username == Username && machineEvent.ResourceURI != null &&
                                       machineEvent.ResourceURI.User == SIPEventPresenceURI.User && machineEvent.ResourceURI.Host == SIPEventPresenceURI.Host);
                            }
                        }
                        else if (SIPEventDialogURI == null && SIPEventPresenceURI == null)
                        {
                            return(ShowUsername(proxyEvent.Username));
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    return(false);
                }

                #endregion
            }
            else if (BaseType == MACHINE_BASE_TYPE && !(proxyEvent is SIPMonitorMachineEvent))
            {
                return(false);
            }
            else
            {
                SIPMonitorConsoleEvent consoleEvent = proxyEvent as SIPMonitorConsoleEvent;

                string serverAddress   = (consoleEvent.ServerEndPoint != null) ? consoleEvent.ServerEndPoint.Address.ToString() : null;
                string remoteIPAddress = (consoleEvent.RemoteEndPoint != null) ? consoleEvent.RemoteEndPoint.Address.ToString() : null;
                string dstIPAddress    = (consoleEvent.DestinationEndPoint != null) ? consoleEvent.DestinationEndPoint.Address.ToString() : null;

                if (SIPRequestFilter != WILDCARD && consoleEvent.Message != null && consoleEvent.EventType == SIPMonitorEventTypesEnum.FullSIPTrace)
                {
                    if (ShowEvent(consoleEvent.EventType, consoleEvent.ServerEndPoint) && ShowServer(consoleEvent.ServerType))
                    {
                        if (SIPRequestFilter == SIPREQUEST_INVITE_VALUE)
                        {
                            // Do a regex to pick out ACKs, BYEs, CANCELs, INVITEs and REFERs.
                            if (Regex.Match(consoleEvent.Message, "(ACK|BYE|CANCEL|INVITE|REFER) +?sips?:", RegexOptions.IgnoreCase).Success ||
                                Regex.Match(consoleEvent.Message, @"CSeq: \d+ (ACK|BYE|CANCEL|INVITE|REFER)(\r|\n)", RegexOptions.IgnoreCase).Success)
                            {
                                return(ShowRegex(consoleEvent.Message) && (ShowIPAddress(remoteIPAddress) || ShowIPAddress(dstIPAddress)));
                            }
                        }
                        else if (SIPRequestFilter == SIPREQUEST_REGISTER_VALUE)
                        {
                            // Do a regex to pick out REGISTERs.
                            if (Regex.Match(consoleEvent.Message, "REGISTER +?sips?:", RegexOptions.IgnoreCase).Success ||
                                Regex.Match(consoleEvent.Message, @"CSeq: \d+ REGISTER(\r|\n)", RegexOptions.IgnoreCase).Success)
                            {
                                return(ShowRegex(consoleEvent.Message) && (ShowIPAddress(remoteIPAddress) || ShowIPAddress(dstIPAddress)));
                            }
                        }
                        else if (SIPRequestFilter == SIPREQUEST_NOTIFY_VALUE)
                        {
                            // Do a regex to pick out NOTIFYs and SUBSCRIBEs.
                            if (Regex.Match(consoleEvent.Message, "(NOTIFY|SUBSCRIBE) +?sips?:", RegexOptions.IgnoreCase).Success ||
                                Regex.Match(consoleEvent.Message, @"CSeq: \d+ (NOTIFY|SUBSCRIBE)(\r|\n)", RegexOptions.IgnoreCase).Success)
                            {
                                return(ShowRegex(consoleEvent.Message) && (ShowIPAddress(remoteIPAddress) || ShowIPAddress(dstIPAddress)));
                            }
                        }

                        return(false);
                    }
                }

                if (ShowEvent(consoleEvent.EventType, consoleEvent.ServerEndPoint))
                {
                    bool showIPAddress = ShowIPAddress(remoteIPAddress) || ShowIPAddress(dstIPAddress);
                    bool showUsername  = ShowUsername(consoleEvent.Username);
                    bool showServerIP  = ShowServerIPAddress(serverAddress);
                    bool showRegex     = ShowRegex(consoleEvent.Message);
                    bool showServer    = ShowServer(consoleEvent.ServerType);

                    if (showUsername && showServerIP && showRegex && showIPAddress && showServer)
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }