From d408e7676870683f225a246ccbee5386777f5adf Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Tue, 27 Jun 2017 16:05:44 -0700
Subject: [PATCH] Clean up PHP script, defining all necessary vars

---
 send.php | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/send.php b/send.php
index ada4869..139611f 100644
--- a/send.php
+++ b/send.php
@@ -1,6 +1,22 @@
 <?php
 
-function im( $message = '', $channel = '#errors' ) {
+/**
+ * Parse log entry and format for webhook
+ *
+ * TODO: Switch to bash! This is a silly, vestigial implementation.
+ *
+ * @param string $message
+ * @param string $channel
+ * @param string $username
+ * @param string $icon_url
+ * @param string $webhook_url
+ * @return bool
+ */
+function im( $message = '', $channel = '#errors', $username = 'Error Bot', $icon_url = '', $webhook_url ) {
+	if ( ! is_string( $webhook_url ) ) {
+		return false;
+	}
+
 	static $counter = 1;
 
 	if ( '' == $message ) {
@@ -10,7 +26,7 @@ function im( $message = '', $channel = '#errors' ) {
 		$message = var_export( $message, true );
 	}
 
-	// Mattermost
+	// TODO: make an attachment?
 	$post_data = array(
 		'channel'  => $channel,
 		'username' => $username,
@@ -40,9 +56,13 @@ function im( $message = '', $channel = '#errors' ) {
 
 	curl_exec( $curl );
 	curl_close( $curl );
+	return true;
 }
 
-$message = isset( $argv[1] ) ? $argv[1] : '';
-$channel = isset( $argv[3] ) ? $argv[3] : '';
+$message     = isset( $argv[1] ) ? $argv[1] : null;
+$channel     = isset( $argv[2] ) ? $argv[2] : null;
+$username    = isset( $argv[3] ) ? $argv[3] : null;
+$icon_url    = isset( $argv[4] ) ? $argv[4] : null;
+$webhook_url = isset( $argv[5] ) ? $argv[5] : null;
 
-im( $message, $channel );
+im( $message, $channel, $username, $icon_url, $webhook_url );
-- 
GitLab