summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-04-16 10:30:15 +0200
committerSuren A. Chilingaryan <csa@suren.me>2018-04-16 10:30:15 +0200
commit55783753ae8f2d857a7225b7a93c1d47039e5a90 (patch)
treee077b61b0f004141712e7d16876f9c19175ac681 /scripts
downloadconky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.gz
conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.bz2
conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.tar.xz
conky-55783753ae8f2d857a7225b7a93c1d47039e5a90.zip
OpenShift monitoring
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/conky-atom.sh55
-rwxr-xr-xscripts/conky-rss.sh48
-rwxr-xr-xscripts/conky_process_requests.pl77
-rwxr-xr-xscripts/emerge-current.sh33
-rwxr-xr-xscripts/emerge-progress.sh20
-rwxr-xr-xscripts/emerge-status.sh39
-rwxr-xr-xscripts/lastsync.pl7
-rwxr-xr-xscripts/netstat-in.sh9
-rwxr-xr-xscripts/ping.pl19
-rwxr-xr-xscripts/run_conky.sh24
10 files changed, 331 insertions, 0 deletions
diff --git a/scripts/conky-atom.sh b/scripts/conky-atom.sh
new file mode 100755
index 0000000..2cd0192
--- /dev/null
+++ b/scripts/conky-atom.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+# RSS Display Script by Bill Woodford (admin@sdesign.us) v1.0
+#
+# This script is designed to output story titles for most any RSS Feed.
+#
+# This script depends on curl. Please ensure it is installed and in your $PATH
+# Gentoo: emerge -av net-misc/curl
+# Debian: apt-get install curl
+# Homepage: http://curl.haxx.se/
+#
+# Usage:
+# .conkyrc: ${execi [time] /path/to/script/conky-rss.sh URI LINES TITLENUM}
+# URI = Location of feed, ex. http://www.gentoo.org/rdf/en/glsa-index.rdf
+# LINES = How many titles to display (default 5)
+# TITLENUM = How many times the title of the feed itself is specified, usually 1 or 2 (default 2)
+#
+# Usage Example
+# ${execi 300 /home/youruser/scripts/conky-rss.sh http://www.foxnews.com/xmlfeed/rss/0,4313,1,00.rss 4 2}
+
+#RSS Setup - Don't change unless you want these values hard-coded!
+uri=$1 #URI of RSS Feed
+lines=$2 #Number of headlines
+titlenum=$3 #Number of extra titles
+if [ -n $4 ]; then
+ width=$4
+else
+ width=1024
+fi
+
+#Script start
+#Require a uri, as a minimum
+if [[ "$uri" == "" ]]; then
+ echo "No URI specified, cannot continue!" >&2
+ echo "Please read script for more information" >&2
+else
+ #Set defaults if none specified
+ if [[ $lines == "" ]]; then lines=5 ; fi
+ if [[ $titlenum == "" ]]; then titlenum=2 ; fi
+
+ #The actual work
+ atom=`curl -s --connect-timeout 30 $uri`
+ echo $atom |\
+ sed -e 's/<\/title>/<\/title>\n/g' |\
+ grep '<title' |\
+ sed -e 's/^.*<title/<title/' |\
+ sed -e 's#<\(/\?\)title>#<\1p>#g' |\
+ html2text -utf8 -width 65536 |\
+ cut -d '/' -f 2- | sed -e 's/-[[:digit:].r\-]\+:/:/' |\
+ tail -n +2 |\
+ head -n $(($lines + $titlenum)) |\
+ tail -n $(($lines)) |\
+ cut -c 1-`echo $((3 * $width))` |\
+ fmt -t -w $width
+
+fi
diff --git a/scripts/conky-rss.sh b/scripts/conky-rss.sh
new file mode 100755
index 0000000..92375b5
--- /dev/null
+++ b/scripts/conky-rss.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+# RSS Display Script by Bill Woodford (admin@sdesign.us) v1.0
+#
+# This script is designed to output story titles for most any RSS Feed.
+#
+# This script depends on curl. Please ensure it is installed and in your $PATH
+# Gentoo: emerge -av net-misc/curl
+# Debian: apt-get install curl
+# Homepage: http://curl.haxx.se/
+#
+# Usage:
+# .conkyrc: ${execi [time] /path/to/script/conky-rss.sh URI LINES TITLENUM}
+# URI = Location of feed, ex. http://www.gentoo.org/rdf/en/glsa-index.rdf
+# LINES = How many titles to display (default 5)
+# TITLENUM = How many times the title of the feed itself is specified, usually 1 or 2 (default 2)
+#
+# Usage Example
+# ${execi 300 /home/youruser/scripts/conky-rss.sh http://www.foxnews.com/xmlfeed/rss/0,4313,1,00.rss 4 2}
+
+#RSS Setup - Don't change unless you want these values hard-coded!
+uri=$1 #URI of RSS Feed
+lines=$2 #Number of headlines
+titlenum=$3 #Number of extra titles
+if [ -n $4 ]; then
+ width=$4
+else
+ width=1024
+fi
+
+#Script start
+#Require a uri, as a minimum
+if [[ "$uri" == "" ]]; then
+ echo "No URI specified, cannot continue!" >&2
+ echo "Please read script for more information" >&2
+else
+ #Set defaults if none specified
+ if [[ $lines == "" ]]; then lines=5 ; fi
+ if [[ $titlenum == "" ]]; then titlenum=2 ; fi
+
+ #The actual work
+ curl -s --connect-timeout 30 $uri |\
+ sed -e 's/<\/title>/\n/g' |\
+ grep -o '<title>.*' |\
+ sed -e 's/<title>//' |\
+ head -n $(($lines + $titlenum)) |\
+ tail -n $(($lines)) | \
+ fmt -t -w $width
+fi
diff --git a/scripts/conky_process_requests.pl b/scripts/conky_process_requests.pl
new file mode 100755
index 0000000..4e66d7a
--- /dev/null
+++ b/scripts/conky_process_requests.pl
@@ -0,0 +1,77 @@
+#! /usr/bin/perl
+
+use Digest::MD5 qw(md5_hex);
+
+$dir = $ENV{'HOME'} . "/.conky/info/";
+
+sub process_server_request {
+ my $server = shift(@_);
+ my $fn = shift(@_);
+
+ open fl, $fn;
+ @commands = <fl>;
+ close fl;
+
+ $n_cmd = 0;
+ foreach $cmd(@commands) {
+ if ($cmd !~ /^[\/\w\d_]/) {next;}
+ $n_cmd = $n_cmd + 1;
+ }
+
+ if ($n_cmd > 1) {
+ $ping = $commands[0];
+ chomp($ping);
+
+ $md5 = md5_hex($ping);
+ $res = `$ping`;
+
+ open(fl, ">$dir/$server-$md5.srv");
+ print fl $res;
+ close(fl);
+
+ delete($commands[0]);
+ } else {
+ $res = 1
+ }
+
+ if ($res > 0) {
+ foreach $cmd(@commands) {
+ if ($cmd !~ /^[\/\w\d_]/) {next;}
+ chomp($cmd);
+ $md5 = md5_hex($cmd);
+ open(fl, ">$dir/$server-$md5.srv");
+ open(cmd, "$cmd |");
+ while (<cmd>) { print fl; }
+ close(cmd);
+ close(fl);
+ }
+ }
+}
+
+sub process_item {
+ my $item = shift(@_);
+
+ $fn = $ENV{'HOME'} . "/.conky/requests/" . $item;
+ if (! -f $fn) { return; }
+
+ if ($item =~ /^(.*)\.srv$/) {
+ $server = $1;
+
+ process_server_request($server, $fn);
+
+ unlink($fn);
+ }
+}
+
+opendir dir, $ENV{'HOME'} . "/.conky/requests/";
+@dirlist = readdir dir;
+closedir dir;
+
+if ($#ARGV >= 0) {
+ $item = shift(@ARGV);
+ process_item($item);
+} else {
+ foreach $item(@dirlist) {
+ process_item($item);
+ }
+}
diff --git a/scripts/emerge-current.sh b/scripts/emerge-current.sh
new file mode 100755
index 0000000..53e7a19
--- /dev/null
+++ b/scripts/emerge-current.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+# emerge-current.sh by Hellf[i]re
+#
+# This script is designed to read the name of the last package compiled.
+#
+# As this script does read the entirety of emerge.log, it will be rather
+# heavy on the CPU. It shouldn't be enough to be noticable on newer (2.0Ghz+)
+# processors, but it still should not be run more often than every 30 seconds.
+#
+# Usage:
+# .conkyrc: ${execi [time] /path/to/script/emerge-current.sh}
+#
+# Usage Example
+# ${execi 30 /home/youruser/scripts/emerge-current.sh}
+
+if [ -n "$1" ]; then
+ num=$1
+else
+ num=1
+fi
+
+tac /var/log/emerge.log |\
+grep 'Compiling' |\
+head -n $num |\
+sed -e 's/.*(//' |\
+sed -e 's/::.*)//' |\
+sed -e '2,$ { s|^[^/]\+/|| }' |\
+sed -e '2,$ { s|-[0-9.]\+\(-r[0-9]\+\)\?$|| }' |\
+head -n $num | sed -e "2 { s/^/ / }" -e "2,$ { :a ; N ; s/\n/, /; ta }" |\
+cut -d \) -f 1
+
+
+
diff --git a/scripts/emerge-progress.sh b/scripts/emerge-progress.sh
new file mode 100755
index 0000000..1f28f73
--- /dev/null
+++ b/scripts/emerge-progress.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+# source: Jeremy_Z @ forums.gentoo.org http://forums.gentoo.org/viewtopic-t-351806-postdays-0-postorder-asc-start-550.html
+#
+# This script will report the progress of the last emerge command run. It
+# reports the TOTAL percentage complete - not the percentage of the current
+# package. For example, if there are 110 packages currently being emerged, and
+# it is on the 55th package, it will report 50.
+#
+# Usage:
+# .conkyrc: ${execibar [time] /path/to/script/emerge-progress.sh}
+#
+# Usage Example
+# ${execibar 30 /home/youruser/scripts/emerge-progress.sh}
+
+tail -n 50 /var/log/emerge.log |\
+tac |\
+grep -v "Starting retry" |\
+grep -iE '([0-9]* of [0-9]*)' -o -m 1 |\
+sed -e 's/\(.*\) of \(.*\)/\1 \2/' |\
+awk '{print 100.0*$1/$2}'
diff --git a/scripts/emerge-status.sh b/scripts/emerge-status.sh
new file mode 100755
index 0000000..a1241ef
--- /dev/null
+++ b/scripts/emerge-status.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+#
+# emerge-status.sh by Hellf[i]re
+#
+# This script will report the current status of portage.
+#
+# Usage:
+# .conkyrc: ${execi [time] /path/to/script/emerge-current.sh}
+#
+# Usage Example
+# ${execi 30 /home/youruser/scripts/emerge-current.sh}
+#
+# Known Bugs:
+# 1) If there are two emerges running at once, when the first one finishes
+# running, the script will report the current status as "Completed".
+# 2) If there is a emerge running and you run a search, the script will
+# report the current status as "Completed", until the running emerge
+# moves to the next package, or itself completes.
+# The reasons for this are twofold - one, it's a feature ;) and two, there
+# would be far too much parsing required to find out the current status of
+# every command which is run in parallel.
+
+STATUS=`tail -n 15 /var/log/emerge.log |\
+grep -iE "Compiling|Cleaning|AUTOCLEAN|completed|search|terminating|rsync" |\
+cut -d ' ' -f "2-" |\
+grep -Ev 'Finished\.|Cleaning up\.\.\.' |\
+tail -n 1`
+
+#echo "$STATUS"
+
+if [ "`echo "$STATUS" | grep -i compiling`" != "" ]; then echo Compiling
+elif [ "`echo "$STATUS" | grep -i cleaning`" != "" ]; then echo Cleaning
+elif [ "`echo "$STATUS" | grep -i autoclean`" != "" ]; then echo Autoclean
+elif [ "`echo "$STATUS" | grep -i sync`" != "" ]; then echo Syncing
+elif [ "`echo "$STATUS" | grep -i search`" != "" ]; then echo Searching
+elif [ "`echo "$STATUS" | grep -i completed`" != "" ]; then echo Completed
+elif [ "`echo "$STATUS" | grep -i terminating`" != "" ]; then echo Completed
+else echo Script Error!
+fi
diff --git a/scripts/lastsync.pl b/scripts/lastsync.pl
new file mode 100755
index 0000000..37bef03
--- /dev/null
+++ b/scripts/lastsync.pl
@@ -0,0 +1,7 @@
+#!/usr/bin/perl
+use Date::Manip;
+
+$date = `grep "Sync completed" /var/log/emerge.log | tail -n1 | cut -c-10`;
+$date = &DateCalc("Jan 1, 1970 00:00:00 GMT",$date);
+$date = UnixDate("$date","%A %H:%M");
+print "$date";
diff --git a/scripts/netstat-in.sh b/scripts/netstat-in.sh
new file mode 100755
index 0000000..993d97e
--- /dev/null
+++ b/scripts/netstat-in.sh
@@ -0,0 +1,9 @@
+#! /bin/bash
+
+query=""
+for port in `netstat -lntu | tail -n +3 | grep -v "127.0.0.1" | awk -e '{print $4}' | rev | cut -d ':' -f 1 | rev | sort -n | uniq`; do
+ [ $port -gt 32768 ] && continue;
+ [ -z "$query" ] && query="sport = :$port" || query="$query or sport = :$port"
+done
+
+eval /sbin/ss -nrtu state established "'( $query ) '" | tail -n +2 | grep -v localhost | awk -F'[:\t ]+' -e '$6 != $4 { print $6, $5 }'
diff --git a/scripts/ping.pl b/scripts/ping.pl
new file mode 100755
index 0000000..0f24483
--- /dev/null
+++ b/scripts/ping.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl -w
+use Net::Ping;
+use Switch;
+
+if (@ARGV >1) { $host=$ARGV[0]; $timeout=$ARGV[1]; }
+elsif (@ARGV>0) { $host=$ARGV[0]; $timeout=2; }
+else { print "Usage is: $0 host <timeout=1>\n"; exit; }
+
+if ($host =~ /^(.*):(\d+)$/) {
+ $host = $1;
+ $port = $2;
+} else {
+ $port = 22;
+}
+
+$p=Net::Ping->new('tcp');
+$p->port_number($port);
+if ($p->ping($host, $timeout)) {print 1;} else {print 0;}
+$p->close();
diff --git a/scripts/run_conky.sh b/scripts/run_conky.sh
new file mode 100755
index 0000000..abdea35
--- /dev/null
+++ b/scripts/run_conky.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+if [ "$1" != "start" ]; then
+ killall -9 conky
+ killall -9 rainlendar2
+ killall -9 rainlendar2.bin
+fi
+
+if [ "$1" != "stop" ]; then
+ python /opt/scripts/unlock.py gui || exit
+
+ killall -9 gpg-agent
+ pass test
+
+ conky -q -d -c /etc/conky/sysinfo.conf
+ conky -q -d -c /etc/conky/netstat.conf
+ conky -q -d -c /etc/conky/gentoo.conf
+ conky -q -d -c /etc/conky/logs.conf
+ conky -q -d -c /etc/conky/todo.conf
+ # todo should be loaded before forecast
+ sleep 0.3
+ conky -q -d -c /etc/conky/forecast.conf
+ /opt/rainlendar2/rainlendar2 --quiet &
+fi