From 2509134b70005e5d5d9958cf896e0741a62cde50 Mon Sep 17 00:00:00 2001
From: Erick Hitter <erick@ethitter.com>
Date: Tue, 27 Jun 2017 22:53:52 +0000
Subject: [PATCH] Port basics from the existing scheme

---
 pipe.sh  |  3 +++
 send.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
 create mode 100755 pipe.sh
 create mode 100644 send.php

diff --git a/pipe.sh b/pipe.sh
new file mode 100755
index 0000000..b32fce3
--- /dev/null
+++ b/pipe.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+tail -Fq log.log | while read x ; do php im.php "$x" "#errors"; done
diff --git a/send.php b/send.php
new file mode 100644
index 0000000..ada4869
--- /dev/null
+++ b/send.php
@@ -0,0 +1,48 @@
+<?php
+
+function im( $message = '', $channel = '#errors' ) {
+	static $counter = 1;
+
+	if ( '' == $message ) {
+		$message = 'debug ' . $counter;
+		$counter++;
+	} elseif ( is_array( $message ) || is_object( $message ) ) {
+		$message = var_export( $message, true );
+	}
+
+	// Mattermost
+	$post_data = array(
+		'channel'  => $channel,
+		'username' => $username,
+		'icon_url' => $icon_url,
+		'text'     => "```\n{$message}\n```",
+	);
+
+	$curl = curl_init();
+
+	$body = json_encode( $post_data );
+
+	curl_setopt_array(
+		$curl, array(
+			CURLOPT_URL            => $webhook_url,
+			CURLOPT_RETURNTRANSFER => true,
+			CURLOPT_ENCODING       => '',
+			CURLOPT_FOLLOWLOCATION => true,
+			CURLOPT_TIMEOUT        => 10,
+			CURLOPT_CUSTOMREQUEST  => 'POST',
+			CURLOPT_POSTFIELDS     => $body,
+			CURLOPT_HTTPHEADER     => array(
+				'Content-Type: application/json',
+				'Content-Length: ' . strlen( $body ),
+			),
+		)
+	);
+
+	curl_exec( $curl );
+	curl_close( $curl );
+}
+
+$message = isset( $argv[1] ) ? $argv[1] : '';
+$channel = isset( $argv[3] ) ? $argv[3] : '';
+
+im( $message, $channel );
-- 
GitLab