[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r19567: {arm} Few small tweaks to arm including: - added tiny shell script (arm/trunk)
Author: atagar
Date: 2009-05-26 01:36:59 -0400 (Tue, 26 May 2009)
New Revision: 19567
Added:
arm/trunk/arm
Modified:
arm/trunk/arm.py
arm/trunk/armInterface.py
arm/trunk/readme.txt
Log:
Few small tweaks to arm including:
- added tiny shell script to alias starting
- added more informative error message if TorCtl isn't available
- changed defaultly logged events
- make inclusion of 'unknown' events toggleable
Added: arm/trunk/arm
===================================================================
--- arm/trunk/arm (rev 0)
+++ arm/trunk/arm 2009-05-26 05:36:59 UTC (rev 19567)
@@ -0,0 +1,3 @@
+#!/bin/sh
+python arm.py $*
+
Property changes on: arm/trunk/arm
___________________________________________________________________
Added: svn:executable
+ *
Modified: arm/trunk/arm.py
===================================================================
--- arm/trunk/arm.py 2009-05-26 05:35:41 UTC (rev 19566)
+++ arm/trunk/arm.py 2009-05-26 05:36:59 UTC (rev 19567)
@@ -13,13 +13,19 @@
import socket
import getpass
import binascii
+
+try:
+ from TorCtl import TorCtl
+except ImportError:
+ print "Unable to load TorCtl (see readme for instructions)"
+ sys.exit()
+
import armInterface
-from TorCtl import TorCtl
DEFAULT_CONTROL_ADDR = "127.0.0.1"
DEFAULT_CONTROL_PORT = 9051
DEFAULT_AUTH_COOKIE = os.path.expanduser("~/.tor/control_auth_cookie") # TODO: Check if this is valid for macs
-DEFAULT_LOGGED_EVENTS = "wefz" # WARN, ERR, DESCCHANGED, STATUS_SERVER
+DEFAULT_LOGGED_EVENTS = "nwe" # NOTICE, WARN, ERR
NO_AUTH, COOKIE_AUTH, PASSWORD_AUTH = range(3) # enums for authentication type
EVENT_TYPES = {
@@ -29,7 +35,7 @@
"w": "WARN", "f": "DESCCHANGED", "s": "STREAM", "y": "STATUS_CLIENT",
"e": "ERR", "g": "GUARD", "t": "STREAM_BW", "z": "STATUS_SERVER"}
-HELP_TEXT = """Usage arm.py [OPTION]
+HELP_TEXT = """Usage arm [OPTION]
Terminal Tor relay status monitor.
-i, --interface [ADDRESS:]PORT change control interface from %s:%i
@@ -38,18 +44,18 @@
-p, --password[=PASSWORD] authenticates using password, prompting
without terminal echo if not provided
-e, --event=[EVENT FLAGS] event types in message log (default: %s)
- d DEBUG a ADDRMAP l NEWDESC u AUTHDIR_NEWDESCS
- i INFO b BW m NS v CLIENTS_SEEN
- n NOTICE c CIRC o ORCONN x STATUS_GENERAL
- w WARN f DESCCHANGED s STREAM y STATUS_CLIENT
- e ERR g GUARD t STREAM_BW z STATUS_SERVER
- Aliases: A All Events N No Events R Runlevels (dinwe)
+ d DEBUG a ADDRMAP l NEWDESC u AUTHDIR_NEWDESCS
+ i INFO b BW m NS v CLIENTS_SEEN
+ n NOTICE c CIRC o ORCONN x STATUS_GENERAL
+ w WARN f DESCCHANGED s STREAM y STATUS_CLIENT
+ e ERR g GUARD t STREAM_BW z STATUS_SERVER
+ Aliases: A All Events U Unknown Events R Runlevels (dinwe)
-h, --help presents this help
Example:
-arm.py -c authenticate using the default cookie
-arm.py -i 1643 -p prompt for password using control port 1643
-arm.py -e=we -p=nemesis use password 'nemesis' with 'WARN'/'ERR' events
+arm -c authenticate using the default cookie
+arm -i 1643 -p prompt for password using control port 1643
+arm -e=we -p=nemesis use password 'nemesis' with 'WARN'/'ERR' events
""" % (DEFAULT_CONTROL_ADDR, DEFAULT_CONTROL_PORT, DEFAULT_AUTH_COOKIE, DEFAULT_LOGGED_EVENTS)
class Input:
@@ -182,9 +188,8 @@
if flag == "A":
expandedEvents = set(EVENT_TYPES.values())
break
- elif flag == "N":
- expandedEvents = set()
- break
+ elif flag == "U":
+ expandedEvents.add("UNKNOWN")
elif flag == "R":
expandedEvents = expandedEvents.union(set(["DEBUG", "INFO", "NOTICE", "WARN", "ERR"]))
elif flag in EVENT_TYPES:
Modified: arm/trunk/armInterface.py
===================================================================
--- arm/trunk/armInterface.py 2009-05-26 05:35:41 UTC (rev 19566)
+++ arm/trunk/armInterface.py 2009-05-26 05:36:59 UTC (rev 19567)
@@ -47,7 +47,7 @@
subwindow.
"""
- def __init__(self, logScreen, includeBW):
+ def __init__(self, logScreen, includeBW, includeUnknown):
TorCtl.PostEventListener.__init__(self)
self.msgLog = [] # tuples of (isMsgFirstLine, logText, color)
self.logScreen = logScreen # curses window where log's displayed
@@ -55,6 +55,7 @@
self.pauseBuffer = [] # location where messages are buffered if paused
self.msgLogLock = Lock() # haven't noticed any concurrency errors but better safe...
self.includeBW = includeBW # true if we're supposed to listen for BW events
+ self.includeUnknown = includeUnknown # true if registering unrecognized events
# Listens for all event types and redirects to registerEvent
# TODO: not sure how to stimulate all event types - should be tried before
@@ -92,7 +93,7 @@
self.registerEvent("NEWCONSENSUS", "<STUB>", "white") # TODO: implement - variables: event.nslist
def unknown_event(self, event):
- self.registerEvent("UNKNOWN", event.event_string, "red")
+ if self.includeUnknown: self.registerEvent("UNKNOWN", event.event_string, "red")
def registerEvent(self, type, msg, color):
"""
@@ -391,6 +392,15 @@
screen.refresh()
def drawTorMonitor(stdscr, conn, loggedEvents):
+ """
+ Starts arm interface reflecting information on provided control port.
+
+ stdscr - curses window
+ conn - active Tor control port connection
+ loggedEvents - types of events to be logged (plus an optional "UNKNOWN" for
+ otherwise unrecognized events)
+ """
+
global COLOR_ATTR_INITIALIZED
# use terminal defaults to allow things like semi-transparent backgrounds
@@ -425,7 +435,7 @@
logScreen = stdscr.subwin(y - 17, x, 17, 0) # uses all remaining space for message log
# listeners that update bandwidthScreen and logScreen with Tor statuses
- logListener = LogMonitor(logScreen, "BW" in loggedEvents)
+ logListener = LogMonitor(logScreen, "BW" in loggedEvents, "UNKNOWN" in loggedEvents)
conn.add_event_listener(logListener)
bandwidthListener = BandwidthMonitor(bandwidthScreen)
@@ -438,7 +448,10 @@
while not eventsSet:
try:
# adds BW events if not already included (so bandwidth monitor will work)
- conn.set_events(loggedEvents.union(set(["BW"])))
+ # removes UNKNOWN since not an actual event type
+ connEvents = loggedEvents.union(set(["BW"]))
+ connEvents.discard("UNKNOWN")
+ conn.set_events(connEvents)
eventsSet = True
except TorCtl.ErrorReply, exc:
msg = str(exc)
@@ -454,6 +467,8 @@
logListener.registerEvent("ARM-ERR", "Unsupported event type: %s" % eventType, "red")
else:
raise exc
+ loggedEvents = list(loggedEvents)
+ loggedEvents.sort() # alphabetizes
eventsListing = ", ".join(loggedEvents)
bandwidthScreen.refresh()
Modified: arm/trunk/readme.txt
===================================================================
--- arm/trunk/readme.txt 2009-05-26 05:35:41 UTC (rev 19566)
+++ arm/trunk/readme.txt 2009-05-26 05:36:59 UTC (rev 19567)
@@ -1,4 +1,4 @@
-ARM (ARM Relay Monitor) - Terminal status monitor for Tor relays.
+arm (arm relay monitor) - Terminal status monitor for Tor relays.
Developed by Damian Johnson (www.atagar.com - atagar1@xxxxxxxxx)
All code under the GPL v3 (http://www.gnu.org/licenses/gpl.html)