Beispiel #1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                log.Info("Mailer Service triggered");
                var incidentRepository = new IncidentRepository();
                var mailManager        = new MailManager();

                var incidents = await incidentRepository.GetIncidents(new DateTime(1971, 1, 1));

                log.Info($"Incidents found: {incidents.Count}");

                var sla = Decimal.Parse(AppSettingsProvider.GetSettingValue(INCIDENTS_SLA));
                var incidentsExceedingSla = incidentRepository.GetIncidentsExceedingSla(incidents, sla);
                log.Info($"Incidents exceeding SLA: {incidentsExceedingSla.Count}");


                if (incidentsExceedingSla != null && incidentsExceedingSla.Count > 0)
                {
                    log.Info("Attempting to send email");
                    mailManager.SendEmailForExceedingIncidents(incidentsExceedingSla, AppSettingsProvider.GetSettingValue(NOTIFICATION_SUBJECT));
                    log.Info("Emails sent");
                }

                return(req.CreateResponse(HttpStatusCode.OK, "Function completed"));
            }
            catch (Exception exception)
            {
                log.Error(exception.ToString());
                throw;
            }
        }
Beispiel #2
0
        public static void Run([TimerTrigger("0 0 */2 * * *")] TimerInfo myTimer, TraceWriter log)
        {
            log.Info($"Incident Notification Job triggered at: {DateTime.Now}");

            try
            {
                log.Info("Mailer Service triggered");
                var incidentRepository = new IncidentRepository();
                var mailManager        = new MailManager();

                var lastTrigger = myTimer.ScheduleStatus.Last;

                var incidents = incidentRepository.GetIncidents(lastTrigger).Result;
                log.Info($"Total Incidents found: {incidents.Count}");

                var sla = Decimal.Parse(AppSettingsProvider.GetSettingValue(INCIDENTS_SLA));
                var incidentsExceedingSla = incidentRepository.GetIncidentsExceedingSla(incidents, sla);
                log.Info($"Incidents exceeding SLA: {incidentsExceedingSla.Count}");


                if (incidentsExceedingSla != null && incidentsExceedingSla.Count > 0)
                {
                    log.Info("Attempting to send email");
                    mailManager.SendEmailForExceedingIncidents(incidentsExceedingSla, AppSettingsProvider.GetSettingValue(NOTIFICATION_SUBJECT));
                    log.Info("Emails sent");
                }
            }
            catch (Exception exception)
            {
                log.Error(exception.ToString());
                throw;
            }
        }
Beispiel #3
0
        public async Task <List <Incident> > GetIncidents(DateTime createdDateTime)
        {
            var createdDateStr = createdDateTime.ToString("yyyy-MM-dd");
            var pageSize       = int.Parse(AppSettingsProvider.GetSettingValue(TOPDESK_INCIDENTS_PAGESIZE));
            var offset         = 0;
            var incidents      = new List <Incident>();


            using (var httpClient = new HttpClient())
            {
                var authorizationHeader = await CreateTokenAuthorizationHeader();

                httpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader);
                var isResultPartial = true;

                do
                {
                    var incidentsUrl = string.Format(AppSettingsProvider.GetSettingValue(TOPDESK_INCIDENTS_ENDPOINT), AppSettingsProvider.GetSettingValue(TOPDESK_ENDPOINT), createdDateStr, offset, pageSize);
                    var response     = await httpClient.GetAsync(incidentsUrl);

                    isResultPartial = response.StatusCode == HttpStatusCode.PartialContent;
                    var result = await response.Content.ReadAsStringAsync();

                    var partialIncidents = JsonConvert.DeserializeObject <List <Incident> >(result);
                    incidents.AddRange(partialIncidents);


                    offset = offset + pageSize;
                } while (isResultPartial);
            }

            var incidentsSinceLastTimer = incidents.Where(incident => incident.CreationDate >= createdDateTime).ToList();

            return(incidentsSinceLastTimer);
        }
Beispiel #4
0
 public MailManager()
 {
     _senderEmailAddress   = AppSettingsProvider.GetSettingValue(EMAIL_SENDER_ID);
     _senderEmailPassword  = AppSettingsProvider.GetSettingValue(EMAIL_SENDER_PASSWORD);
     _smtpHost             = AppSettingsProvider.GetSettingValue(EMAIL_SMTP_CLIENT);
     _smtpPort             = int.Parse(AppSettingsProvider.GetSettingValue(EMAIL_SMTP_PORT));
     _receiverEmailAddress = AppSettingsProvider.GetSettingValue(NOTIFICATION_EMAIL_ID);
 }
Beispiel #5
0
        private async Task <string> GetAuthorizationToken()
        {
            var operatorName     = AppSettingsProvider.GetSettingValue(OPERATOR_USERNAME);
            var operatorPassword = AppSettingsProvider.GetSettingValue(OPERATOR_PASSWORD);
            var loginUrl         = string.Format(AppSettingsProvider.GetSettingValue(TOPDESK_LOGIN_ENDPOINT), AppSettingsProvider.GetSettingValue(TOPDESK_ENDPOINT));

            using (var httpClient = new HttpClient())
            {
                var authorizationHeader = CreateBasicAuthorizationHeader(operatorName, operatorPassword);
                httpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader);

                var response = await httpClient.GetAsync(loginUrl);

                var result = await response.Content.ReadAsStringAsync();

                return(result);
            }
        }