Beispiel #1
0
        public static void Search(SearchPayload payload)
        {
            Console.WriteLine("Start Searching...");
            HttpWebRequest tryThis = (HttpWebRequest)WebRequest.Create("https://jarvis-west.dc.ad.msft.net/user-api/v1/config/security/HPSTSUrl/securityLevel/TwoFA?_=" + DateTimeUtils.GetMillisFromEpoch());

            //HEADER INFO
            tryThis.Accept = "application/json, text/javascript, */*; q=0.01";
            tryThis.Headers.Add("accept-encoding", "gzip, deflate, br");
            tryThis.Method      = "GET";
            tryThis.ContentType = "application/json";
            tryThis.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
            tryThis.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            tryThis.Headers.Add("accept-encoding", "gzip, deflate, br");
            tryThis.Headers.Add("accept-language", "en-US,en;q=0.9");
            tryThis.Headers.Add("clientid", "Jarvis");
            tryThis.Headers.Add("origin", JARVIS_URL);
            tryThis.Headers.Add("csrftoken", Properties.Get("CSRFToken"));
            tryThis.CookieContainer = GetCookies();
            Console.WriteLine("ASDF: " + GetStringResponse(tryThis));

            HttpWebRequest request = CreatePOSTRequest("https://jarvis-west.dc.ad.msft.net/user-api/v2/logs/startSearchV2");

            //HEADER INFO
            request.Accept = "application/json, text/javascript, */*; q=0.01";
            request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
            request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-US,en;q=0.9");
            request.Headers.Add("clientid", "Jarvis");
            request.CookieContainer = GetCookies();
            request.Headers.Add("csrftoken", "hjk8y6+PqcIxMQRjuroq8Z2DNxwQCt1X31SoOCTME53zEzrC6nI2xjWth74HGGg9jOXP/uYAjFX8AqXZimlqvPv30LrgksPEO0K0XSPELpNGcDdx6dKG5YWADPYAEyOo2XTVC+/lcYfsa5bP+iyUOy3zNVtouO4q80oypyM3tXuaYxl5EUazv2ux8pUTjsbMe2JD4+8DUtYLjHGDqlftP72CCrL+iayIJVReZGWi+q6h/vYwMBIGW8T8Vd9iVrLgboSfvpmNczXDC1X0fapN6QYuUK8J1yNGQrEgwYqzK6rns1ie4lj9yVTUpRSABOxI+e0Kh7K+nkTp43SiYtAuEg==");
            request.Headers.Add("dnt", "1");
            request.Headers.Add("origin", JARVIS_URL);
            request.Referer   = "https://jarvis-west.dc.ad.msft.net/logs/dgrep?page=logs&be=DGrep&offset=-15&offsetUnit=Minutes&UTC=false&ep=FirstParty%20PROD&ns=RunnerService&en=RunnerCentralEventTable&conditions=[[%22Status%22,%22%3D%3D%22,%22Unhealthy%22],[%22Role%22,%22%3D%3D%22,%22RunnerContainer%22],[%22InstanceName%22,%22contains%22,%22/Us_11_Content/Primary/%22],[%22Name%22,%22%3D%3D%22,%22ngspouploaddoc%22]]&clientQuery=where%20Status!%3D%22Dead%22%20%26%26%20UserField2!%3D%22%22%20let%20Error%3DUserField2.Substring(0,%20UserField2.IndexOf(%22%7C%22))%20let%20MachineName%3DRegex.Match(UserField2,%22%5C]MachineInfo::(.*?)%5C%7C%22).Groups[1].Value%20let%20CorrelationId%3DRegex.Match(UserField2,%22%5C]CorrelationId::(.*?)%5C%7C%22).Groups[1].Value%20let%20StartTimeUtc%3DRegex.Match(UserField2,%22%5C]ExecutionStartTime::(.*?)%5C%7C%22).Groups[1].Value%20let%20EndTimeUtc%3DRegex.Match(UserField2,%22%5C]ExecutionEndTime::(.*?)%5C%7C%22).Groups[1].Value%20let%20Farm%3DRegex.Match(InstanceName,%22.*?/.*?/(.*?)/[12]%22).Groups[1].Value.Trim()%20let%20Latency%3DInt32.Parse(Regex.Match(UserField2,%22%5C]AlertingLatency::(.*?)%5C%7C%22).Groups[1].Value)%20let%20InstanceNum%3DInstanceName.Split(%27/%27).Last()%20let%20HttpStatus%3DRegex.Match(UserField2,%22%5C]HttpStatus::(.*?)%5C%7C%22).Groups[1].Value%20let%20NetworkId%3DRegex.Match(UserField2,%22%5C]NetworkId::(.*?)%5C%7C%22).Groups[1].Value%20let%20FarmId%3DRegex.Match(UserField2,%22%5C]FarmId::(.*?)%5C%7C%22).Groups[1].Value%20let%20Url%3DRegex.Match(UserField2,%22%5C]Url::(.*?)%5C%7C%22).Groups[1].Value%20let%20ExecutionId%3DRegex.Match(UserField2,%22%5C]RowKey::(.*?)%5C%7C%22).Groups[1].Value%20select%20InstanceNum,Farm,Error,StartTimeUtc,EndTimeUtc,MachineName,CorrelationId,Latency,HttpStatus,NetworkId,FarmId,Url,ExecutionId&chartEditorVisible=true&chartType=Line&chartLayers=[[%22New%20Layer%22,%22%22]]%20";
            request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36";

            byte[] content = ConvertPayloadToContentByteArray(payload);
            request.ContentLength = content.Length;
            using (Stream dataStream = request.GetRequestStream())
            {
                dataStream.Write(content, 0, content.Length);
                dataStream.Close();
            }

            // Get response; don't care about return since this just initiates the search
            Console.WriteLine("ASDF2: " + GetStringResponse(request));
        }
        public static FailedProbesOverview Get(string farmLabel, SiteEnum site, DateTime startTime, DateTime endTime)
        {
            FailedProbesOverview overview = new FailedProbesOverview();

            string searchID = Guid.NewGuid().ToString();
            // start the search
            SearchPayload payload = new SearchPayload
            {
                EndTime    = DateTimeUtils.ToZuluString(endTime),
                Endpoint   = ENDPOINT,
                EventNames = new List <string>()
                {
                    "RunnerCentralEventTable"
                },
                IdentityColumns = new Dictionary <string, string>(),
                MaxResults      = 50000,
                Namespaces      = new List <string>()
                {
                    "RunnerService"
                },
                Query          = null,
                QueryID        = searchID,
                QueryType      = 0,
                SearchCriteria = new List <LogSearchCriteria>()
                {
                    new LogSearchCriteria
                    {
                        Key       = "Status",
                        Operation = 1,
                        Value     = "Unhealthy"
                    },
                    new LogSearchCriteria
                    {
                        Key       = "Role",
                        Operation = 1,
                        Value     = "RunnerContainer"
                    },
                    new LogSearchCriteria
                    {
                        Key       = "InstanceName",
                        Operation = 5,
                        Value     = "/" + farmLabel + "/Primary/"
                    },
                    new LogSearchCriteria
                    {
                        Key       = "Name",
                        Operation = 1,
                        Value     = "ngspo" + site.GetSiteName()
                    }
                },
                StartTime = DateTimeUtils.ToZuluString(startTime)
            };

            FailedProbesRequester.Search(payload);

            // search started, let's ping until we find results
            SearchResponse lastResponse;
            int            count = 0;

            do
            {
                Console.WriteLine("sleeping...");
                Thread.Sleep(1000);
                lastResponse = FailedProbesRequester.Ping(searchID);
            } while (!lastResponse.Status.Equals("Completed") && count++ < 60);

            Console.WriteLine("COUNT: " + count);

            // search is complete, let's grab top 20 results
            lastResponse = FailedProbesRequester.GetFailedProbes(searchID);

            Console.Write(lastResponse);
            return(overview);
        }