Пример #1
0
        private static void SendDataDrivenEmail(MySqlConnection con)
        {
            Dictionary <string, string> dictFlareSystemConfigurationEntries = SystemConfigurationEntry.GetDictionary(con);

            if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerAddress))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server address is specified");
            }

            if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerUserName))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server user name is specified");
            }

            if (!dictFlareSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerPassword))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server password is specified");
            }

            string       strSMTPServerAddress  = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerAddress];
            string       strSMTPServerUserName = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerUserName];
            string       strSMTPServerPassword = dictFlareSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerPassword];
            const string strFrom    = @"*****@*****.**";
            const string strTo      = @"*****@*****.**";
            const string strSubject = @"Data-driven e-mail test";
            string       strBody    = string.Format(@"Hello Tom; It is now {0} Universal Time.",
                                                    MySqlUtils.DateTimeToString(DateTime.UtcNow));

            Console.WriteLine(@"About to send data-driven e-mail to {0}...", strTo);
            MailUtils.SendMail(strSMTPServerAddress, strSMTPServerUserName, strSMTPServerPassword,
                               strFrom, strTo, null, null, strSubject, strBody);
            Console.WriteLine(@"E-mail sent.");
        }
Пример #2
0
        protected void lbSearchResultSummaries_SelectedIndexChanged(object sender, EventArgs e)
        {
            string strSelectedSearchResultSummary = lbSearchResultSummaries.SelectedValue;

            if (strSelectedSearchResultSummary == null || !SearchResults.ContainsKey(strSelectedSearchResultSummary))
            {
                ClearSelectedSearchResultFields();
                return;
            }

            TargetLogRecord tlrSearchResult = SearchResults[strSelectedSearchResultSummary];

            tbLogRecordID.Text  = tlrSearchResult.LogID.ToString();
            tbTargetID.Text     = tlrSearchResult.TargetID.ToString();
            tbTimeStamp.Text    = MySqlUtils.DateTimeToString(tlrSearchResult.TimeStamp);
            tbStatus.Text       = tlrSearchResult.Status.ToString();
            tbMessage.Text      = tlrSearchResult.Message;
            tbErrorCode.Text    = tlrSearchResult.ErrorCode.ToString();
            tbLocationID.Text   = tlrSearchResult.LocationID.ToString();
            tbResponseTime.Text = tlrSearchResult.ResponseTime.ToString();
        }
Пример #3
0
        protected override void PageLoadWorker(object sender, EventArgs e)
        {
            bool bPopulateTargetNamesListBox = false;

            // Ensure that m_dictTargets is set.
            m_dictTargets         = TargetNameToIDDictionary;
            m_dictTargetsIDToName = TargetIDToNameDictionary;

            if (m_dictTargets == null)
            {
                MySqlConnection con = GetMySqlConnection();

                m_dictTargets               = NamedAndNumberedDatabaseObject.GetNameToIDDictionary(con, Target.SelectIDAndNameCommand);
                TargetNameToIDDictionary    = m_dictTargets;
                m_dictTargetsIDToName       = null; // Force a rebuild of the Targets ID To Name dictionary.
                bPopulateTargetNamesListBox = true;
            }
            else if (!IsPostBack)
            {
                bPopulateTargetNamesListBox = true;
            }

            if (bPopulateTargetNamesListBox)
            {
                WebUtils.PopulateListItemCollectionFromStringEnumerable(m_dictTargets.Keys, lbTargetNames.Items);
            }

            if (m_dictTargetsIDToName == null)
            {
                /*
                 * m_dictTargetsIDToName = new Dictionary<uint, string>();
                 *
                 * foreach (KeyValuePair<string, uint> kvp in m_dictTargets)
                 * {
                 *  m_dictTargetsIDToName.Add(kvp.Value, kvp.Key);
                 * }
                 */
                m_dictTargetsIDToName = NamedAndNumberedDatabaseObject.GetIDToNameDictionary(m_dictTargets);

                TargetIDToNameDictionary = m_dictTargetsIDToName;
            }

            bool bPopulateAccountNamesListBox = false;

            // Ensure that m_dictAccounts is set.
            m_dictAccounts = AccountNameToIDDictionary;

            if (m_dictAccounts == null)
            {
                MySqlConnection con = GetMySqlConnection();

                m_dictAccounts               = NamedAndNumberedDatabaseObject.GetNameToIDDictionary(con, Account.SelectIDAndNameCommand);
                AccountNameToIDDictionary    = m_dictAccounts;
                bPopulateAccountNamesListBox = true;
            }
            else if (!IsPostBack)
            {
                bPopulateAccountNamesListBox = true;
            }

            if (bPopulateAccountNamesListBox)
            {
                WebUtils.PopulateListItemCollectionFromStringEnumerable(m_dictAccounts.Keys, lbAccountNames.Items);
            }

            if (!IsPostBack)
            {
                string strNow = MySqlUtils.DateTimeToString(DateTime.UtcNow); //dtNow.ToString(@"yyyy-MM-dd HH:mm:ss");

                rbAny.Checked          = true;
                lbTargetNames.Enabled  = false;
                lbAccountNames.Enabled = false;

                tbStartTimeStamp.Enabled = false;
                tbStartTimeStamp.Text    = strNow;
                tbEndTimeStamp.Enabled   = false;
                tbEndTimeStamp.Text      = strNow;
            }

            if (SearchResults == null)
            {
                ClearSelectedSearchResultFields();
            }
        }
Пример #4
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            uint unTargetID = 0;

            if (rbTarget.Checked)
            {
                string strSelectedTargetName = lbTargetNames.SelectedValue;

                if (strSelectedTargetName == null)
                {
                    throw new Exception(@"Cannot search by target: no target name is selected");
                }

                unTargetID = m_dictTargets[strSelectedTargetName];
            }

            uint unAccountID = 0;

            if (rbAccount.Checked)
            {
                string strSelectedAccountName = lbAccountNames.SelectedValue;

                if (strSelectedAccountName == null)
                {
                    throw new Exception(@"Cannot search by account: no account name is selected");
                }

                unAccountID = m_dictAccounts[strSelectedAccountName];
            }

            bool     bFailedOnly       = cbFailuresOnly.Checked;
            DateTime?ndtStartTimeStamp = null;

            if (cbStartTimeStamp.Checked)
            {
                ndtStartTimeStamp = DateTime.Parse(tbStartTimeStamp.Text);
            }

            DateTime?ndtEndTimeStamp = null;

            if (cbEndTimeStamp.Checked)
            {
                ndtEndTimeStamp = DateTime.Parse(tbEndTimeStamp.Text);
            }

            string                 strCommandText   = TargetLogRecord.GetSelectCommand(unTargetID, unAccountID, bFailedOnly, ndtStartTimeStamp, ndtEndTimeStamp);
            MySqlConnection        con              = GetMySqlConnection();
            List <TargetLogRecord> lstSearchResults = TargetLogRecord.GetRecords(con, strCommandText);
            Dictionary <string, TargetLogRecord> dictSearchResults = new Dictionary <string, TargetLogRecord>();

            foreach (TargetLogRecord tlr in lstSearchResults)
            {
                uint   unTargetID2      = tlr.TargetID;
                string strRecordSummary = string.Format(@"{0} {1} {2}",
                                                        //tlr.TimeStamp.ToString(@"yyyy-MM-dd HH:mm:ss"),
                                                        MySqlUtils.DateTimeToString(tlr.TimeStamp),
                                                        tlr.Status,
                                                        m_dictTargetsIDToName.ContainsKey(unTargetID2) ? m_dictTargetsIDToName[unTargetID2] : unTargetID2.ToString());

                dictSearchResults.Add(strRecordSummary, tlr);
            }

            // Store (lstSearchResults and) dictSearchResults in the Session.
            SearchResults = dictSearchResults;

            WebUtils.PopulateListItemCollectionFromStringEnumerable(dictSearchResults.Keys, lbSearchResultSummaries.Items);

            ClearSelectedSearchResultFields();
        }
Пример #5
0
        // Send an e-mail to each of the target's account's contacts.

        private void SendFailureNotificationEmails(Target target, TargetLogRecord tlr)
        {
            if (!m_dictSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerAddress))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server address is specified");
            }

            if (!m_dictSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerUserName))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server user name is specified");
            }

            if (!m_dictSystemConfigurationEntries.ContainsKey(SystemConfigurationEntryKeys.SMTPServerPassword))
            {
                throw new Exception(@"Flare system configuration error: No SMTP server password is specified");
            }

            string       strSMTPServerAddress  = m_dictSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerAddress];
            string       strSMTPServerUserName = m_dictSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerUserName];
            string       strSMTPServerPassword = m_dictSystemConfigurationEntries[SystemConfigurationEntryKeys.SMTPServerPassword];
            const string strFrom    = @"Flare Server Monitoring";
            const string strSubject = @"Server monitoring failure notification";

            foreach (Contact contact in m_lstAllContacts)
            {
                if (contact.AccountID != target.AccountID || !contact.Enabled)  // We could filter out disabled contacts at the SQL level
                {
                    continue;
                }

                string strBody = string.Format(@"Hello {0} {1}; Your server '{2}' was unreachable at {3} Universal Time.",
                                               contact.FirstName, contact.LastName, target.Name, MySqlUtils.DateTimeToString(tlr.TimeStamp));

#if DO_NOT_SEND_EMAILS
                LogToConsole(@"**** Simulating the sending of e-mail ****");
                LogToConsole(string.Format(@"SMTP Server Address : {0}", strSMTPServerAddress));
                LogToConsole(string.Format(@"SMTP Server User Name : {0}", strSMTPServerUserName));
                LogToConsole(string.Format(@"SMTP Server Password : {0}", strSMTPServerPassword));
                LogToConsole(string.Format(@"From : {0}", strFrom));
                LogToConsole(string.Format(@"To : {0}", contact.EmailAddress));
                LogToConsole(string.Format(@"Subject : {0}", strSubject));
                LogToConsole(string.Format(@"Body : {0}", strBody));
                LogToConsole(@"**** End of e-mail ****");
#else
                MailUtils.SendMail(strSMTPServerAddress, strSMTPServerUserName, strSMTPServerPassword,
                                   strFrom, contact.EmailAddress, null, null, strSubject, strBody);
#endif
            }
        }