Ejemplo n.º 1
0
        /// <summary>
        /// Called when we have determined that we have 1 or more alert notification files which need
        /// to be uploaded.
        /// </summary>
        /// <param name="notifications"></param>
        protected void UploadNotifications(AlertNotificationFileList notificationFiles)
        {
            LogFile ourLog = LogFile.Instance;

            try
            {
                // Load the list of Alert Definitions as we will need to match these against the notifications
                AlertMonitorSettings alertMonitorSettings = AlertMonitorSettings.Load();
                //
                foreach (AlertNotificationFile notificationFile in notificationFiles.AlertNotificationFiles)
                {
                    ourLog.Write("Uploading Alert Notifications for " + notificationFile.AssetName, true);

                    // locate the asset for which these notifications have been created
                    //int assetID = lwDataAccess.AssetFind(notificationFile.AssetName, String.Empty);

                    // Skip any notifications for assets which we do not know about
                    //if (assetID == 0)
                    //    continue;

                    // The file may contain 1 or more individual alert triggers so iterate through them now
                    foreach (AlertNotification notification in notificationFile.AlertNotifications)
                    {
                        // We need to find the Alert Definition for which this alert has been generated
                        //AlertDefinition alertDefinition = alertMonitorSettings.FindAlert(notification.AlertName);
                        //if (alertDefinition == null)
                        //    continue;

                        // Create an alert in the database
                        Alert newAlert = new Alert();
                        newAlert.Type      = Alert.AlertType.alertmonitor;
                        newAlert.Category  = Alert.AlertCategory.changed;
                        newAlert.AssetName = notificationFile.AssetName;
                        newAlert.AlertName = notification.AlertName;
                        //
                        if (notification.Category != "")
                        {
                            newAlert.Message = notification.Category + @"\" + notification.Key;
                        }
                        else
                        {
                            newAlert.Message = notification.Key;
                        }
                        newAlert.Field1 = notification.OldValue;
                        newAlert.Field2 = notification.NewValue;

                        // Add the alert to the database
                        newAlert.Add();
                        ourLog.Write("....ADDING AN ALERT TO THE DATABASE, ID was " + newAlert.AlertID.ToString(), true);
                    }
                }
            }

            catch (Exception ex)
            {
                ourLog.Write("Exception occurred in [UploadNotifications], Exception Text is is " + ex.Message, true);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// UploadNow
        /// =========
        ///
        /// Called when the file system watcher has determined that a .ADF file has appeared in one of the
        /// watched audit data folders.
        ///
        /// Actually this is now called every 60 seconds as the file system watchers appeared to be very unreliable
        /// and could easily fail to initialize depending on system resources
        ///
        /// We need to check for various types of files
        ///
        ///		ADF - Audit Data Files created by v8 Scanners
        ///		ANF	- Alert Notification File created by Alert Monitor
        ///		AUD/SWA - Audit Files created by the USB/Mobile Device Scanners
        ///
        /// </summary>
        protected void UploadNow(string uploadFolder)
        {
            LogFile ourLog = LogFile.Instance;

            try
            {
                ourLog.Write("Uploading any new audit data files from [" + uploadFolder + "]", true);

                // Find all of the upload files in the specified folder
                List <AuditFileInfo> listAuditFiles = new List <AuditFileInfo>();
                AuditUploader        auditLoader    = new AuditUploader(uploadFolder, this._service.LicenseCount);
                auditLoader.EnumerateFiles(listAuditFiles);
                ourLog.Write("There are " + listAuditFiles.Count.ToString() + " new audit data files available", true);

                // sort the list by audit scan date
                listAuditFiles.Sort();

                // then upload each in turn
                int index = 0;
                foreach (AuditFileInfo thisAuditFile in listAuditFiles)
                {
                    try
                    {
                        ourLog.Write("Uploading audit data file [" + Path.GetFileName(thisAuditFile.Filename) + "]  Index : " + index.ToString(), true);
                        auditLoader.UploadAuditDataFile(thisAuditFile.AuditFile);
                    }
                    catch (Exception ex)
                    {
                        ourLog.Write("An exception occurred while uploading the audit file [" + thisAuditFile.Filename + "].  The error was [" + ex.Message + "]", true);
                        string backupFile = thisAuditFile.AuditFile.FileName.Replace(Path.GetExtension(thisAuditFile.Filename), ".ADF.ERROR");

                        if (File.Exists(backupFile))
                        {
                            File.Delete(backupFile);
                        }

                        File.Move(thisAuditFile.AuditFile.FileName, backupFile);

                        ourLog.Write("Erroneous audit file renamed to [" + backupFile + "]", true);
                    }
                }

                // OK Do we have any Alert Notification files that need uploading?
                ourLog.Write("Uploading any new alert notification files from [" + uploadFolder + "]", true);
                AlertNotificationFileList notifications = new AlertNotificationFileList();
                if (notifications.Populate(uploadFolder) != 0)
                {
                    UploadNotifications(notifications);
                }

                // Do we have any USB/Mobile Device audits to upload
                LyncAuditFileList listLyncAudits = new LyncAuditFileList();
                if (listLyncAudits.Populate(uploadFolder) != 0)
                {
                    UploadLyncAudits(listLyncAudits, uploadFolder);
                }

                ourLog.Write("...done", true);
            }

            catch (Exception ex)
            {
                ourLog.Write("Exception occurred in [UploadNow], Exception Text is " + ex.Message, true);
            }
        }