Browse Source

Merge pull request #12 from bvberkum/pullrequests/ssh-nodes

ssh nodes, and misc.
Soulou 6 years ago
parent
commit
bf1b72fa54
4 changed files with 34 additions and 7 deletions
  1. 1 1
      Dockerfile
  2. 1 0
      README.md
  3. 0 2
      nginx.conf
  4. 32 4
      start-munin.sh

+ 1 - 1
Dockerfile

@@ -12,7 +12,7 @@ VOLUME /var/lib/munin
 VOLUME /var/log/munin
 
 ADD ./munin.conf /etc/munin/munin.conf
-AdD ./nginx.conf /etc/nginx/nginx.conf
+ADD ./nginx.conf /etc/nginx/nginx.conf
 ADD ./nginx-munin /etc/nginx/sites-enabled/munin
 ADD ./start-munin.sh /munin
 ADD ./munin-graph-logging.patch /usr/share/munin

+ 1 - 0
README.md

@@ -36,6 +36,7 @@ The port is always optional, default is 4949
 
 * `NODES` format: `name1:ip1[:port1] name2:ip2[:port2] …`
 * `SNMP_NODES` format: `name1:ip1[:port1]` …
+* `SSH_NODES` format: `name1:ip1[:port1]` …
 
 ## Port
 

+ 0 - 2
nginx.conf

@@ -26,5 +26,3 @@ http {
 	include /etc/nginx/conf.d/*.conf;
 	include /etc/nginx/sites-enabled/*;
 }
-
-

+ 32 - 4
start-munin.sh

@@ -1,6 +1,7 @@
 #!/bin/bash
 NODES=${NODES:-}
 SNMP_NODES=${SNMP_NODES:-}
+SSH_NODES=${SSH_NODES:-}
 MUNIN_USERS=${MUNIN_USERS:-${MUNIN_USER:-user}}
 MUNIN_PASSWORDS=${MUNIN_PASSWORDS:-${MUNIN_PASSWORD:-password}}
 MAIL_CONF_PATH='/var/lib/munin/.mailrc'
@@ -49,7 +50,7 @@ fi
 
 # generate the Munin auth username/password file
 if [ ! -f /etc/munin/htpasswd.users ]; then
-  uc = 0
+  uc=0
   IFS=' ' read -ra ARR_USERS <<< "$MUNIN_USERS"
   IFS=' ' read -ra ARR_PASSWORDS <<< "$MUNIN_PASSWORDS"
   for u in "${ARR_USERS[@]}"; do
@@ -67,7 +68,7 @@ do
   if [ ${#PORT} -eq 0 ]; then
       PORT=4949
   fi
-  if ! grep -q $HOST /etc/munin/munin.conf ; then
+  if ! grep -q "'^$HOST$'" /etc/munin/munin.conf ; then
     cat << EOF >> /etc/munin/munin.conf
 [$NAME]
     address $HOST
@@ -75,6 +76,7 @@ do
     port $PORT
 
 EOF
+    echo "Added node '$NAME' '$HOST'"
     fi
 done
 
@@ -87,7 +89,7 @@ do
   if [ ${#PORT} -eq 0 ]; then
       PORT=4949
   fi
-  if ! grep -q $HOST /etc/munin/munin.conf ; then
+  if ! grep -q "'^$HOST$'" /etc/munin/munin.conf ; then
     cat << EOF >> /etc/munin/munin.conf
 [$NAME]
     address $HOST
@@ -95,6 +97,27 @@ do
     port $PORT
 
 EOF
+    echo "Added SNMP node '$NAME' '$HOST'"
+    fi
+done
+
+for SSH_NODE in $SSH_NODES
+do
+  NAME=`echo $SSH_NODE | cut -d ":" -f1`
+  HOST=`echo $SSH_NODE | cut -d ":" -f2`
+  PORT=`echo $SSH_NODE | cut -d ":" -f3`
+  if [ ${#PORT} -eq 0 ]; then
+      PORT=4949
+  fi
+  if ! grep -q "'^$HOST$'" /etc/munin/munin.conf ; then
+    cat << EOF >> /etc/munin/munin.conf
+[$NAME]
+    address ssh://$HOST/usr/bin/nc localhost 4949
+    use_node_name yes
+    port $PORT
+
+EOF
+    echo "Added SSH node '$NAME' '$HOST'"
     fi
 done
 
@@ -119,16 +142,21 @@ fi
 /usr/sbin/rsyslogd
 # start cron
 /usr/sbin/cron
+# Issue: 'NUMBER OF HARD LINKS > 1' prevents cron exec in container
+# https://github.com/phusion/baseimage-docker/issues/198
+touch /etc/crontab /etc/cron.d/*
 # start local munin-node
 /usr/sbin/munin-node
 echo "Using the following munin nodes:"
 echo $NODES
+echo "(ssh) $SSH_NODES"
+echo "(snmp) $SNMP_NODES"
 # start spawn-cgi to enable CGI interface with munin (dynamix graph generation)
 spawn-fcgi -s /var/run/munin/fcgi-graph.sock -U munin -u munin -g munin /usr/lib/munin/cgi/munin-cgi-graph
 # start nginx
 /usr/sbin/nginx
 # show logs
-echo "Tailing /var/log/syslog..."
+echo "Tailing syslog and munin-update log..."
 tail -F /var/log/syslog /var/log/munin/munin-update.log & pid=$!
 echo "tail -F running in $pid"