public async Task <IActionResult> GetDatasets()
        {
            var accessToken = await _tokenGenerator.GenerateADTokenWithRetries();

            if (string.IsNullOrEmpty(accessToken))
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, "Unable to generate AD token"));
            }
            var baseUrl     = _configuration["ProgrammaticExport:ApiEndpointUrl"];
            var datasetPath = _configuration["ProgrammaticExport:DatasetsPath"];

            using var client   = new HttpClient();
            client.BaseAddress = new Uri(baseUrl);
            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await client.GetAsync(datasetPath);

            if ((int)response.StatusCode != 200)
            {
                return(StatusCode((int)response.StatusCode, response));
            }
            var responseString = await response.Content.ReadAsStringAsync();

            APIOutput <ScheduledDatasetObject> datasetResultObject = JsonConvert.DeserializeObject <APIOutput <ScheduledDatasetObject> >(responseString);

            return(Ok(datasetResultObject));
        }
Esempio n. 2
0
    public APIOutput ProblemStatus(bool ignoreCertificate = false)
    {
        // Creating Variables
        RESTClient APIClient   = new RESTClient(Target);
        APIOutput  outputValue = new APIOutput();
        Dictionary <string, string> parameters = new Dictionary <string, string>
        {
            // Adding Parameters
            { "Api-Token", Token }
        };
        // API Call
        string APIResponse = APIClient.GetRequest("/problem/status", URLParameters: parameters, IgnoreCertificate: ignoreCertificate);

        outputValue.RawData = APIResponse;
        // Processing Response
        if (APIResponse == "Certificate Error")
        {
            outputValue.APIStatus = APIResult.CertificateError;
        }
        else
        {
            outputValue.APIStatus   = APIResult.Success;
            outputValue.OutputClass = JsonConvert.DeserializeObject <ProblemData.ProblemStatus.Root_Problemstatus>(APIResponse);
        }
        return(outputValue);
    }
        public async Task <IActionResult> CreateQuery(
            [FromQuery(Name = "query")] string query           = null,
            [FromQuery(Name = "query_name")] string query_name = null)
        {
            if (string.IsNullOrEmpty(query) || string.IsNullOrEmpty(query_name))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, "Query name and the query are mandatory"));
            }

            var accessToken = await _tokenGenerator.GenerateADTokenWithRetries();

            if (string.IsNullOrEmpty(accessToken))
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, "Unable to generate AD token"));
            }

            // Create the query
            ScheduledQueriesInputObject scheduledQueriesInputObject = new ScheduledQueriesInputObject
            {
                Query = query,
                Name  = query_name
            };

            var baseUrl   = _configuration["ProgrammaticExport:ApiEndpointUrl"];
            var queryPath = _configuration["ProgrammaticExport:QueryPath"];

            using var client   = new HttpClient();
            client.BaseAddress = new Uri(baseUrl);
            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var content = new StringContent(
                JsonConvert.SerializeObject(scheduledQueriesInputObject),
                System.Text.Encoding.UTF8,
                "application/json");

            HttpResponseMessage response = await client.PostAsync(queryPath, content);

            if ((int)response.StatusCode != 200)
            {
                return(StatusCode((int)response.StatusCode, response));
            }
            // Read output to get the queryId
            var responseString = await response.Content.ReadAsStringAsync();

            APIOutput <ScheduledQueriesObject> queryResultObject = JsonConvert.DeserializeObject <APIOutput <ScheduledQueriesObject> >(responseString);

            if (queryResultObject.TotalCount != 1)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, "Query creation failed"));
            }

            return(Ok(queryResultObject.Value.First().QueryId));
        }
Esempio n. 4
0
    public APIOutput Hosts(bool ignoreCertificate = false,
                           string tag             = "NA",
                           long startTimestamp    = -1,
                           long endTimestamp      = -1)
    {
        // Creating Variables
        RESTClient APIClient   = new RESTClient(Target);
        APIOutput  outputValue = new APIOutput();
        Dictionary <string, string> parameters = new Dictionary <string, string>
        {
            // Adding Parameters
            { "Api-Token", Token }
        };

        // Tag
        if (tag != "NA")
        {
            parameters.Add("tag", tag);
        }
        // Start Time
        if (startTimestamp != -1)
        {
            parameters.Add("startTimestamp", startTimestamp.ToString());
        }
        // End Time
        if (endTimestamp != -1)
        {
            parameters.Add("endTimestamp", endTimestamp.ToString());
        }
        // API Call
        string APIResponse = APIClient.GetRequest("/entity/infrastructure/hosts", URLParameters: parameters, IgnoreCertificate: ignoreCertificate);

        outputValue.RawData = APIResponse;
        // Processing Response
        if (APIResponse == "Certificate Error")
        {
            outputValue.APIStatus = APIResult.CertificateError;
        }
        else
        {
            outputValue.APIStatus   = APIResult.Success;
            outputValue.OutputClass = JsonConvert.DeserializeObject <List <TopologyData.Hosts.RootObject> >(APIResponse);
        }
        return(outputValue);
    }
Esempio n. 5
0
    public APIOutput TimeSeries(string TID,
                                bool ignoreCertificate        = false,
                                string EntityName             = "",
                                Filter_AggregationTypes AType = Filter_AggregationTypes.None,
                                Filter_TSRelativeTime relTime = Filter_TSRelativeTime.OneHour,
                                Filter_QueryMode qmode        = Filter_QueryMode.total)
    {
        // Creating Variables
        RESTClient APIClient   = new RESTClient(Target);
        APIOutput  outputValue = new APIOutput();
        Dictionary <string, string> parameters = new Dictionary <string, string>
        {
            // Adding Parameters
            { "Api-Token", Token },
            { "timeseriesId", TID },
            { "queryMode", qmode.ToString() }
        };

        // Aggregation Type
        if (AType != Filter_AggregationTypes.None)
        {
            parameters.Add("aggregationType", AType.ToString());
        }
        // Entity Name
        if (!string.IsNullOrEmpty(EntityName))
        {
            parameters.Add("entity", EntityName);
        }
        // Relative Time
        switch (relTime)
        {
        case Filter_TSRelativeTime.OneHour:
            parameters.Add("relativeTime", "hour");
            break;

        case Filter_TSRelativeTime.TwoHours:
            parameters.Add("relativeTime", "2hours");
            break;

        case Filter_TSRelativeTime.SixHours:
            parameters.Add("relativeTime", "6hours");
            break;

        case Filter_TSRelativeTime.Day:
            parameters.Add("relativeTime", "day");
            break;

        case Filter_TSRelativeTime.Week:
            parameters.Add("relativeTime", "week");
            break;

        case Filter_TSRelativeTime.Month:
            parameters.Add("relativeTime", "month");
            break;

        default:
            break;
        }
        // API Call
        string APIResponse = APIClient.GetRequest("/timeseries", URLParameters: parameters, IgnoreCertificate: ignoreCertificate);

        outputValue.RawData = APIResponse;
        // Processing Response
        if (APIResponse == "Certificate Error")
        {
            outputValue.APIStatus = APIResult.CertificateError;
        }
        else
        {
            outputValue.APIStatus   = APIResult.Success;
            outputValue.OutputClass = JsonConvert.DeserializeObject <TimeSeriesData.RootObject>(APIResponse);
        }
        return(outputValue);
    }
Esempio n. 6
0
    public APIOutput ProblemFeed(bool ignoreCertificate                   = false,
                                 Filter_ProblemStatus pStatus             = Filter_ProblemStatus.ALL,
                                 Filter_ProblemImpactLevel pImpactLevel   = Filter_ProblemImpactLevel.ALL,
                                 Filter_ProblemRelativeTime pRelativeTime = Filter_ProblemRelativeTime.OneHour)
    {
        // Creating Variables
        RESTClient APIClient   = new RESTClient(Target);
        APIOutput  outputValue = new APIOutput();
        Dictionary <string, string> parameters = new Dictionary <string, string>
        {
            // Adding Parameters
            { "Api-Token", Token }
        };

        // Status
        if (pStatus != Filter_ProblemStatus.ALL)
        {
            parameters.Add("status", pStatus.ToString());
        }
        // Impact Level
        if (pImpactLevel != Filter_ProblemImpactLevel.ALL)
        {
            parameters.Add("impactLevel", pImpactLevel.ToString());
        }
        // Relative Time
        switch (pRelativeTime)
        {
        case Filter_ProblemRelativeTime.OneHour:
            parameters.Add("relativeTime", "hour");
            break;

        case Filter_ProblemRelativeTime.TwoHours:
            parameters.Add("relativeTime", "2hours");
            break;

        case Filter_ProblemRelativeTime.SixHours:
            parameters.Add("relativeTime", "6hours");
            break;

        case Filter_ProblemRelativeTime.Day:
            parameters.Add("relativeTime", "day");
            break;

        case Filter_ProblemRelativeTime.Week:
            parameters.Add("relativeTime", "week");
            break;

        case Filter_ProblemRelativeTime.Month:
            parameters.Add("relativeTime", "month");
            break;

        default:
            break;
        }
        // API Call
        string APIResponse = APIClient.GetRequest("/problem/feed", URLParameters: parameters, IgnoreCertificate: ignoreCertificate);

        outputValue.RawData = APIResponse;
        // Processing Response
        if (APIResponse == "Certificate Error")
        {
            outputValue.APIStatus = APIResult.CertificateError;
        }
        else
        {
            outputValue.APIStatus   = APIResult.Success;
            outputValue.OutputClass = JsonConvert.DeserializeObject <ProblemData.ProblemFeed.Root_ProblemFeed>(APIResponse);
        }
        return(outputValue);
    }
        public async Task <IActionResult> ScheduleReport(
            [FromQuery(Name = "query_id")] string query_id                       = null,
            [FromQuery(Name = "report_name")] string report_name                 = null,
            [FromQuery(Name = "report_start_name")] string report_start_time     = null,
            [FromQuery(Name = "recurrence_interval")] string recurrence_interval = null,
            [FromQuery(Name = "recurrence_count")] string recurrence_count       = null)
        {
            if (string.IsNullOrEmpty(query_id) || string.IsNullOrEmpty(report_name))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, "Query Id and the report name are mandatory"));
            }

            var accessToken = await _tokenGenerator.GenerateADTokenWithRetries();

            if (string.IsNullOrEmpty(accessToken))
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, "Unable to generate AD token"));
            }

            ScheduledReportCreateInputObject scheduledReportCreateInputObject = new ScheduledReportCreateInputObject()
            {
                QueryId    = query_id,
                ReportName = report_name,
                //CallbackUrl should be a publicly accesible URL
                //CallbackUrl = "https://localhost:44365/reportready/",
                RecurrenceInterval = Int32.Parse(string.IsNullOrEmpty(recurrence_interval) ?
                                                 _configuration["ProgrammaticExport:RecurrenceInterval"] : recurrence_interval),
                RecurrenceCount = Int32.Parse(string.IsNullOrEmpty(recurrence_count) ?
                                              _configuration["ProgrammaticExport:RecurrenceCount"] : recurrence_count),
                StartTime = string.IsNullOrEmpty(report_start_time) ?
                            DateTime.UtcNow.AddMinutes(90).ToString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'") : report_start_time
            };

            var baseUrl    = _configuration["ProgrammaticExport:ApiEndpointUrl"];
            var reportPath = _configuration["ProgrammaticExport:ReportPath"];

            using var client   = new HttpClient();
            client.BaseAddress = new Uri(baseUrl);
            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {accessToken}");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var content = new StringContent(
                JsonConvert.SerializeObject(scheduledReportCreateInputObject),
                System.Text.Encoding.UTF8,
                "application/json");
            var response = await client.PostAsync(reportPath, content);

            if ((int)response.StatusCode != 200)
            {
                return(StatusCode((int)response.StatusCode, response));
            }
            var responseString = await response.Content.ReadAsStringAsync();

            APIOutput <ScheduledReportObject> reportResultObject = JsonConvert.DeserializeObject <APIOutput <ScheduledReportObject> >(responseString);

            if (reportResultObject.TotalCount != 1)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, "Report creation failed"));
            }

            return(Ok(reportResultObject.Value.First().ReportId));
        }