Changeset 700


Ignore:
Timestamp:
03/21/13 16:38:54 (11 years ago)
Author:
ramonb
Message:
  • updated Gmetric XDR protocol to version 3.1+ compatible
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/0.4/jobmond/jobmond.py

    r699 r700  
    16911691                del self.jobs[ id ]
    16921692
    1693 #
    1694 # Gmetric by Nick Galbreath - nickg(a.t)modp(d.o.t)com
    1695 # Version 1.0 - 21-April2-2007
    1696 # http://code.google.com/p/embeddedgmetric/
    1697 #
    1698 # Modified by: Ramon Bastiaans
    1699 # For the Job Monarch Project, see: https://subtrac.sara.nl/oss/jobmonarch/
    1700 #
    1701 # added: DEFAULT_TYPE for Gmetric's
    1702 # added: checkHostProtocol to determine if target is multicast or not
    1703 # changed: allow default for Gmetric constructor
    1704 # changed: allow defaults for all send() values except dmax
    1705 #
    1706 
    17071693GMETRIC_DEFAULT_TYPE    = 'string'
    17081694GMETRIC_DEFAULT_HOST    = '127.0.0.1'
    17091695GMETRIC_DEFAULT_PORT    = '8649'
    1710 GMETRIC_DEFAULT_UNITS    = ''
     1696GMETRIC_DEFAULT_UNITS   = ''
    17111697
    17121698class Gmetric:
     
    17141700    global GMETRIC_DEFAULT_HOST, GMETRIC_DEFAULT_PORT
    17151701
    1716     slope       = { 'zero' : 0, 'positive' : 1, 'negative' : 2, 'both' : 3, 'unspecified' : 4 }
    1717     type        = ( '', 'string', 'uint16', 'int16', 'uint32', 'int32', 'float', 'double', 'timestamp' )
    1718     protocol    = ( 'udp', 'multicast' )
     1702    slope           = { 'zero' : 0, 'positive' : 1, 'negative' : 2, 'both' : 3, 'unspecified' : 4 }
     1703    type            = ( '', 'string', 'uint16', 'int16', 'uint32', 'int32', 'float', 'double', 'timestamp' )
     1704    protocol        = ( 'udp', 'multicast' )
    17191705
    17201706    def __init__( self, host=GMETRIC_DEFAULT_HOST, port=GMETRIC_DEFAULT_PORT ):
    1721        
     1707               
    17221708        global GMETRIC_DEFAULT_TYPE
    17231709
    17241710        self.prot       = self.checkHostProtocol( host )
    1725         self.msg    = xdrlib.Packer()
     1711        self.data_msg   = xdrlib.Packer()
     1712        self.meta_msg   = xdrlib.Packer()
    17261713        self.socket     = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
    17271714
     
    17471734        MULTICAST_ADDRESS_MAX   = ( "239", "255", "255", "255" )
    17481735
    1749         ip_fields           = ip.split( '.' )
     1736        ip_fields               = ip.split( '.' )
    17501737
    17511738        if ip_fields >= MULTICAST_ADDRESS_MIN and ip_fields <= MULTICAST_ADDRESS_MAX:
     
    17581745
    17591746        if len( units ) == 0:
    1760             units        = GMETRIC_DEFAULT_UNITS
     1747            units       = GMETRIC_DEFAULT_UNITS
    17611748
    17621749        if len( typestr ) == 0:
    1763             typestr        = GMETRIC_DEFAULT_TYPE
    1764 
    1765         msg         = self.makexdr( name, value, typestr, units, self.slopestr, self.tmax, dmax )
    1766 
    1767         return self.socket.sendto( msg, self.hostport )
    1768 
    1769     def makexdr( self, name, value, typestr, unitstr, slopestr, tmax, dmax ):
     1750            typestr     = GMETRIC_DEFAULT_TYPE
     1751
     1752        (meta_msg, data_msg) = self.makexdr( name, value, typestr, units, self.slopestr, self.tmax, dmax )
     1753
     1754        meta_rt = self.socket.sendto( meta_msg, self.hostport )
     1755        data_rt = self.socket.sendto( data_msg, self.hostport )
     1756
     1757        return ( meta_rt, data_rt )
     1758
     1759    def makexdr( self, name, value, typestr, unitstr, slopestr, tmax, dmax, group=None, spoof=None ):
     1760
     1761        hostname = "unset"
    17701762
    17711763        if slopestr not in self.slope:
     
    17811773            raise ValueError( "Name must be non-empty" )
    17821774
    1783         self.msg.reset()
    1784         self.msg.pack_int( 0 )
    1785         self.msg.pack_string( typestr )
    1786         self.msg.pack_string( name )
    1787         self.msg.pack_string( str( value ) )
    1788         self.msg.pack_string( unitstr )
    1789         self.msg.pack_int( self.slope[ slopestr ] )
    1790         self.msg.pack_uint( int( tmax ) )
    1791         self.msg.pack_uint( int( dmax ) )
    1792 
    1793         return self.msg.get_buffer()
     1775        self.meta_msg.reset()
     1776        self.meta_msg.pack_int( 128 )
     1777
     1778        if not spoof:
     1779            self.meta_msg.pack_string( hostname )
     1780        else:
     1781            self.meta_msg.pack_string( spoof )
     1782
     1783        self.meta_msg.pack_string( name )
     1784
     1785        if not spoof:
     1786            self.meta_msg.pack_int( 0 )
     1787        else:
     1788            self.meta_msg.pack_int( 1 )
     1789           
     1790        self.meta_msg.pack_string( typestr )
     1791        self.meta_msg.pack_string( name )
     1792        self.meta_msg.pack_string( unitstr )
     1793        self.meta_msg.pack_int( self.slope[ slopestr ] )
     1794        self.meta_msg.pack_uint( int( tmax ) )
     1795        self.meta_msg.pack_uint( int( dmax ) )
     1796
     1797        if not group:
     1798            self.meta_msg.pack_int( 0 )
     1799        else:
     1800            self.meta_msg.pack_int( 1 )
     1801            self.meta_msg.pack_string( "GROUP" )
     1802            self.meta_msg.pack_string( group )
     1803
     1804        self.data_msg.reset()
     1805        self.data_msg.pack_int( 128+5 )
     1806
     1807        if not spoof:
     1808            self.data_msg.pack_string( hostname )
     1809        else:
     1810            self.data_msg.pack_string( spoof )
     1811
     1812        self.data_msg.pack_string( name )
     1813
     1814        if not spoof:
     1815            self.data_msg.pack_int( 0 )
     1816        else:
     1817            self.data_msg.pack_int( 1 )
     1818
     1819        self.data_msg.pack_string( "%s" )
     1820        self.data_msg.pack_string( str( value ) )
     1821
     1822        return ( self.meta_msg.get_buffer(), self.data_msg.get_buffer() )
    17941823
    17951824def printTime( ):
Note: See TracChangeset for help on using the changeset viewer.