Esempio n. 1
0
        public SlackReactorTests()
        {
            _slackApi = Substitute.For <ISlackApi>();
            _appHost  = Substitute.For <IAppHost>();
            _appHost.Host.Returns(new Host(new[] { "listenUri" }, "instance"));
            _appHost.App.Returns(new Apps.App("app-id", "App Title", new Dictionary <string, string>(), "storage-path"));

            _slackReactor = new SlackReactor(_slackApi)
            {
                WebhookUrl = "http://webhookurl.com"
            };
            _slackReactor.Attach(_appHost);

            _event = new Event <LogEventData>("id", 1, DateTime.Now, new LogEventData
            {
                Id         = "111",
                Level      = LogEventLevel.Information,
                Properties = new Dictionary <string, object>()
                {
                    { "Property1", "Value1" },
                    { "Property2", "Value2" },
                    { "Property3", "Value3" }
                }
            });
        }
Esempio n. 2
0
 public SlackNotification(ISlackApi api, ISettingsService <SlackNotificationSettings> sn, ILogger <SlackNotification> log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t,
                          ISettingsService <CustomizationSettings> s, IRepository <RequestSubscription> sub, IMusicRequestRepository music,
                          IRepository <UserNotificationPreferences> userPref) : base(sn, r, m, t, s, log, sub, music, userPref)
 {
     Api    = api;
     Logger = log;
 }
Esempio n. 3
0
 public SlackApiService(
     ISlackApiFactory slackApiFactory,
     IMemoryCache memoryCache)
 {
     this.slackApi    = slackApiFactory.CreateSlackApi();
     this.memoryCache = memoryCache;
     this.random      = new Random();
 }
Esempio n. 4
0
        public static Task <AuthenticationResult> Login(this ISlackApi This, string userId, string teamId, string password)
        {
            var dict = new Dictionary <string, string> {
                { "user", userId },
                { "team", teamId },
                { "password", password },
            };

            return(This.LoginRaw(dict));
        }
Esempio n. 5
0
        public static async Task <MessageListForRoom> GetLatestMessages(this ISlackApi This, string token, string channelId)
        {
            var dict = new Dictionary <string, string> {
                { "token", token },
                { "channel", channelId },
            };

            var ret = await This.GetMessagesForChannelRaw(dict);

            if (!ret.ok || ret.messages == null)
            {
                throw new Exception("Can't load messages for " + channelId);
            }

            return(ret);
        }
Esempio n. 6
0
        public static async Task <ChannelList> GetChannels(this ISlackApi This, string token)
        {
            var dict = new Dictionary <string, string> {
                { "token", token },
                { "exclude_archived", "1" },
            };

            var ret = await This.GetChannelsRaw(dict);

            if (!ret.ok || ret.channels == null || ret.channels.Count == 0)
            {
                // NB: Slack guarantees that there is always at least one
                // channel
                throw new Exception("Retrieving channels failed");
            }

            return(ret);
        }
Esempio n. 7
0
 public static Task <AvailableTeamList> GetTeamsForUser(this ISlackApi This, string email)
 {
     return(This.GetTeamsForUserRaw(new Dictionary <string, string> {
         { "email", email }
     }));
 }
 public SlackPostMessageExtensions(ISlackApi slackApi)
 {
     _slackApi = slackApi;
 }
 public SlackApiService(
     ISlackApiFactory slackApiFactory)
 {
     this.slackApi = slackApiFactory.CreateSlackApi();
 }
Esempio n. 10
0
 public SlackUserExtensions(ISlackApi slackApi)
 {
     _slackApi = slackApi;
 }
Esempio n. 11
0
        public void On(Event <LogEventData> evt)
        {
            _suppressions = _suppressions ?? new EventTypeSuppressions(SuppressionMinutes);
            if (_suppressions.ShouldSuppressAt(evt.EventType, DateTime.UtcNow))
            {
                return;
            }

            var color = EventFormatting.LevelToColor(evt.Data.Level);

            var message = new SlackMessage("[" + evt.Data.Level + "] " + evt.Data.RenderedMessage,
                                           GenerateMessageText(evt),
                                           string.IsNullOrWhiteSpace(Username) ? App.Title : EventFormatting.SubstitutePlaceholders(Username, evt, false),
                                           string.IsNullOrWhiteSpace(IconUrl) ? DefaultIconUrl : IconUrl,
                                           Channel);

            if (_slackApi == null)
            {
                _slackApi = new SlackApi(ProxyServer);
            }

            if (ExcludePropertyInformation)
            {
                _slackApi.SendMessage(WebhookUrl, message);
                return;
            }

            if (IsAlert(evt))
            {
                var resultsUrl  = EventFormatting.SafeGetProperty(evt, "ResultsUrl");
                var resultsText = SlackSyntax.Hyperlink(resultsUrl, "Explore detected results in Seq");
                var results     = new SlackMessageAttachment(color, resultsText);
                message.Attachments.Add(results);

                if (MessageTemplate != null)
                {
                    message.Attachments.Add(new SlackMessageAttachment(color, MessageTemplate, null, true));
                }

                _slackApi.SendMessage(WebhookUrl, message);
                return;
            }

            var special = new SlackMessageAttachment(color);

            special.Fields.Add(new SlackMessageAttachmentField("Level", evt.Data.Level.ToString(), @short: true));
            message.Attachments.Add(special);

            foreach (var key in SpecialProperties)
            {
                if (evt.Data.Properties == null || !evt.Data.Properties.ContainsKey(key))
                {
                    continue;
                }

                var property = evt.Data.Properties[key];
                special.Fields.Add(new SlackMessageAttachmentField(key, property.ToString(), @short: true));
            }

            if (evt.Data.Exception != null)
            {
                message.Attachments.Add(new SlackMessageAttachment(color, SlackSyntax.Preformatted(evt.Data.Exception), "Exception Details", textIsMarkdown: true));
            }

            if (evt.Data.Properties != null && evt.Data.Properties.TryGetValue("StackTrace", out var st) && st is string stackTrace)
            {
                message.Attachments.Add(new SlackMessageAttachment(color, SlackSyntax.Preformatted(stackTrace), "Stack Trace", textIsMarkdown: true));
            }

            var includedPropertiesArray = string.IsNullOrWhiteSpace(IncludedProperties) ? new string[0] : IncludedProperties.Split(',').Select(x => x.Trim());
            var otherProperties         = new SlackMessageAttachment(color, "Properties");

            if (evt.Data.Properties != null)
            {
                foreach (var property in evt.Data.Properties)
                {
                    if (SpecialProperties.Contains(property.Key))
                    {
                        continue;
                    }
                    if (property.Key == "StackTrace")
                    {
                        continue;
                    }
                    if (includedPropertiesArray.Any() && !includedPropertiesArray.Contains(property.Key))
                    {
                        continue;
                    }

                    string value = ConvertPropertyValueToString(property.Value);

                    otherProperties.Fields.Add(new SlackMessageAttachmentField(property.Key, value, @short: false));
                }
            }

            if (otherProperties.Fields.Count != 0)
            {
                message.Attachments.Add(otherProperties);
            }

            _slackApi.SendMessage(WebhookUrl, message);
        }
Esempio n. 12
0
 internal SlackReactor(ISlackApi slackApi)
 {
     _slackApi = slackApi;
 }
 public SlackNotification(ISlackApi api, ISettingsService <SlackNotificationSettings> sn)
 {
     Api      = api;
     Settings = sn;
 }
 public SlackApiService(
     ISlackApi slackApi)
 {
     _slackApi = slackApi;
 }
Esempio n. 15
0
 public SlackNotification(ISlackApi api, ISettingsService <SlackNotificationSettings> sn, ILogger <SlackNotification> log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t,
                          ISettingsService <CustomizationSettings> s) : base(sn, r, m, t, s, log)
 {
     Api    = api;
     Logger = log;
 }
Esempio n. 16
0
        public AdminModule(ISettingsService <PlexRequestSettings> prService,
                           ISettingsService <CouchPotatoSettings> cpService,
                           ISettingsService <AuthenticationSettings> auth,
                           ISettingsService <PlexSettings> plex,
                           ISettingsService <SonarrSettings> sonarr,
                           ISettingsService <SickRageSettings> sickrage,
                           ISonarrApi sonarrApi,
                           ISettingsService <EmailNotificationSettings> email,
                           IPlexApi plexApi,
                           ISettingsService <PushbulletNotificationSettings> pbSettings,
                           PushbulletApi pbApi,
                           ICouchPotatoApi cpApi,
                           ISettingsService <PushoverNotificationSettings> pushoverSettings,
                           IPushoverApi pushoverApi,
                           IRepository <LogEntity> logsRepo,
                           INotificationService notify,
                           ISettingsService <HeadphonesSettings> headphones,
                           ISettingsService <LogSettings> logs,
                           ICacheProvider cache, ISettingsService <SlackNotificationSettings> slackSettings,
                           ISlackApi slackApi) : base("admin", prService)
        {
            PrService           = prService;
            CpService           = cpService;
            AuthService         = auth;
            PlexService         = plex;
            SonarrService       = sonarr;
            SonarrApi           = sonarrApi;
            EmailService        = email;
            PlexApi             = plexApi;
            PushbulletService   = pbSettings;
            PushbulletApi       = pbApi;
            CpApi               = cpApi;
            SickRageService     = sickrage;
            LogsRepo            = logsRepo;
            PushoverService     = pushoverSettings;
            PushoverApi         = pushoverApi;
            NotificationService = notify;
            HeadphonesService   = headphones;
            LogService          = logs;
            Cache               = cache;
            SlackSettings       = slackSettings;
            SlackApi            = slackApi;

            this.RequiresClaims(UserClaims.Admin);

            Get["/"] = _ => Admin();

            Get["/authentication"]  = _ => Authentication();
            Post["/authentication"] = _ => SaveAuthentication();

            Post["/"] = _ => SaveAdmin();

            Post["/requestauth"] = _ => RequestAuthToken();

            Get["/getusers"] = _ => GetUsers();

            Get["/couchpotato"]  = _ => CouchPotato();
            Post["/couchpotato"] = _ => SaveCouchPotato();

            Get["/plex"]  = _ => Plex();
            Post["/plex"] = _ => SavePlex();

            Get["/sonarr"]  = _ => Sonarr();
            Post["/sonarr"] = _ => SaveSonarr();

            Get["/sickrage"]  = _ => Sickrage();
            Post["/sickrage"] = _ => SaveSickrage();

            Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles();
            Post["/cpprofiles"]     = _ => GetCpProfiles();

            Get["/emailnotification"]      = _ => EmailNotifications();
            Post["/emailnotification"]     = _ => SaveEmailNotifications();
            Post["/testemailnotification"] = _ => TestEmailNotifications();
            Get["/status"] = _ => Status();

            Get["/pushbulletnotification"]      = _ => PushbulletNotifications();
            Post["/pushbulletnotification"]     = _ => SavePushbulletNotifications();
            Post["/testpushbulletnotification"] = _ => TestPushbulletNotifications();

            Get["/pushovernotification"]      = _ => PushoverNotifications();
            Post["/pushovernotification"]     = _ => SavePushoverNotifications();
            Post["/testpushovernotification"] = _ => TestPushoverNotifications();

            Get["/logs"]      = _ => Logs();
            Get["/loglevel"]  = _ => GetLogLevels();
            Post["/loglevel"] = _ => UpdateLogLevels(Request.Form.level);
            Get["/loadlogs"]  = _ => LoadLogs();

            Get["/headphones"]  = _ => Headphones();
            Post["/headphones"] = _ => SaveHeadphones();

            Post["/createapikey"] = x => CreateApiKey();

            Post["/autoupdate"] = x => AutoUpdate();

            Post["/testslacknotification"] = _ => TestSlackNotification();

            Get["/slacknotification"]  = _ => SlackNotifications();
            Post["/slacknotification"] = _ => SaveSlackNotifications();
        }
Esempio n. 17
0
        public AdminModule(ISettingsService <PlexRequestSettings> prService,
                           ISettingsService <CouchPotatoSettings> cpService,
                           ISettingsService <AuthenticationSettings> auth,
                           ISettingsService <PlexSettings> plex,
                           ISettingsService <SonarrSettings> sonarr,
                           ISettingsService <SickRageSettings> sickrage,
                           ISonarrApi sonarrApi,
                           ISettingsService <EmailNotificationSettings> email,
                           IPlexApi plexApi,
                           ISettingsService <PushbulletNotificationSettings> pbSettings,
                           PushbulletApi pbApi,
                           ICouchPotatoApi cpApi,
                           ISettingsService <PushoverNotificationSettings> pushoverSettings,
                           ISettingsService <NewletterSettings> newsletter,
                           IPushoverApi pushoverApi,
                           IRepository <LogEntity> logsRepo,
                           INotificationService notify,
                           ISettingsService <HeadphonesSettings> headphones,
                           ISettingsService <LogSettings> logs,
                           ICacheProvider cache, ISettingsService <SlackNotificationSettings> slackSettings,
                           ISlackApi slackApi, ISettingsService <LandingPageSettings> lp,
                           ISettingsService <ScheduledJobsSettings> scheduler, IJobRecord rec, IAnalytics analytics,
                           ISettingsService <NotificationSettingsV2> notifyService, IRecentlyAdded recentlyAdded,
                           ISettingsService <WatcherSettings> watcherSettings
                           , ISecurityExtensions security) : base("admin", prService, security)
        {
            PrService            = prService;
            CpService            = cpService;
            AuthService          = auth;
            PlexService          = plex;
            SonarrService        = sonarr;
            SonarrApi            = sonarrApi;
            EmailService         = email;
            PlexApi              = plexApi;
            PushbulletService    = pbSettings;
            PushbulletApi        = pbApi;
            CpApi                = cpApi;
            SickRageService      = sickrage;
            LogsRepo             = logsRepo;
            PushoverService      = pushoverSettings;
            PushoverApi          = pushoverApi;
            NotificationService  = notify;
            HeadphonesService    = headphones;
            NewsLetterService    = newsletter;
            LogService           = logs;
            Cache                = cache;
            SlackSettings        = slackSettings;
            SlackApi             = slackApi;
            LandingSettings      = lp;
            ScheduledJobSettings = scheduler;
            JobRecorder          = rec;
            Analytics            = analytics;
            NotifySettings       = notifyService;
            RecentlyAdded        = recentlyAdded;
            WatcherSettings      = watcherSettings;

            Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);

            Get["/"] = _ => Admin();

            Get["/authentication", true] = async(x, ct) => await Authentication();

            Post["/authentication", true] = async(x, ct) => await SaveAuthentication();

            Post["/", true] = async(x, ct) => await SaveAdmin();

            Post["/requestauth"] = _ => RequestAuthToken();

            Get["/getusers"] = _ => GetUsers();

            Get["/couchpotato"]  = _ => CouchPotato();
            Post["/couchpotato"] = _ => SaveCouchPotato();

            Get["/plex"]        = _ => Plex();
            Post["/plex", true] = async(x, ct) => await SavePlex();

            Get["/sonarr"]  = _ => Sonarr();
            Post["/sonarr"] = _ => SaveSonarr();

            Get["/sickrage"]  = _ => Sickrage();
            Post["/sickrage"] = _ => SaveSickrage();

            Post["/sonarrprofiles"]   = _ => GetSonarrQualityProfiles();
            Post["/cpprofiles", true] = async(x, ct) => await GetCpProfiles();

            Post["/cpapikey"] = x => GetCpApiKey();

            Get["/emailnotification"]            = _ => EmailNotifications();
            Post["/emailnotification"]           = _ => SaveEmailNotifications();
            Post["/testemailnotification", true] = async(x, ct) => await TestEmailNotifications();

            Get["/pushbulletnotification"]            = _ => PushbulletNotifications();
            Post["/pushbulletnotification"]           = _ => SavePushbulletNotifications();
            Post["/testpushbulletnotification", true] = async(x, ct) => await TestPushbulletNotifications();

            Get["/pushovernotification"]            = _ => PushoverNotifications();
            Post["/pushovernotification"]           = _ => SavePushoverNotifications();
            Post["/testpushovernotification", true] = async(x, ct) => await TestPushoverNotifications();

            Get["/logs"]      = _ => Logs();
            Get["/loglevel"]  = _ => GetLogLevels();
            Post["/loglevel"] = _ => UpdateLogLevels(Request.Form.level);
            Get["/loadlogs"]  = _ => LoadLogs();

            Get["/headphones"]  = _ => Headphones();
            Post["/headphones"] = _ => SaveHeadphones();

            Get["/newsletter"]  = _ => Newsletter();
            Post["/newsletter"] = _ => SaveNewsletter();

            Post["/createapikey"] = x => CreateApiKey();



            Post["/testslacknotification", true] = async(x, ct) => await TestSlackNotification();

            Get["/slacknotification"]  = _ => SlackNotifications();
            Post["/slacknotification"] = _ => SaveSlackNotifications();

            Get["/landingpage", true] = async(x, ct) => await LandingPage();

            Post["/landingpage", true] = async(x, ct) => await SaveLandingPage();

            Get["/scheduledjobs", true] = async(x, ct) => await GetScheduledJobs();

            Post["/scheduledjobs", true] = async(x, ct) => await SaveScheduledJobs();

            Post["/clearlogs", true] = async(x, ct) => await ClearLogs();

            Get["/notificationsettings", true] = async(x, ct) => await NotificationSettings();

            Post["/notificationsettings"] = x => SaveNotificationSettings();

            Post["/recentlyAddedTest"] = x => RecentlyAddedTest();
        }