@ -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 ;
@ -84,11 +81,19 @@ namespace Ombi.Controllers.External
[HttpPost("discord")]
[HttpPost("discord")]
public bool Discord ( [ FromBody ] DiscordNotificationSettings settings )
public bool Discord ( [ FromBody ] DiscordNotificationSettings settings )
{
{
settings . Enabled = true ;
try
DiscordNotification . NotifyAsync (
{
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
settings . Enabled = true ;
DiscordNotification . NotifyAsync (
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
return true ;
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Discord" ) ;
return false ;
}
}
}
/// <summary>
/// <summary>
@ -99,11 +104,20 @@ namespace Ombi.Controllers.External
[HttpPost("pushbullet")]
[HttpPost("pushbullet")]
public bool Pushbullet ( [ FromBody ] PushbulletSettings settings )
public bool Pushbullet ( [ FromBody ] PushbulletSettings settings )
{
{
settings . Enabled = true ;
try
PushbulletNotification . NotifyAsync (
{
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
settings . Enabled = true ;
PushbulletNotification . NotifyAsync (
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Pushbullet" ) ;
return false ;
}
}
}
/// <summary>
/// <summary>
@ -114,11 +128,20 @@ namespace Ombi.Controllers.External
[HttpPost("pushover")]
[HttpPost("pushover")]
public bool Pushover ( [ FromBody ] PushoverSettings settings )
public bool Pushover ( [ FromBody ] PushoverSettings settings )
{
{
settings . Enabled = true ;
try
PushoverNotification . NotifyAsync (
{
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
settings . Enabled = true ;
PushoverNotification . NotifyAsync (
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Pushover" ) ;
return false ;
}
return true ;
}
}
/// <summary>
/// <summary>
@ -129,11 +152,21 @@ namespace Ombi.Controllers.External
[HttpPost("mattermost")]
[HttpPost("mattermost")]
public bool Mattermost ( [ FromBody ] MattermostNotificationSettings settings )
public bool Mattermost ( [ FromBody ] MattermostNotificationSettings settings )
{
{
settings . Enabled = true ;
try
MattermostNotification . NotifyAsync (
{
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
settings . Enabled = true ;
MattermostNotification . NotifyAsync (
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Mattermost" ) ;
return false ;
}
return true ;
}
}
@ -145,11 +178,19 @@ namespace Ombi.Controllers.External
[HttpPost("slack")]
[HttpPost("slack")]
public bool Slack ( [ FromBody ] SlackNotificationSettings settings )
public bool Slack ( [ FromBody ] SlackNotificationSettings settings )
{
{
settings . Enabled = true ;
try
SlackNotification . NotifyAsync (
{
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
settings . Enabled = true ;
SlackNotification . NotifyAsync (
new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
return true ;
return true ;
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test Slack" ) ;
return false ;
}
}
}
/// <summary>
/// <summary>
@ -293,10 +334,18 @@ namespace Ombi.Controllers.External
[HttpPost("telegram")]
[HttpPost("telegram")]
public async Task < bool > Telegram ( [ FromBody ] TelegramSettings settings )
public async Task < bool > Telegram ( [ FromBody ] TelegramSettings settings )
{
{
settings . Enabled = true ;
try
await TelegramNotification . NotifyAsync ( new NotificationOptions { NotificationType = NotificationType . Test , RequestId = - 1 } , settings ) ;
{
settings . Enabled = true ;
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>
@ -307,9 +356,17 @@ namespace Ombi.Controllers.External
[HttpPost("sickrage")]
[HttpPost("sickrage")]
public async Task < bool > SickRage ( [ FromBody ] SickRageSettings settings )
public async Task < bool > SickRage ( [ FromBody ] SickRageSettings settings )
{
{
settings . Enabled = true ;
try
var result = await SickRageApi . Ping ( settings . ApiKey , settings . FullUri ) ;
{
return result ? . data ? . pid ! = null ;
settings . Enabled = true ;
var result = await SickRageApi . Ping ( settings . ApiKey , settings . FullUri ) ;
return result ? . data ? . pid ! = null ;
}
catch ( Exception e )
{
Log . LogError ( LoggingEvents . Api , e , "Could not test SickRage" ) ;
return false ;
}
}
}
}
}
}
}