/*creates alarm actions and logs info into database*/ public void createActions(SNSAlarm myAlarm) { SNS_Alarm_Action myAlarmAction; SNS_Action mySNSAction; // Settings mySettings; //create a new alarm action myAlarmAction = new SNS_Alarm_Action(myAlarm.Name, myAlarm.Type, myAlarm.Subject); //figure out what to do for that action mySNSAction = new SNS_Action(myAlarmAction.name, myAlarmAction.subject, myAlarmAction.type); //set that action for SNS_Alarm_Action myAlarmAction.typeSNSAction = mySNSAction; //add alarm action to database //log alarm Event alarmEvent = new Event("source", myAlarm, myAlarmAction, mySNSAction); //add to database using (AWS_SNS_API_Context myDbContext = new AWS_SNS_API_Context()) { myDbContext.Alarms.Add(myAlarm); myDbContext.SNSAlarmActions.Add(myAlarmAction); myDbContext.SNSActions.Add(mySNSAction); myDbContext.EventLog.Add(alarmEvent); myDbContext.SaveChanges(); } performAction(myAlarmAction); }
/*perform action requested from SNS alarm*/ public void performAction(SNS_Alarm_Action action) { if (action.typeSNSAction.cName == className.EMAIL) { try { MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**"); mail.Subject = action.subject; mail.Body = "This is an email from an SNS alarm"; SmtpClient SmtpClient = new SmtpClient("smtp.gmail.com", 587); SmtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "merklesns"); SmtpClient.EnableSsl = true; SmtpClient.Send(mail); Console.WriteLine("Message sent"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }