Exemplo n.º 1
0
        public static async Task Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Accept.Clear();
            httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.samanage.v2.1+json"));
            httpClient.DefaultRequestHeaders.Add("X-Samanage-Authorization", System.Environment.GetEnvironmentVariable("SaManageJWT"));
            var filter        = System.Environment.GetEnvironmentVariable("IncidentFilter");
            var incidentsJSON = await httpClient.GetStringAsync($"https://api.samanage.com/incidents.json?{filter}");

            dynamic incidents = JsonConvert.DeserializeObject(incidentsJSON);

            var newRequest = new AgilityRequest()
            {
                id         = incidents[0].number,
                state      = incidents[0].state,
                databaseID = "KES"
            };

            Uri url = new Uri(System.Environment.GetEnvironmentVariable("Automation_API_URL") + "/NewAgilityRequest/" + newRequest.state + "/" + newRequest.id);

            string strPayload = JsonConvert.SerializeObject(newRequest);

            log.LogInformation($"Requesting url: {url.AbsoluteUri}");

            HttpContent content = new StringContent(strPayload, Encoding.UTF8, "application/json");

            var result = httpClient.PostAsync(url, content).Result;

            log.LogInformation($"Posted request. Response:{result}");
        }
Exemplo n.º 2
0
 public static void Run(
     [HttpTrigger(AuthorizationLevel.Anonymous, "post", "get", Route = "NewAgilityRequest/{state}/{id}")] HttpRequest req, string state, string id,
     [CosmosDB(databaseName: "Test", collectionName: "NewAgilityDB", ConnectionStringSetting = "CosmosDB", PartitionKey = "{state}", Id = "{id}")] AgilityRequest agilityReq,
     [CosmosDB(databaseName: "Test", collectionName: "NewAgilityDB", ConnectionStringSetting = "CosmosDB")] out AgilityRequest document,
     ILogger log)
 {
     if (agilityReq == null)
     {
         string requestBody = new StreamReader(req.Body).ReadToEnd();
         document = JsonConvert.DeserializeObject <AgilityRequest>(requestBody);
         log.LogInformation($"Added info for ticket {document.id}");
     }
     else
     {
         document = null;
         log.LogInformation("Ticket was already logged.");
     }
 }