Browse Source

Add ffho_base state (ff_log_to_bot) + git.c3pb.de pubkey.

Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>
Maximilian Wilhelm 7 years ago
parent
commit
a91b3fe67e
2 changed files with 87 additions and 0 deletions
  1. 60 0
      ffho_base/ff_log_to_bot
  2. 27 0
      ffho_base/init.sls

+ 60 - 0
ffho_base/ff_log_to_bot

@@ -0,0 +1,60 @@
+#!/bin/sh
+#
+# Log status message to IRC bot. Fall back to sending mail if bot is sick.
+#
+# Maximilian Wilhelm <max@rfc2324.org>
+#  -- Mon, 02 Jun 2014 10:02:40 +0200
+#
+
+set -e
+
+STATUS_BOT_ADDR="{{ salt['pillar.get']('ffho:status_bot:addr') }}"
+STATUS_BOT_PORT="{{ salt['pillar.get']('ffho:status_bot:port') }}"
+TECH_C_MAIL="{{ salt['pillar.get']('ffho:tech_c_mail') }}"
+
+temp_file="$(mktemp)"
+
+trap "rm -f -- \"${temp_file}\"" EXIT 1 2 15
+
+# Specific source address given?
+src_ip=""
+if [ "$1" = "-s" ]; then
+	shift
+
+	# Valid local IP address given?
+	if [ "$1" ] && ip route get "$1" | grep -q "dev lo" 2>/dev/null; then
+		src_ip="$1"
+		shift
+	fi
+fi
+
+if [ $# = 0 -o "$1" = "-" ]; then
+	cat > "${temp_file}"
+else
+	echo "$@" > "${temp_file}"
+fi
+
+# If there is no data, there's nothing we can do *sniff*
+if [ ! -s "${temp_file}" ]; then
+	exit 0
+fi
+
+nc_opts=""
+if echo ${STATUS_BOT_ADDR} | grep -q ":"; then
+	if echo ${src_ip} | grep -vq ":"; then
+		src_ip=$(ip a s dev lo 2>/dev/null | awk '/inet6/ { sub ("/128","",$2); print $2 }' | grep ":ffff:") || true
+	fi
+else
+	if echo ${src_ip} | grep -qv "^[0-9]\+\."; then
+		src_ip=$(ip a s dev lo 2>/dev/null | awk '/inet 10.132.255./ { sub ("/32","",$2); print $2 }') || true
+	fi
+fi
+
+
+if [ "${src_ip}" ]; then
+	nc_opts="-s ${src_ip}"
+fi
+
+if ! nc ${nc_opts} "${STATUS_BOT_ADDR}" "${STATUS_BOT_PORT}" < "${temp_file}"; then
+	mail -s "FF-log from {{ grains['id'] }}" ${TECH_C_MAIL} < "${temp_file}"
+fi

+ 27 - 0
ffho_base/init.sls

@@ -0,0 +1,27 @@
+#
+# Stuff for every f*cking FFHO machine
+#
+
+ffho_packages:
+  pkg.installed:
+    - pkgs:
+      - git
+      - openssl
+      - netcat-openbsd
+
+
+# SSH fingerprint of gitlab on git.c3pb.de
+git.c3pb.pubkey:
+  ssh_known_hosts:
+    - name: git.c3pb.de
+    - present
+    - user: root
+    - enc: ecdsa
+    - fingerprint: 60:97:30:24:0b:85:21:e4:c3:49:c2:f5:12:de:1c:da
+
+
+/usr/local/bin/ff_log_to_bot:
+  file.managed:
+    - source: salt://ffho_base/ff_log_to_bot
+    - template: jinja
+    - mode: 755