# ---------------------------------------------------------------------- # Copyright (c) 2009 CSC Ltd. (http://www.csc.fi) # (All rights reversed) # Based on "getPoolInfos.py" from DCACHE.ORG (R) # # This program is free software; you can redistribute it and/or # modify it under the terms of version 2 of the GNU General Public # License published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, contact Novell, Inc. # ---------------------------------------------------------------------- # from org.pcells.services.connection import * from dmg.protocols.ssh import * from dmg.cells.nucleus import NoRouteToCellException from java.lang import System from java.io import File from java.io import FileNotFoundException import sys,time,types connectionStartID=1 DEBUG=False class ourDomainEventListener( DomainEventListener) : def __init__(self,MyXrootDoor) : self.XrootDoor=MyXrootDoor return def connectionOpened( self , connection ) : connection.sendObject( self.XrootDoor.CellName , "info" , MyMessageListener , connectionStartID ) ; def connectionClosed( self , connection ) : print "Connection closed" def connectionOutOfBand( self , connection , subject ) : print "Connection out of band" class ourDomainConnectionListener( DomainConnectionListener ) : # # this class only has one object in the application which # is used whenever data arrives from the channel. # def __init__( self, MyXrootDoor ) : self.XrootDoor=MyXrootDoor self.currentID=connectionStartID self.currentXrootKid=0 return def getInfo(self,obj) : self.currentID += 1 for line in obj.split("\n") : if not ":" in line :continue tokens=line.split(":") self.XrootDoor.Info[tokens[0].strip()]=tokens[1].strip() ; connection.sendObject(self.XrootDoor.CellName, "get children",MyMessageListener, self.currentID ) return def getChildrenNames(self,obj) : self.currentID += 1 for kid in obj.split("\n") : if not "%s-unknow" % self.XrootDoor.CellName in kid : continue self.XrootDoor.Connections.append( { "CellName" : "N/A", "Protocol Version": "N/A", "Connected with" : "N/A", "number of open files" : "N/A", "number of logical streams" : "N/A" } ) self.XrootDoor.Connections[-1:][0]["CellName"]=kid if len(self.XrootDoor.Connections) > 0 : connection.sendObject(self.XrootDoor.Connections[self.currentXrootKid]["CellName"], "info",MyMessageListener, self.currentID ) return def getChildrenInfo(self,obj) : if type(obj) == types.StringType : tokens=obj.split("\n") self.XrootDoor.Connections[self.currentXrootKid]["Protocol Version"]=tokens[1][len("Protocol Version"):].strip() self.XrootDoor.Connections[self.currentXrootKid]["Connected with"]=tokens[2][len("Connected with"):].strip() self.XrootDoor.Connections[self.currentXrootKid]["number of open files"]=tokens[3][len("number of open files:"):].strip() self.XrootDoor.Connections[self.currentXrootKid]["number of logical streams"]=tokens[4][len("number of logical streams:"):].strip() self.currentXrootKid += 1 if self.currentXrootKid < len(self.XrootDoor.Connections) : self.currentID += 1 connection.sendObject(self.XrootDoor.Connections[self.currentXrootKid]["CellName"], "info",MyMessageListener, self.currentID ) return def domainAnswerArrived( self , obj , id ) : if DEBUG : print "id=%d,child-cutoff=%d" % (id,connectionStartID+2+len(self.XrootDoor.Connections)) if id == connectionStartID : self.currentID += 1 connection.sendObject(self.XrootDoor.CellName, "info",MyMessageListener, self.currentID ) ; elif id == connectionStartID+1 : self.getInfo(obj) elif id == connectionStartID+2 : self.getChildrenNames(obj) elif id > connectionStartID+2 and id < connectionStartID+2+len(self.XrootDoor.Connections) : self.getChildrenInfo(obj) elif id == connectionStartID+2+len(self.XrootDoor.Connections) : self.getChildrenInfo(obj) # store the info of the last kid self.currentID += 1 connection.sendObject("local","logoff",MyMessageListener, self.currentID ) else : self.XrootDoor.html_dump() System.exit(0) class XrootDoor : def __init__(self,CellName) : self.CellName=CellName self.Info={} self.Connections=[] return def dump(self) : print "CellName: %s" % self.CellName print "Info :" for k in self.Info : print "%s : %s" % (k,self.Info[k]) print "Connections :" for k in self.Connections: print "%s" % (k) def html_dump(self) : print """ HIP/CSC Storage Element """ print "

Statistics Xrootd-Door %s

" % self.CellName print "Updated at: %s
" % time.asctime(time.localtime()) print "

Connections - Overview

" print '' print "" print "" print "" print "" print "" print "" print "" print "" print "" % self.Info["Logins/max"].split("/")[0] print "" % self.Info["Logins/max"].split("/")[1] print "" % self.Info["Logins denied"] print "" % self.Info["Logins failed"] print "" % self.Info["Logins created"] print "" print "
current LoginsMax. current LoginsDenied LoginsFailed LoginsTotal Logins Created
%s%s%s%s%s
" print "

Open connections by Client

" print "For sorting by column click on the table headers" print '' print "" print "" ConnsByClient={} for k in self.Connections : if ConnsByClient.has_key(k["Connected with"]) : ConnsByClient[k["Connected with"]] += 1 else : ConnsByClient[k["Connected with"]] = 1 tmpkeys=ConnsByClient.keys() tmpkeys.sort() for k in tmpkeys : print "" print "" % k print "" % ConnsByClient[k] print "" print "
Clientnumber of open connections
%s%s
" print "

Detailed Info of the Xrootd-Door

" print "" print "

All open connections

" print "For sorting by column click on the table headers" print '' print "" print "" for k in self.Connections: print "" print "" % k["CellName"] print "" % k["Protocol Version"] print "" % k["Connected with"] print "" % k["number of logical streams"] print "" % k["number of open files"] print "" print "
CellNameProtocol VersionConnected withnumber of logical streamsnumber of open files
%s%s%s%s%s
" print "" #---------------------------------------------------------------------- # # Main Routine # #---------------------------------------------------------------------- # if len(sys.argv) < 6 : print "Usage : ... " System.exit(4) # # Define the ListenerObject for all incoming message # MyXrootDoor=XrootDoor(CellName=sys.argv[5]) MyMessageListener = ourDomainConnectionListener(MyXrootDoor) MyDomainEventListener=ourDomainEventListener(MyXrootDoor) # # Define Host and portnumber # connection=Ssh1DomainConnection(sys.argv[1],int(sys.argv[2])) connection.setLoginName(sys.argv[3]) # # Establish the secret : either password or identity file # secret=sys.argv[4] if secret[0] == "/" : connection.setPassword("") try : connection.setIdentityFile( File(secret) ) except FileNotFoundException, e : print "Authentication Failed ...",e.getMessage() System.exit(1) else : connection.setPassword(secret) connection.addDomainEventListener( MyDomainEventListener ) # # and now go # try : connection.go() except SshAuthenticationException, e : print "Authentication Failed ...",e.getMessage() System.exit(1)