<s> import cPickle as pickle <EOL> import json <EOL> from jasmin . protocols . cli . managers import Manager <EOL> from jasmin . protocols . smpp . stats import SMPPClientStatsCollector , SMPPServerStatsCollector <EOL> from jasmin . protocols . http . stats import HttpAPIStatsCollector <EOL> from . usersm import UserExist <EOL> from . smppccm import ConnectorExist <EOL> from jasmin . vendor . tabulate import tabulate <EOL> def formatDateTime ( dt ) : <EOL> if dt == <NUM_LIT:0> : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return dt . strftime ( "<STR_LIT>" ) <EOL> class StatsManager ( Manager ) : <EOL> "<STR_LIT>" <EOL> managerName = '<STR_LIT>' <EOL> @ UserExist ( uid_key = '<STR_LIT:user>' ) <EOL> def user ( self , arg , opts ) : <EOL> headers = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> table = [ ] <EOL> user = self . pb [ '<STR_LIT>' ] . getUser ( opts . user ) <EOL> for k , v in user . getCnxStatus ( ) . smpps . iteritems ( ) : <EOL> if isinstance ( v , dict ) : <EOL> v = json . dumps ( v ) <EOL> row = [ ] <EOL> row . append ( '<STR_LIT>' % k ) <EOL> row . append ( '<STR_LIT>' ) <EOL> if k [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> row . append ( formatDateTime ( v ) ) <EOL> else : <EOL> row . append ( v ) <EOL> table . append ( row ) <EOL> for k , v in user . getCnxStatus ( ) . httpapi . iteritems ( ) : <EOL> if isinstance ( v , dict ) : <EOL> v = json . dumps ( v ) <EOL> row = [ ] <EOL> row . append ( '<STR_LIT>' % k ) <EOL> row . append ( '<STR_LIT>' ) <EOL> if k [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> row . append ( formatDateTime ( v ) ) <EOL> else : <EOL> row . append ( v ) <EOL> table . append ( row ) <EOL> self . protocol . sendData ( <EOL> tabulate ( table , headers , tablefmt = "<STR_LIT>" , numalign = "<STR_LIT:left>" ) . encode ( '<STR_LIT:ascii>' ) ) <EOL> def users ( self , arg , opts ) : <EOL> headers = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> table = [ ] <EOL> users = pickle . loads ( self . pb [ '<STR_LIT>' ] . perspective_user_get_all ( None ) ) <EOL> for user in users : <EOL> row = [ ] <EOL> row . append ( '<STR_LIT>' % user . uid ) <EOL> row . append ( user . getCnxStatus ( ) . smpps [ '<STR_LIT>' ] [ '<STR_LIT>' ] + <EOL> user . getCnxStatus ( ) . smpps [ '<STR_LIT>' ] [ '<STR_LIT>' ] + <EOL> user . getCnxStatus ( ) . smpps [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> row . append ( formatDateTime ( user . getCnxStatus ( ) . smpps [ '<STR_LIT>' ] ) ) <EOL> row . append ( user . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] ) <EOL> row . append ( formatDateTime ( user . getCnxStatus ( ) . httpapi [ '<STR_LIT>' ] ) ) <EOL> table . append ( row ) <EOL> self . protocol . sendData ( <EOL> tabulate ( table , headers , tablefmt = "<STR_LIT>" , numalign = "<STR_LIT:left>" ) . encode ( '<STR_LIT:ascii>' ) , prompt = False ) <EOL> self . protocol . sendData ( '<STR_LIT>' % ( len ( table ) ) ) <EOL> @ ConnectorExist ( cid_key = '<STR_LIT>' ) <EOL> def smppc ( self , arg , opts ) : <EOL> sc = SMPPClientStatsCollector ( ) <EOL> headers = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> table = [ ] <EOL> for k , v in sc . get ( opts . smppc ) . getStats ( ) . iteritems ( ) : <EOL> if isinstance ( v , dict ) : <EOL> v = json . dumps ( v ) <EOL> row = [ ] <EOL> row . append ( '<STR_LIT>' % k ) <EOL> if k [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> row . append ( formatDateTime ( v ) ) <EOL> else : <EOL> row . append ( v ) <EOL> table . append ( row ) <EOL> self . protocol . sendData ( <EOL> tabulate ( table , headers , tablefmt = "<STR_LIT>" , numalign = "<STR_LIT:left>" ) . encode ( '<STR_LIT:ascii>' ) ) <EOL> def smppcs ( self , arg , opts ) : <EOL> sc = SMPPClientStatsCollector ( ) <EOL> headers = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> table = [ ] <EOL> connectors = self . pb [ '<STR_LIT>' ] . perspective_connector_list ( ) <EOL> for connector in connectors : <EOL> row = [ ] <EOL> row . append ( '<STR_LIT>' % connector [ '<STR_LIT:id>' ] ) <EOL> row . append ( formatDateTime ( sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) ) ) <EOL> row . append ( formatDateTime ( sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) ) ) <EOL> row . append ( formatDateTime ( sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) ) ) <EOL> row . append ( '<STR_LIT>' % ( <EOL> sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) , <EOL> sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) ) ) <EOL> row . append ( '<STR_LIT>' % ( <EOL> sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) , <EOL> sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) ) ) <EOL> row . append ( sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) ) <EOL> row . append ( sc . get ( connector [ '<STR_LIT:id>' ] ) . get ( '<STR_LIT>' ) ) <EOL> table . append ( row ) <EOL> self . protocol . sendData ( <EOL> tabulate ( table , headers , tablefmt = "<STR_LIT>" , numalign = "<STR_LIT:left>" ) . encode ( '<STR_LIT:ascii>' ) , prompt = False ) <EOL> self . protocol . sendData ( '<STR_LIT>' % ( len ( table ) ) ) <EOL> def httpapi ( self , arg , opts ) : <EOL> sc = HttpAPIStatsCollector ( ) <EOL> headers = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> table = [ ] <EOL> for k , v in sc . get ( ) . getStats ( ) . iteritems ( ) : <EOL> if isinstance ( v , dict ) : <EOL> v = json . dumps ( v ) <EOL> row = [ ] <EOL> row . append ( '<STR_LIT>' % k ) <EOL> if k [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> row . append ( formatDateTime ( v ) ) <EOL> else : <EOL> row . append ( v ) <EOL> table . append ( row ) <EOL> self . protocol . sendData ( tabulate ( table , headers , tablefmt = "<STR_LIT>" , numalign = "<STR_LIT:left>" ) . encode ( '<STR_LIT:ascii>' ) ) <EOL> def smppsapi ( self , arg , opts ) : <EOL> """<STR_LIT>""" <EOL> sc = SMPPServerStatsCollector ( ) <EOL> headers = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> table = [ ] <EOL> for k , v in sc . get ( '<STR_LIT>' ) . getStats ( ) . iteritems ( ) : <EOL> row = [ ] <EOL> row . append ( '<STR_LIT>' % k ) <EOL> if k [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> row . append ( formatDateTime ( v ) ) <EOL> else : <EOL> row . append ( v ) <EOL> table . append ( row ) <EOL> self . protocol . sendData ( tabulate ( table , headers , tablefmt = "<STR_LIT>" , numalign = "<STR_LIT:left>" ) . encode ( '<STR_LIT:ascii>' ) ) </s>
