@ -1,7 +1,6 @@
using System ;
using System ;
using System.Linq ;
using System.Linq ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using Hangfire ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.Extensions.Logging ;
using Microsoft.Extensions.Logging ;
using Ombi.Api.CouchPotato ;
using Ombi.Api.CouchPotato ;
@ -10,7 +9,6 @@ using Ombi.Api.Plex;
using Ombi.Api.Radarr ;
using Ombi.Api.Radarr ;
using Ombi.Api.SickRage ;
using Ombi.Api.SickRage ;
using Ombi.Api.Sonarr ;
using Ombi.Api.Sonarr ;
using Ombi.Api.Telegram ;
using Ombi.Attributes ;
using Ombi.Attributes ;
using Ombi.Core.Notifications ;
using Ombi.Core.Notifications ;
using Ombi.Core.Settings.Models.External ;
using Ombi.Core.Settings.Models.External ;
@ -18,7 +16,6 @@ using Ombi.Helpers;
using Ombi.Notifications ;
using Ombi.Notifications ;
using Ombi.Notifications.Agents ;
using Ombi.Notifications.Agents ;
using Ombi.Notifications.Models ;
using Ombi.Notifications.Models ;
using Ombi.Notifications.Templates ;
using Ombi.Settings.Settings.Models.External ;
using Ombi.Settings.Settings.Models.External ;
using Ombi.Settings.Settings.Models.Notifications ;
using Ombi.Settings.Settings.Models.Notifications ;
@ -83,6 +80,8 @@ namespace Ombi.Controllers.External
/// <returns></returns>
/// <returns></returns>
[HttpPost("discord")]
[HttpPost("discord")]
public bool Discord ( [ FromBody ] DiscordNotificationSettings settings )
public bool Discord ( [ FromBody ] DiscordNotificationSettings settings )
{
try
{
{
settings . Enabled = true ;
settings . Enabled = true ;
DiscordNotification . NotifyAsync (
DiscordNotification . NotifyAsync (
@ -90,6 +89,12 @@ namespace Ombi.Controllers.External
return true ;
return true ;
}
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Discord" ) ;
return false ;
}
}
/// <summary>
/// <summary>
/// Sends a test message to Pushbullet using the provided settings
/// Sends a test message to Pushbullet using the provided settings
@ -99,12 +104,21 @@ namespace Ombi.Controllers.External
[HttpPost("pushbullet")]
[HttpPost("pushbullet")]
public bool Pushbullet ( [ FromBody ] PushbulletSettings settings )
public bool Pushbullet ( [ FromBody ] PushbulletSettings settings )
{
{
try
{
settings . Enabled = true ;
settings . Enabled = true ;
PushbulletNotification . NotifyAsync (
PushbulletNotification . NotifyAsync (
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
return true ;
}
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Pushbullet" ) ;
return false ;
}
}
/// <summary>
/// <summary>
/// Sends a test message to Pushover using the provided settings
/// Sends a test message to Pushover using the provided settings
@ -113,6 +127,8 @@ namespace Ombi.Controllers.External
/// <returns></returns>
/// <returns></returns>
[HttpPost("pushover")]
[HttpPost("pushover")]
public bool Pushover ( [ FromBody ] PushoverSettings settings )
public bool Pushover ( [ FromBody ] PushoverSettings settings )
{
try
{
{
settings . Enabled = true ;
settings . Enabled = true ;
PushoverNotification . NotifyAsync (
PushoverNotification . NotifyAsync (
@ -120,6 +136,13 @@ namespace Ombi.Controllers.External
return true ;
return true ;
}
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Pushover" ) ;
return false ;
}
}
/// <summary>
/// <summary>
/// Sends a test message to mattermost using the provided settings
/// Sends a test message to mattermost using the provided settings
@ -128,12 +151,22 @@ namespace Ombi.Controllers.External
/// <returns></returns>
/// <returns></returns>
[HttpPost("mattermost")]
[HttpPost("mattermost")]
public bool Mattermost ( [ FromBody ] MattermostNotificationSettings settings )
public bool Mattermost ( [ FromBody ] MattermostNotificationSettings settings )
{
try
{
{
settings . Enabled = true ;
settings . Enabled = true ;
MattermostNotification . NotifyAsync (
MattermostNotification . NotifyAsync (
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
return true ;
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Mattermost" ) ;
return false ;
}
}
}
@ -144,6 +177,8 @@ namespace Ombi.Controllers.External
/// <returns></returns>
/// <returns></returns>
[HttpPost("slack")]
[HttpPost("slack")]
public bool Slack ( [ FromBody ] SlackNotificationSettings settings )
public bool Slack ( [ FromBody ] SlackNotificationSettings settings )
{
try
{
{
settings . Enabled = true ;
settings . Enabled = true ;
SlackNotification . NotifyAsync (
SlackNotification . NotifyAsync (
@ -151,6 +186,12 @@ namespace Ombi.Controllers.External
return true ;
return true ;
}
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Slack" ) ;
return false ;
}
}
/// <summary>
/// <summary>
/// Sends a test message via email to the admin email using the provided settings
/// Sends a test message via email to the admin email using the provided settings
@ -292,12 +333,20 @@ namespace Ombi.Controllers.External
/// <returns></returns>
/// <returns></returns>
[HttpPost("telegram")]
[HttpPost("telegram")]
public async Task < bool > Telegram ( [ FromBody ] TelegramSettings settings )
public async Task < bool > Telegram ( [ FromBody ] TelegramSettings settings )
{
try
{
{
settings . Enabled = true ;
settings . Enabled = true ;
await TelegramNotification . NotifyAsync ( new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
await TelegramNotification . NotifyAsync ( new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
return true ;
}
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Telegram" ) ;
return false ;
}
}
/// <summary>
/// <summary>
/// Sends a test message to Slack using the provided settings
/// Sends a test message to Slack using the provided settings
@ -306,10 +355,18 @@ namespace Ombi.Controllers.External
/// <returns></returns>
/// <returns></returns>
[HttpPost("sickrage")]
[HttpPost("sickrage")]
public async Task < bool > SickRage ( [ FromBody ] SickRageSettings settings )
public async Task < bool > SickRage ( [ FromBody ] SickRageSettings settings )
{
try
{
{
settings . Enabled = true ;
settings . Enabled = true ;
var result = await SickRageApi . Ping ( settings . ApiKey , settings . FullUri ) ;
var result = await SickRageApi . Ping ( settings . ApiKey , settings . FullUri ) ;
return result ? . data ? . pid ! = null ;
return result ? . data ? . pid ! = null ;
}
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test SickRage" ) ;
return false ;
}
}
}
}
}
}