Exemplo n.º 1
0
        public async Task <HttpResponseMessage> Get()
        {
            var events = new List <ServerSideEvent>();

            try
            {
                events = await EventLogParser.GetEvents(EventLogFile);

                return(Request.CreateResponse(HttpStatusCode.OK, events));
            }
            catch (XmlException)
            {
                RenameEventLogFile();
                return(Request.CreateResponse(HttpStatusCode.OK, events));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 2
0
        public Task <EventLogResponse> Get(string stack = null, string startTime = null, string endTime = null)
        {
            DateTime startTimeUtc, endTimeUtc;
            TimeSpan timeGrainTimeSpan;
            string   errorMessage;

            if (!PrepareStartEndTimeUtc(startTime, endTime, null, out startTimeUtc, out endTimeUtc, out timeGrainTimeSpan, out errorMessage))
            {
                if (Request == null)
                {
                    throw new WebException(HttpStatusCode.BadRequest.ToString() + ": " + errorMessage);
                }

                throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage));
            }

            Parser parser = new EventLogParser();

            return(parser.GetEventLogs(stack, startTimeUtc, endTimeUtc));
        }
        private void ParseEventLog()
        {
            StivLibrary.EventLogParser SELP = new EventLogParser();
            //Copy the eventlist from the Jobber to local variable, then clear it so we dont have to send it back and forth.
            GV.CurrentActionForLog = "Parsing at " + DateTime.Now.ToShortTimeString();
            //Note to self.  Using an equals is almost a link.   Update source hoses copy.  Lets iterate instead.
            foreach (var aneventski in Job2Do.EventList)
            {
                Eventlist.Add(aneventski);
            }
            Job2Do.EventList.Clear();
            Job2Do.status = "Started";

            Job2Do.TaskStatusColor = "Yellow";
            Job2Do.taskdetails.Add("Starting to parse " + Eventlist.Count.ToString(), Job2Do.Taskname);

            NotifyConsole();

            int Critcount  = 0;
            int Errorcount = 0;
            int Warncount  = 0;
            int Infcount   = 0;

            try
            {
                //Start a parsing here and then add to return values
                foreach (var AnEventType in Eventlist)
                {
                    int seconds = AnEventType.EventAgeHours * 24 * 3600 + AnEventType.EventAgeHours * 3600 + AnEventType.EventAgeMinutes * 60;
                    var result  = SELP.QueryActiveLog(AnEventType.source, seconds, AnEventType.EventLevel);
                    foreach (KeyValuePair <string, string> KVP in result)
                    {
                        if (!Job2Do.taskdetails.ContainsKey(KVP.Key))
                        {
                            Job2Do.taskdetails.Add(KVP.Key, KVP.Value);
                        }
                        else
                        {
                            string oldie  = Job2Do.taskdetails[KVP.Key];
                            string newbie = KVP.Value + oldie;
                            Job2Do.taskdetails[KVP.Key] = newbie;
                        }
                    }
                }
                Job2Do.TaskStatusColor = "Green";

                //Count Types:
                foreach (string details in Job2Do.taskdetails.Values)
                {
                    string[] source = details.Split(new char[] { '.', '?', '!', ' ', ';', ',' }, StringSplitOptions.RemoveEmptyEntries);

                    var matchQueryInformation = from word in source where word.ToLowerInvariant() == "Level:Information".ToLowerInvariant()  select word;
                    Infcount += matchQueryInformation.Count();

                    var matchQueryWarn = from word in source where word.ToLowerInvariant() == "Level:Warning".ToLowerInvariant() select word;
                    Warncount += matchQueryWarn.Count();

                    var matchQueryErr = from word in source where word.ToLowerInvariant() == "Level:Error".ToLowerInvariant() select word;
                    Errorcount += matchQueryErr.Count();

                    var matchQueryCrit = from word in source where word.ToLowerInvariant() == "Level:Critical".ToLowerInvariant() select word;
                    Critcount += matchQueryCrit.Count();
                }


                if (Warncount > 0)
                {
                    Job2Do.TaskStatusColor = "Yellow";
                }
                if (Errorcount > 0)
                {
                    Job2Do.TaskStatusColor = "Orange";
                }
                if (Warncount > 0)
                {
                    Job2Do.TaskStatusColor = "Red";
                }

                Job2Do.status      = "Completed";
                Job2Do.tasksummary = String.Format("Crit:{0}  Err:{1} Warn:{2}  Inf:{3}", Critcount.ToString(), Errorcount.ToString(), Warncount.ToString(), Infcount.ToString());


                Job2Do.timecompleted = DateTime.Now;
            }
            catch (Exception ex)
            {
                GV.CurrentActionForLog = "Parsing failed " + DateTime.Now.ToShortTimeString();
                Job2Do.status          = "Failed";
                Job2Do.TaskStatusColor = "Red";
                Job2Do.taskdetails.Add("Failed!", ex.ToString());
            }
        }