External notifications, webhooks, MQTT etc

Really is! Obviously needs a little more to catch exceptions, authentication and filter just the log types that I want. Maybe eventually a UI to configure these options too.

<?php

/**
 * @file
 * Contains farm_events_http.module.
 */
use Drupal\Core\Entity\EntityInterface;
/**
 * Implements hook_ENTITY_TYPE_update().
 */
function farm_events_http_log_update(EntityInterface $entity) {
	
$log = $entity->toArray();
//Create httpClient.
$client = \Drupal::httpClient();
//Sending POST Request with $json_data to external server
$request = $client->post('http://192.168.1.7:1880/farmos/webhook', [ 'json' => $log]);
//Getting Response after JSON Decode.
$response = json_decode($request->getBody());

Really opens options for Node-Red automations.

1 Like