Beispiel #1
0
        public override bool AddMonitorEvent(SIPMonitorMachineEvent machineEvent)
        {
            try
            {
                lock (DialogInfo)
                {
                    MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.Monitor, "Monitor event " + machineEvent.MachineEventType + " dialog " + ResourceURI.ToString() + " (ID " + machineEvent.ResourceID + ").", SubscriptionDialogue.Owner));

                    string state = GetStateForEventType(machineEvent.MachineEventType);

                    if (machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPDialogueRemoved)
                    {
                        DialogInfo.DialogItems.Add(new SIPEventDialog(machineEvent.ResourceID, state, null));
                        return(true);
                    }
                    else
                    {
                        SIPDialogueAsset sipDialogue = GetDialogue_External(new Guid(machineEvent.ResourceID));

                        if (sipDialogue == null)
                        {
                            // Couldn't find the dialogue in the database so it must be terminated.
                            DialogInfo.DialogItems.Add(new SIPEventDialog(machineEvent.ResourceID, "terminated", null));
                            return(true);
                        }
                        else if (machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPDialogueTransfer)
                        {
                            // For dialog transfer events add both dialogs involved to the notification.
                            DialogInfo.DialogItems.Add(new SIPEventDialog(sipDialogue.Id.ToString(), state, sipDialogue.SIPDialogue));

                            if (sipDialogue.SIPDialogue.BridgeId != Guid.Empty)
                            {
                                SIPDialogueAsset bridgedDialogue = GetDialogues_External(d => d.BridgeId == sipDialogue.BridgeId && d.Id != sipDialogue.Id, null, 0, 1).FirstOrDefault();
                                if (bridgedDialogue != null)
                                {
                                    DialogInfo.DialogItems.Add(new SIPEventDialog(bridgedDialogue.Id.ToString(), state, bridgedDialogue.SIPDialogue));
                                }
                            }

                            return(true);
                        }
                        else
                        {
                            DialogInfo.DialogItems.Add(new SIPEventDialog(sipDialogue.Id.ToString(), state, sipDialogue.SIPDialogue));
                            return(true);
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.Monitor, "Exception AddMonitorEvent. " + excp.Message, null));
                logger.Error("Exception SIPDialogEventSubscription AddMonitorEvent. " + excp.Message);
                throw;
            }
        }
 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);
     }
 }
Beispiel #3
0
        public static SIPMonitorMachineEvent ParseMachineEventCSV(string eventCSV)
        {
            try
            {
                SIPMonitorMachineEvent machineEvent = new SIPMonitorMachineEvent();

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

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

                machineEvent.SessionID        = eventFields[1];
                machineEvent.MonitorServerID  = eventFields[2];
                machineEvent.MachineEventType = SIPMonitorMachineEventTypes.GetMonitorMachineTypeForId(Convert.ToInt32(eventFields[3]));
                machineEvent.Created          = DateTimeOffset.ParseExact(eventFields[4], SERIALISATION_DATETIME_FORMAT, CultureInfo.InvariantCulture);
                machineEvent.Username         = eventFields[5];
                machineEvent.RemoteEndPoint   = SIPEndPoint.ParseSIPEndPoint(eventFields[6]);
                machineEvent.Message          = eventFields[7];
                machineEvent.ResourceID       = eventFields[8];
                string resourceURI = eventFields[9].Trim('#');

                if (!resourceURI.IsNullOrBlank())
                {
                    machineEvent.ResourceURI = SIPURI.ParseSIPURIRelaxed(resourceURI);
                }

                return(machineEvent);
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPMonitorMachineEvent ParseEventCSV. " + excp.Message);
                return(null);
            }
        }
Beispiel #4
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);
            }
        }
 public virtual bool AddMonitorEvent(SIPMonitorMachineEvent machineEvent)
 {
     throw new NotImplementedException();
 }
Beispiel #6
0
        /// <summary>
        /// Checks and where required adds a presence related monitor event to the list of pending notifications.
        /// </summary>
        /// <param name="machineEvent">The monitor event that has been received.</param>
        /// <returns>True if a notification needs to be sent as a result of this monitor event, false otherwise.</returns>
        public override bool AddMonitorEvent(SIPMonitorMachineEvent machineEvent)
        {
            try
            {
                MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.Monitor, "Monitor event " + machineEvent.MachineEventType + " presence " + machineEvent.ResourceURI.ToString() + " for subscription to " + ResourceURI.ToString() + ".", SubscriptionDialogue.Owner));

                string safeSIPAccountID         = machineEvent.ResourceID;
                SIPURI sipAccountURI            = machineEvent.ResourceURI;
                bool   sendNotificationForEvent = true;
                string avatarURL = null;

                if (m_switchboardSIPAccountsOnly)
                {
                    // Need to check whether the SIP account is switchboard enabled before forwarding the notification.
                    Guid sipAccountID = new Guid(machineEvent.ResourceID);
                    //sendNotificationForEvent = Convert.ToBoolean(m_sipAccountPersistor.GetProperty(sipAccountID, "IsSwitchboardEnabled"));
                    sendNotificationForEvent = Convert.ToBoolean(GetSipAccountProperty_External(sipAccountID, "IsSwitchboardEnabled"));

                    if (sendNotificationForEvent)
                    {
                        //avatarURL = m_sipAccountPersistor.GetProperty(sipAccountID, "AvatarURL") as string;
                        avatarURL = GetSipAccountProperty_External(sipAccountID, "AvatarURL") as string;
                    }
                }

                if (sendNotificationForEvent)
                {
                    if (machineEvent.MachineEventType == SIPMonitorMachineEventTypesEnum.SIPRegistrarBindingUpdate)
                    {
                        // A binding has been updated so there is at least one device online for the SIP account.
                        Presence.Tuples.Add(new SIPEventPresenceTuple(safeSIPAccountID, SIPEventPresenceStateEnum.open, sipAccountURI, Decimal.Zero, avatarURL));
                        //logger.Debug(" single presence open.");
                    }
                    else
                    {
                        // A binding has been removed but there could still be others.
                        Guid sipAccountID  = new Guid(machineEvent.ResourceID);
                        int  bindingsCount = GetSIPRegistrarBindingsCount_External(b => b.SIPAccountId == sipAccountID);
                        if (bindingsCount > 0)
                        {
                            Presence.Tuples.Add(new SIPEventPresenceTuple(safeSIPAccountID, SIPEventPresenceStateEnum.open, sipAccountURI, Decimal.Zero, avatarURL));
                        }
                        else
                        {
                            Presence.Tuples.Add(new SIPEventPresenceTuple(safeSIPAccountID, SIPEventPresenceStateEnum.closed, sipAccountURI, Decimal.Zero, avatarURL));
                        }
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPresenceEventSubscription AddMonitorEvent. " + excp.Message);
                throw;
            }
        }