aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlas Oliva <blasoliva@gmail.com>2015-02-22 14:15:09 -0300
committerBlas Oliva <blasoliva@gmail.com>2015-02-22 14:15:09 -0300
commit65c1c0f22536aed507fb1630ceef54bfa82b4849 (patch)
tree569159cc43811a420080aada9f59980c6121f93f
parentd81c2cb36a72c5df61f7ce63ced3996760ad28b5 (diff)
downloadreebot-65c1c0f22536aed507fb1630ceef54bfa82b4849.tar.gz
reebot-65c1c0f22536aed507fb1630ceef54bfa82b4849.zip
Updating reefuncs
-rw-r--r--config.py21
-rw-r--r--reefuncs.py48
2 files changed, 51 insertions, 18 deletions
diff --git a/config.py b/config.py
index 3f3ba82..22fd37f 100644
--- a/config.py
+++ b/config.py
@@ -1,8 +1,9 @@
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 = "r33bot"
5channels_list = [ "#reevo" ] 6channels_list = [ "#reevo-dev" ]
6irc_server = "irc.freenode.org" 7irc_server = "irc.freenode.org"
7irc_port = 6667 8irc_port = 6667
8 9
@@ -12,5 +13,19 @@ 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',
17}
18
19# Reevo servers
20hosts = {
21 'ergaster' : {
22 'IP' : '88.80.186.30',
23 'Descripción' : 'Servidor de pruebas',
24 'Dominio' : 'peervox.org',
25 'Localización' : 'London, England, UK', },
26 'raddad' : {
27 'IP' : '37.187.37.53',
28 'Descripción' : 'Servidor de produccion',
29 'Dominio' : 'reevo.org',
30 'Localización' : 'Strasbourg, Francia', }
16} 31}
diff --git a/reefuncs.py b/reefuncs.py
index 64bd036..0c02532 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
21 send message
22 """ 22 """
23 def __init__(self): 23 def __init__(self):
24 pass 24 pass
@@ -29,14 +29,15 @@ 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 parser.add_argument('-i', '--info', type=self.info, help='print host information', action='store', dest='hostname', nargs='+')
34 35
35 # Parsing arguments 36 # Parsing arguments
36 args = parser.parse_args(arguments.split()) 37 args = parser.parse_args(arguments.split())
37 38
38 # Put responses in a list (the library may already do this...) 39 # Put responses in a list (the library may already do this...)
39 responses = [args.task, args.server, args.message] 40 responses = [args.task, args.host, args.hostname, args.message]
40 41
41 # Return responses 42 # Return responses
42 for r in responses: 43 for r in responses:
@@ -44,12 +45,29 @@ class reefuncs:
44 return ' ' . join(r) 45 return ' ' . join(r)
45 46
46 def task(self, task): 47 def task(self, task):
47 return "Print the task number %s" % task 48 # return "Print the task number %s" % task
49 pass
48 50
49 def ping(self, host): 51 def ping(self, host):
50 ping = ['ping','-v', '-c 3', host] 52 """ Send ping to host """
51 process = subprocess.Popen(ping, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 53 msg = []
52 out, err = process.communicate() 54 if host in hosts.keys():
53 return out 55 cmd = ['ping', '-c 1', hosts[host]['IP']]
56 ping = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
57 out, err = ping.communicate()
58 rc = ping.returncode
59 msg.append('Host %s (%s) is %s\n' % \
60 (host, hosts[host]['IP'], 'up' if rc == 0 else 'down'))
61 return '\n'.join(msg)
62
63 def info(self, host):
64 """ Print hosts info """
65 i = []
66 for hostname, data in hosts.iteritems():
67 if host == hostname:
68 i.append('Nombre del servidor: %c%s%c' % (2, hostname, 2))
69 for key, value in data.iteritems():
70 i.append('%s: %s' % (key, value))
71 return '\n' . join(i)
54 72
55 73