<s> """<STR_LIT>""" <EOL> import os <EOL> import subprocess <EOL> import re <EOL> import diamond . collector <EOL> import diamond . convertor <EOL> class AmavisCollector ( diamond . collector . Collector ) : <EOL> matchers = [ <EOL> re . compile ( r'<STR_LIT>' <EOL> r'<STR_LIT>' ) , <EOL> re . compile ( r'<STR_LIT>' <EOL> r'<STR_LIT>' ) , <EOL> re . compile ( r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' ) , <EOL> re . compile ( r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' ) , <EOL> ] <EOL> def get_default_config_help ( self ) : <EOL> config_help = super ( AmavisCollector , self ) . get_default_config_help ( ) <EOL> config_help . update ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> return config_help <EOL> def get_default_config ( self ) : <EOL> config = super ( AmavisCollector , self ) . get_default_config ( ) <EOL> config . update ( { <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> return config <EOL> def collect ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if self . config [ '<STR_LIT>' ] : <EOL> cmdline = [ <EOL> self . config [ '<STR_LIT>' ] , '<STR_LIT>' , self . config [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , self . config [ '<STR_LIT>' ] , '<STR_LIT:-c>' , '<STR_LIT:1>' <EOL> ] <EOL> else : <EOL> cmdline = [ self . config [ '<STR_LIT>' ] , '<STR_LIT:-c>' , '<STR_LIT:1>' ] <EOL> agent = subprocess . Popen ( cmdline , stdout = subprocess . PIPE ) <EOL> agent_out = agent . communicate ( ) [ <NUM_LIT:0> ] <EOL> lines = agent_out . strip ( ) . split ( os . linesep ) <EOL> for line in lines : <EOL> for rex in self . matchers : <EOL> res = rex . match ( line ) <EOL> if res : <EOL> groups = res . groupdict ( ) <EOL> name = groups [ '<STR_LIT:name>' ] <EOL> for metric , value in groups . items ( ) : <EOL> if metric == '<STR_LIT:name>' : <EOL> continue <EOL> mtype = '<STR_LIT>' <EOL> if metric in ( '<STR_LIT:count>' , '<STR_LIT:time>' ) : <EOL> mtype = '<STR_LIT>' <EOL> self . publish ( "<STR_LIT>" . format ( name , metric ) , <EOL> value , metric_type = mtype ) <EOL> except OSError as err : <EOL> self . log . error ( "<STR_LIT>" , <EOL> self . config [ '<STR_LIT>' ] , <EOL> err ) <EOL> return None <EOL> return True </s>
