~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to build/lib/gplugs/probe.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Malcolm
  • Date: 2012-04-03 21:58:28 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120403215828-6mik0tzug5na93la
Tags: 0.99.1-2
* Removes logfiles on purge (Closes: #668767)
* Reverted location of installed files back to /usr/lib/gozerbot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# plugs/probe.py
 
2
#
 
3
#
 
4
 
 
5
""" check if host:port is open """
 
6
 
 
7
__copyright__ = 'this file is in the public domain'
 
8
 
 
9
from gozerbot.commands import cmnds
 
10
from gozerbot.plughelp import plughelp
 
11
from gozerbot.examples import examples
 
12
from gozerbot.tests import tests
 
13
 
 
14
import socket
 
15
 
 
16
plughelp.add('probe', 'show if host:port is open')
 
17
 
 
18
def handle_probe(bot, ievent):
 
19
    """ probe <host> <port> .. check if host:port is open """
 
20
    try:
 
21
        (host, port) = ievent.args
 
22
        port = int(port)
 
23
    except ValueError:
 
24
        ievent.missing('<host> <port>')
 
25
        return
 
26
    try:
 
27
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
28
        sock.settimeout(2)
 
29
        sock.connect((host, port))
 
30
        sock.close()
 
31
    except socket.timeout:
 
32
        ievent.reply('%s:%s is not up' % (host, port))
 
33
        return
 
34
    except Exception, ex:
 
35
        ievent.reply('%s:%s is not up ==>  %s' % (host, port, str(ex)))
 
36
        return
 
37
    ievent.reply('%s:%s is up' % (host, port))
 
38
 
 
39
cmnds.add('probe', handle_probe, ['OPER', 'PROBE'])
 
40
examples.add('probe', 'probe <host> <port> // show if host:port is open', \
 
41
'probe gozerbot.org 8088')
 
42
tests.add('probe gozerbot.org 10101')