From da6a22c71af46218a38766dc2e23ac8763f252c6 Mon Sep 17 00:00:00 2001
From: Ander Punnar <ander@kvlt.ee>
Date: Wed, 3 Apr 2019 01:11:03 +0300
Subject: [PATCH 1/2] new type: __check_messages

---
 .../conf/type/__check_messages/gencode-remote | 27 ++++++++++
 cdist/conf/type/__check_messages/man.rst      | 52 +++++++++++++++++++
 .../type/__check_messages/parameter/required  |  2 +
 3 files changed, 81 insertions(+)
 create mode 100755 cdist/conf/type/__check_messages/gencode-remote
 create mode 100644 cdist/conf/type/__check_messages/man.rst
 create mode 100644 cdist/conf/type/__check_messages/parameter/required

diff --git a/cdist/conf/type/__check_messages/gencode-remote b/cdist/conf/type/__check_messages/gencode-remote
new file mode 100755
index 00000000..1b4cf247
--- /dev/null
+++ b/cdist/conf/type/__check_messages/gencode-remote
@@ -0,0 +1,27 @@
+#!/bin/sh -e
+#
+# 2019 Ander Punnar (ander-at-kvlt-dot-ee)
+#
+# This file is part of cdist.
+#
+# cdist is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# cdist is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with cdist. If not, see <http://www.gnu.org/licenses/>.
+#
+
+if grep -Eq \
+    "$( cat "$__object/parameter/pattern" )" \
+    "$__messages_in"
+then
+    cat "$__object/parameter/execute" \
+        | tee "$__messages_out"
+fi
diff --git a/cdist/conf/type/__check_messages/man.rst b/cdist/conf/type/__check_messages/man.rst
new file mode 100644
index 00000000..cb505cea
--- /dev/null
+++ b/cdist/conf/type/__check_messages/man.rst
@@ -0,0 +1,52 @@
+cdist-type__check_messages(7)
+=============================
+
+NAME
+----
+cdist-type__check_messages - Check messages for pattern and execute command on match.
+
+
+DESCRIPTION
+-----------
+Check messages for pattern and execute command on match.
+
+This type is useful if you chain together multiple related types using
+dependencies and want to restart service if at least one type changes
+something.
+
+For more information about messages see `cdist messaging <cdist-messaging.html>`_.
+
+For more information about dependencies and execution order see
+`cdist manifest <cdist-manifest.html#dependencies>`_ documentation.
+
+
+REQUIRED PARAMETERS
+-------------------
+pattern
+   Search pattern (passed to ``grep -E``).
+
+execute
+   Command to execute on pattern match.
+
+
+EXAMPLES
+--------
+
+.. code-block:: sh
+
+    __check_messages munin \
+        --pattern '^__(file|link|line)/etc/munin/' \
+        --execute 'service munin-node restart'
+
+
+AUTHORS
+-------
+Ander Punnar <ander-at-kvlt-dot-ee>
+
+
+COPYING
+-------
+Copyright \(C) 2019 Ander Punnar. You can redistribute it
+and/or modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation, either version 3 of the
+License, or (at your option) any later version.
diff --git a/cdist/conf/type/__check_messages/parameter/required b/cdist/conf/type/__check_messages/parameter/required
new file mode 100644
index 00000000..374363cb
--- /dev/null
+++ b/cdist/conf/type/__check_messages/parameter/required
@@ -0,0 +1,2 @@
+pattern
+execute

From decd80bf5de84398db266ea688a2f8c4cde1f31c Mon Sep 17 00:00:00 2001
From: Ander Punnar <ander@kvlt.ee>
Date: Thu, 4 Apr 2019 00:20:46 +0300
Subject: [PATCH 2/2] be more explicit

---
 cdist/conf/type/__check_messages/man.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cdist/conf/type/__check_messages/man.rst b/cdist/conf/type/__check_messages/man.rst
index cb505cea..5c80a0ae 100644
--- a/cdist/conf/type/__check_messages/man.rst
+++ b/cdist/conf/type/__check_messages/man.rst
@@ -23,7 +23,7 @@ For more information about dependencies and execution order see
 REQUIRED PARAMETERS
 -------------------
 pattern
-   Search pattern (passed to ``grep -E``).
+   Extended regular expression pattern for search (passed to ``grep -E``).
 
 execute
    Command to execute on pattern match.