Exemplo n.º 1
0
 static void OnAlertReceived(object sender, IotqiAlert e)
 {
     Console.WriteLine();
     Console.WriteLine("InEventReceiver() - AlertName: {0}, Value: {1}, Data: {2}", e.AlertName, e.AlertValue, e.AlertData);
     Console.WriteLine();
     Console.WriteLine();
 }
Exemplo n.º 2
0
        // POST webhook/Iotqi
        public HttpResponseMessage Post([FromBody] IotqiAlert alertContent)
        {
            if (!IotqiWebhook.ValidateWebhookObject(Request, alertContent))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));;
            }
            //process actions to be taken here
            Program.dispatcher.Dispatch(alertContent);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
 public void Dispatch(IotqiAlert alertContent)
 {
     Alert?.Invoke(this, alertContent);
 }
Exemplo n.º 4
0
        internal static bool ValidateWebhookObject(HttpRequestMessage webhookMessage, IotqiAlert alertContent)
        {
            var signatureReceived = "";
            var signatureComputed = "";

            if (webhookMessage.Headers.TryGetValues("X-Iotqi-Signature", out IEnumerable <string> headerValues))
            {
                signatureReceived = headerValues.FirstOrDefault();
                signatureComputed = IotqiWebhook.GetHashString(JsonConvert.SerializeObject(alertContent).ToLower() + Program.WebhookCredentials);
            }

            if (!string.IsNullOrEmpty(signatureReceived) && signatureReceived != signatureComputed)
            {
                return(false);                           // received signature is invalid
            }
            if (string.IsNullOrEmpty(alertContent.AlertName))
            {
                return(false);                           // alerts must contain names; if this is null, the webhook POST is malformed
            }
            return(true);
        }