示例#1
0
        // tools
        public string InitStartTime(string dateTime = null)
        {
            if (dateTime != null)
            {
                return(dateTime);
            }

            var _startTime = SALsA.GetInstance(Icm).ICM.GetCustomField(Constants.AnalyzerStartTimeField);

            if (_startTime != null)
            {
                try
                {
                    return(DateTime.Parse(_startTime).AddDays(-1).ToUniversalTime().ToString("o"));
                }
                catch { }
            }
            return(Kusto.KustoBase <DateTime> .DefaultStartTime);
        }
示例#2
0
        override protected void GenerateHTMLResult()
        {
            if (_Results.Length == 0)
            {
                Log.Information("Kusto query for {0}.{1}.{2} yielded empty results. Will skip.", Cluster, DataBase, Table);
                _HTMLResults = null;
                return;
            }
            var query = KustoQuery.Replace("|", Environment.NewLine + "|");

            query = String.Format("cluster('{0}').database('{1}').{2}{3}", Cluster, DataBase, query, Environment.NewLine);
            var htmlOut = ResourceUsage.BitMapToHTML(GenerateBitmap());
            var header  = String.Format("<p>Execute: [<a href=\"https://dataexplorer.azure.com/clusters/{0}.kusto.windows.net/databases/{1}?query={2}\">Web</a>] [<a href=\"https://{0}.kusto.windows.net/{1}?query={2}&amp;web=0\">Desktop</a>] [<a href=\"https://lens.msftcloudes.com/v2/#/discover/query//results?datasource=(cluster:{0}.kusto.windows.net,database:{1},type:Kusto)&amp;query={2}&amp;runquery=1\">Web (Lens)</a>] [<a href=\"https://{0}.kusto.windows.net/{1}?query={2}&amp;saw=1\">Desktop (SAW)</a>] <a href=\"https://{0}.kusto.windows.net/{1}\">https://{0}.kusto.windows.net/{1}</a></p><pre><code>{3}</code></pre>",
                                        this.Cluster, this.DataBase, Utility.Base64Encode(Utility.CompressString(query)), Utility.EncodeHtml(query));

            _HTMLResults = String.Format("{0}{1}", header, htmlOut);
            if (WriteToIcm == true)
            {
                SALsA.GetInstance(this.Icm)?.ICM.QueueICMDiscussion(_HTMLResults, htmlfy: false);
            }
        }
示例#3
0
 virtual protected void Init()
 {
     InitTask = new Task(() =>
     {
         try
         {
             kustoClient = new KustoClient(Cluster, DataBase, Icm);
             GenerateKustoQuery();
             _RawResults = kustoClient.Query(Table, ref KustoQuery, this.Icm, null, KustoBaseLimit);
             BuildResult();
             GenerateHTMLResult();
         }
         catch (Exception ex)
         {
             Log.Critical("Failed to query Kusto {0}.{1}.{2}", Cluster, DataBase, Table);
             Log.Exception(ex);
         }
     });
     InitTask.Start();
     SALsA.GetInstance(this.Icm)?.TaskManager.AddOneTask(this.InitTask);
 }
示例#4
0
        public List <object[]> Query(string table, ref string query, int icm, string timestampField = "TIMESTAMP", int limit = Constants.KustoClientQueryLimit)
        {
            if (timestampField != null)
            {
                // TODO : If ICM AnalyzerStartTimeField was changed, it might be newer than the ICM creation date
                DateTime startTime;
                if (!DateTime.TryParse(SALsA.GetInstance(icm).ICM.GetCustomField(Constants.AnalyzerStartTimeField), out startTime))
                {
                    startTime = SALsA.GetInstance(icm).ICM.CurrentICM.CreateDate.AddDays(-1);
                }
                string start = startTime.ToString("u");
                //string end = SALsA.GetInstance(icm).ICM.CurrentICM.CreateDate.ToString("u");
                query = String.Format("{0} | where {1} > datetime({2}) | {3} | limit {4}", table, timestampField, start, /*end,*/ query, limit);
            }
            else
            {
                query = String.Format("{0} | {1} | limit {2}", table, query, limit);
            }
            Log.Verbose("Sending {0} query : {1}", client.DefaultDatabaseName, query);
            var clientRequestProperties = new ClientRequestProperties()
            {
                ClientRequestId = Guid.NewGuid().ToString()
            };

            using (var reader = client.ExecuteQuery(query, clientRequestProperties))
            {
                DataTable dt = new DataTable();
                dt.Load(reader);
                List <object[]> data = new List <object[]>();
                data.Add(new object[dt.Columns.Count]);
                dt.Columns.CopyTo(data[0], 0);
                foreach (DataRow line in dt.Rows)
                {
                    data.Add(new object[dt.Columns.Count]);
                    line.ItemArray.CopyTo(data[data.Count - 1], 0);
                }
                return(data);
            }
        }