aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlas Oliva <blas@gcoop.coop>2015-05-10 22:01:15 -0300
committerBlas Oliva <blas@gcoop.coop>2015-05-10 22:01:15 -0300
commit98181131c80415413ea825576c8ebaa3c38a12dc (patch)
tree4653de479e33079abcfc94645d82bd26f906450f
parentd81c2cb36a72c5df61f7ce63ced3996760ad28b5 (diff)
downloadreebot-98181131c80415413ea825576c8ebaa3c38a12dc.tar.gz
reebot-98181131c80415413ea825576c8ebaa3c38a12dc.zip
reebot matate
-rw-r--r--config.py3
-rw-r--r--[-rwxr-xr-x]reebot.py3
-rw-r--r--reefuncs.py49
3 files changed, 34 insertions, 21 deletions
diff --git a/config.py b/config.py
index 3f3ba82..42ad3c3 100644
--- a/config.py
+++ b/config.py
@@ -1,4 +1,5 @@
1#!/usr/bin/python 1#!/usr/bin/python
2# -*- coding: utf-8 -*-
2 3
3# IRC server params 4# IRC server params
4nickname = "reebot" 5nickname = "reebot"
@@ -12,5 +13,5 @@ db_params = {
12 'database' : 'reevo', 13 'database' : 'reevo',
13 'feed_list' : 'feed_list', 14 'feed_list' : 'feed_list',
14 'log' : 'log', 15 'log' : 'log',
15 'users' : 'users' 16 'users' : 'users',
16} 17}
diff --git a/reebot.py b/reebot.py
index 58bd6d9..8b3d451 100755..100644
--- a/reebot.py
+++ b/reebot.py
@@ -148,8 +148,7 @@ class rBot:
148 msgq = msgqueue.pop() 148 msgq = msgqueue.pop()
149 for channel in channels_list: 149 for channel in channels_list:
150 self.sendmessage( channel, msgq ) 150 self.sendmessage( channel, msgq )
151 151 time.sleep(1)
152 time.sleep(2)
153 # Refresh interval (every X seconds) 152 # Refresh interval (every X seconds)
154 threading.Timer( 10, self.feed_refresh ).start() 153 threading.Timer( 10, self.feed_refresh ).start()
155 154
diff --git a/reefuncs.py b/reefuncs.py
index 64bd036..f532a06 100644
--- a/reefuncs.py
+++ b/reefuncs.py
@@ -3,22 +3,22 @@
3 3
4import argparse 4import argparse
5import subprocess 5import subprocess
6from config import hosts
6 7
7class reefuncs: 8class reefuncs:
8 """ Parse arguments and execute functions 9 """ Parse arguments and execute functions
9 10
10 usage: reebot [-h] [-t TASK [TASK ...]] [-p SERVER [SERVER ...]] [-m MESSAGE [MESSAGE ...]] 11 usage: reebot [-h] [-t TASK] [-p SERVER] [-m MESSAGE] [-i HOSTNAME]
11 12
12 Reebot functions 13 Reebot functions
13 14
14 optional arguments: 15 optional arguments:
15 -h, --help show this help message and exit 16 -h, --help : show this help message and exit
16 -t TASK [TASK ...], --task TASK [TASK ...] 17 -t TASK [TASK ...], --task TASK [TASK ...] : show task status
17 show task status 18 -p SERVER [SERVER ...], --ping SERVER [SERVER ...] : send ping to server
18 -p SERVER [SERVER ...], --ping SERVER [SERVER ...] 19 -m MESSAGE [MESSAGE ...], --msg MESSAGE [MESSAGE ...] : send message
19 send ping to server 20 -i HOSTNAME [HOSTNAME ...], --info HOSTNAME [HOSTNAME ...] : show host info
20 -m MESSAGE [MESSAGE ...], --msg MESSAGE [MESSAGE ...] 21 -k, --matate : restart reebot
21 send message
22 """ 22 """
23 def __init__(self): 23 def __init__(self):
24 pass 24 pass
@@ -29,14 +29,16 @@ class reefuncs:
29 29
30 # Adding arguments 30 # Adding arguments
31 parser.add_argument('-t', '--task', type=self.task, help='show task status', action='store', dest='task', nargs='+') 31 parser.add_argument('-t', '--task', type=self.task, help='show task status', action='store', dest='task', nargs='+')
32 parser.add_argument('-p', '--ping', type=self.ping, help='send ping to server', action='store', dest='server', nargs='+') 32 parser.add_argument('-p', '--ping', type=self.ping, help='send ping to server', action='store', dest='host', nargs='+')
33 parser.add_argument('-m', '--msg', help='send message', action='store', dest='message', nargs='+') 33 parser.add_argument('-m', '--msg', help='send message', action='store', dest='message', nargs='+')
34 34 parser.add_argument('-i', '--info', type=self.info, help='print host information', action='store', dest='hostname', nargs='+')
35 parser.add_argument('-k', '--matate', type=self.matate, help='killing myself', action='store', dest='matate')
36
35 # Parsing arguments 37 # Parsing arguments
36 args = parser.parse_args(arguments.split()) 38 args = parser.parse_args(arguments.split())
37 39
38 # Put responses in a list (the library may already do this...) 40 # Put responses in a list (the library may already do this...)
39 responses = [args.task, args.server, args.message] 41 responses = [args.task, args.host, args.hostname, args.message]
40 42
41 # Return responses 43 # Return responses
42 for r in responses: 44 for r in responses:
@@ -44,12 +46,23 @@ class reefuncs:
44 return ' ' . join(r) 46 return ' ' . join(r)
45 47
46 def task(self, task): 48 def task(self, task):
47 return "Print the task number %s" % task 49 # return "Print the task number %s" % task
50 pass
48 51
52 def matate(self):
53 cmd = ['/etc/init.d/reebot', 'restart']
54 killreebot = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
55 out, err = killreebot.communicate()
56 rc = killreebot.returncode
57 return rc
58
49 def ping(self, host): 59 def ping(self, host):
50 ping = ['ping','-v', '-c 3', host] 60 """ Send ping to host """
51 process = subprocess.Popen(ping, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 61 msg = []
52 out, err = process.communicate() 62 cmd = ['ping', '-c 1', host]
53 return out 63 ping = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
54 64 out, err = ping.communicate()
55 65 rc = ping.returncode
66 msg.append('Host %s is %s\n' % \
67 (host, 'up' if rc == 0 else 'down'))
68 return '\n'.join(msg)