From bf02dca4b0f09d86990a50a4406ab8ecd79cbd5d Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Fri, 12 Jun 2009 19:17:01 +0000 Subject: [PATCH] convenience, maintenance scripts --- statistics/copy-logs.sh | 16 ++++++++++++++++ zabbix/hosts.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 statistics/copy-logs.sh create mode 100755 zabbix/hosts.py diff --git a/statistics/copy-logs.sh b/statistics/copy-logs.sh new file mode 100755 index 0000000..634d873 --- /dev/null +++ b/statistics/copy-logs.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cd /usr/share/monitor +source agent.sh &> /dev/null + +rsync -qv -az -e ssh root@chloe.cs.princeton.edu:/vservers/www-current/var/log/httpd/*-* /var/lib/monitor/httpd-log +rsync -qv -az -e ssh root@chloe.cs.princeton.edu:/vservers/www-current/var/log/httpd/*error* /var/lib/monitor/httpd-log + +rsync -qv -az -e ssh root@chloe.cs.princeton.edu:/vservers/www-current/var/log/*-filesystem* /var/lib/monitor/filesystem +rsync -qv -az -e ssh root@chloe.cs.princeton.edu:/vservers/www-current/var/log/*-checkrpm* /var/lib/monitor/checkrpm + +rsync -qv -az -e ssh root@amber.cs.princeton.edu:/vservers/db-current/var/log/*-filesystem* /var/lib/monitor/filesystem +rsync -qv -az -e ssh root@amber.cs.princeton.edu:/vservers/db-current/var/log/*-checkrpm* /var/lib/monitor/checkrpm + +rsync -qv -az -e ssh root@janine.cs.princeton.edu:/vservers/boot-current/var/log/*-filesystem* /var/lib/monitor/filesystem +rsync -qv -az -e ssh root@janine.cs.princeton.edu:/vservers/boot-current/var/log/*-checkrpm* /var/lib/monitor/checkrpm diff --git a/zabbix/hosts.py b/zabbix/hosts.py new file mode 100755 index 0000000..c2dbde7 --- /dev/null +++ b/zabbix/hosts.py @@ -0,0 +1,32 @@ +#!/usr/bin/python + +from monitor.wrapper import plc +import os + +api = plc.api + +HOSTS_FILE="/etc/hosts" + +def is_in_file(filename, pattern): + f = os.popen("grep %s %s" % ( pattern, filename)) + content = f.read() + if len(content) > 0: + return True + else: + return False +def add_to_file(filename, data): + os.system("echo '%s' >> %s" % (data, filename)) + print "echo '%s' >> %s" % (data, filename) + +sites = api.GetSites({'login_base' : 'mlab*'}, ['node_ids']) +for s in sites: + nodes = api.GetNodes(s['node_ids'], ['hostname', 'interface_ids']) + for node in nodes: + try: + i = api.GetInterfaces({ 'interface_id' : node['interface_ids'], 'is_primary' : True}) + print len(i), i + print "%s %s" % (i[0]['ip'], node['hostname']) + #if not is_in_file(HOSTS_FILE, node['hostname']): + # add_to_file(HOSTS_FILE, "%s %s" % (i[0]['ip'], node['hostname'])) + except: + pass -- 2.43.0