logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
FPSChris  
#1 Posted : Tuesday, October 30, 2018 10:36:57 AM(UTC)
FPSChris


Rank: Guest

Joined: 1/31/2017(UTC)
Posts: 4
United Kingdom

Hey, could anyone help me with a Trigger please.
It's just to ping out an e-mail when the session is over 2 days old, set it to 2 mins for testing.

Event Filter:
Session.Host = 'FPSChris' and Session.SessionType = 'Support' and (Event.EventType = 'CreatedSession' and Event.Time <= $2MINSAGO)


I suspect it's the format of:
Event.Time <= $2MINSAGO

This works in the session filters to see anything less than X or greater than X but I can't find a way to do it in the Trigger. Removing it and creating a session pings me a mail so I know it's working just without the after X mins or days.
Eric  
#2 Posted : Wednesday, October 31, 2018 6:55:40 PM(UTC)
Eric


Rank: Administration

Joined: 7/24/2018(UTC)
Posts: 6
United States

That filter selects for an event with an age, but the trigger is pulled only when the event is created (i.e. its age is ~0).

Instead, following the example in this thread, you can implement a custom trigger handler in an extension with a configurable delay:

Manifest.xml
Code:

<?xml version="1.0" encoding="utf-8"?>
<ExtensionManifest>
	<Version>0.1</Version>
	<Name>Email on Session Age</Name>
	<Author>Mr. Example</Author>
	<ShortDescription>Sends a notification email when a session reaches a specified age.</ShortDescription>
	<Components>
		<DynamicSessionEventTriggerDefinition SourceFile="SessionEventTrigger.cs"/>
	</Components>
	<Settings>
		<Setting Name="DelayExpressionInNotes" IsServerOnly="true">
			<Description>Expression to look for on a line in a session's Notes to find the session age to trigger upon.</Description>
			<DefaultValue>emailWhenAgeInMinutes=</DefaultValue>
		</Setting>
		<Setting Name="EmailToAddress" IsServerOnly="true">
			<Description>Recipient address for the age notification email.</Description>
			<DefaultValue>youremailhere@server.com</DefaultValue>
		</Setting>
	</Settings>
</ExtensionManifest>


SessionEventTrigger.cs
Code:

using System;
using System.Collections.Generic;
using System.Threading;
using ScreenConnect;

public class SessionEventTriggerAccessor : IDynamicSessionEventTrigger
{
	public Proc GetDeferredActionIfApplicable(SessionEventTriggerEvent sessionEventTriggerEvent)
	{
		if (sessionEventTriggerEvent.SessionEvent.EventType == SessionEventType.AddedNote) //whenever you add a note, this will scan for an age to trigger on
		{
			return (Proc)delegate
			{
				int delayInMinutes = 0;
				var indexOfValue = sessionEventTriggerEvent.Session.Notes.IndexOf(ExtensionContext.Current.GetSettingValue("DelayExpressionInNotes"));

				if(indexOfValue < 0 || !int.TryParse(sessionEventTriggerEvent.Session.Notes.Substring(ExtensionContext.Current.GetSettingValue("DelayExpressionInNotes").Length), out delayInMinutes))
					return;

				int sessionAgeInMinutes = (int)(DateTime.Now.Subtract(sessionEventTriggerEvent.Session.FirstEventTime)).TotalMinutes;
				int reportedAgeInMinutes = 0;

				if(delayInMinutes > sessionAgeInMinutes) //wait if we have to
				{
					Thread.Sleep((delayInMinutes - sessionAgeInMinutes) * 60 * 1000); //note: max delay is 24 days due to range limits of Int32 and millisecond granularity of Sleep()
					reportedAgeInMinutes = delayInMinutes;
				}
				else //otherwise trigger on anything older than our target
					reportedAgeInMinutes = sessionAgeInMinutes;

				using (var client = new SmtpClient())
				using (var mailMessage = ServerToolkit.Instance.CreateMailMessage())
				{
					mailMessage.To.Add(ExtensionContext.Current.GetSettingValue("EmailToAddress"));

					mailMessage.Subject = string.Format("Session Age Notification for \"{0}\"", sessionEventTriggerEvent.Session.Name);

					mailMessage.Body = string.Format("Session \"{0}\" ({1}) is {2} minutes old", sessionEventTriggerEvent.Session.Name, sessionEventTriggerEvent.Session.SessionID, reportedAgeInMinutes);
					mailMessage.IsBodyHtml = false;

					client.Send(mailMessage);
				}
			};
		}
		else
			return null;
	}
}


(This has only had a minimum of testing, so let me know if you have any issues.)

Edited by user Wednesday, October 31, 2018 6:56:29 PM(UTC)  | Reason: Not specified

FPSChris  
#3 Posted : Thursday, November 1, 2018 7:32:52 AM(UTC)
FPSChris


Rank: Guest

Joined: 1/31/2017(UTC)
Posts: 4
United Kingdom

Originally Posted by: Eric Go to Quoted Post
That filter selects for an event with an age, but the trigger is pulled only when the event is created (i.e. its age is ~0).

Instead, following the example in this thread, you can implement a custom trigger handler in an extension with a configurable delay:

(This has only had a minimum of testing, so let me know if you have any issues.)



Thank you, I'll "attempt" to give this a go later today and let you know if it works or if I tweaked it
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.