Beispiel #1
0
        static void Main(string[] args)
        {
            string        username     = "******";
            string        password     = "******";
            string        Url          = "https://api.us2.sumologic.com/api/v1/search/jobs";
            List <string> NameServer   = new List <string>();
            List <int>    CountServer  = new List <int>();
            string        DateTimenow  = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
            string        DateTimethen = DateTime.Now.AddDays(-7).ToString("yyyy-MM-ddTHH:mm:ss");

            string   TimeZone = "PST";
            QueryObj queryObj = new QueryObj
            {
                Query    = " count by host",//(eample of wrong query you need to change the query)
                From     = DateTimethen,
                To       = DateTimenow,
                TimeZone = TimeZone
            };

            Request request = new Request(); // new instance of the query it return a tuple for my example machine and count
            var     Result  = request.PostJsonDataToApi(queryObj, Url, username, password);

            for (int m = 0; m < Result.Item1.Count; m++)
            {
                Console.WriteLine("server : " + Result.Item1[m] + " number : " + Result.Item2[m]);
            }
            Console.ReadLine();
        }
Beispiel #2
0
 private void StreamWriter(HttpWebRequest httpWebRequest, QueryObj data)
 {
     using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
     {
         string mydata = new JavaScriptSerializer().Serialize(new
         {
             query    = data.Query,
             from     = data.From,
             to       = data.To,
             timeZone = data.TimeZone
         });
         streamWriter.Write(mydata);
         streamWriter.Flush();
         streamWriter.Close();
         streamWriter.Dispose();
     }
 }
Beispiel #3
0
        public Tuple <List <string>, List <int> > PostJsonDataToApi(QueryObj QueryObj, string Baseurl, string AccessId, string AccessKey)
        {
            string         credentials    = Base64Encode(AccessId, AccessKey);
            HttpWebRequest httpWebRequest = null;

            httpWebRequest = Prepare(httpWebRequest, credentials, Baseurl, "POST");
            StreamWriter(httpWebRequest, QueryObj);
            JobID          = GetJobID(httpWebRequest);
            httpWebRequest = Prepare(httpWebRequest, credentials, JobURL(Baseurl, JobID), "GET");
            if (GetJobStatus(httpWebRequest, JobID))
            {
                httpWebRequest = Prepare(httpWebRequest, credentials, MessageUrl(Baseurl, JobID), "GET");
                result         = GetResult(httpWebRequest, JobID);
            }
            JsonToList();
            var tuple = new Tuple <List <string>, List <int> >(NameServer, CountServer);

            return(tuple);
        }