def accounting(received): """Log data of completed session (call). Input: (dict) received data Output: none """ dbh = DatabaseConnection.getHandler('mod_sql_1') acctType = received.get('Acct-Status-Type', [None])[0] if not acctType: raise ModsqlError, 'Acct-Status-Type not found in request' debug('Accounting %s message received' % acctType) supportedAcctTypes = ['Start', 'Alive', 'Stop'] if acctType not in supportedAcctTypes: return # translate "-" to "_" in request attributes attrs = translateAttrs(received) # Parse date and time from cisco format to datetime class when using # mysql. There are no problems with postgresql however. # This should be done for users who want to log call start and end times into # database. Since they can wish to log these attributes during any type of # request, we should always parse them. if radParsedConfig['ACCESS']['type'] != 'postgresql': tmp = { } # use temporary storage to avoid messing up received attributes tmp['h323_setup_time'] = parseDatetime(attrs.get( 'h323_setup_time', '')) tmp['h323_connect_time'] = parseDatetime( attrs.get('h323_connect_time', '')) tmp['h323_disconnect_time'] = parseDatetime( attrs.get('h323_disconnect_time', '')) for key, value in tmp.iteritems(): if value != None: attrs[key] = str(value) # get sql query template based on Acct-Status-Type parameter queryTpl = None if acctType == 'Start': queryTpl = radParsedConfig['ACCOUNTING'].get('acct_start_query', None) elif acctType == 'Alive': queryTpl = radParsedConfig['ACCOUNTING'].get('acct_update_query', None) elif acctType == 'Stop': queryTpl = radParsedConfig['ACCOUNTING'].get('acct_stop_query', None) # check and parse query template if queryTpl == None: return query = Template(queryTpl).substitute( attrs) # use request items for keyword replacement # execute query success = dbh.execute(query) if not success: raise ModsqlError, "Error executing accounting %s SQL query" % acctType
def accounting(received): """Log data of completed session (call). Input: (dict) received data Output: none """ dbh = DatabaseConnection.getHandler('mod_sql_1') acctType = received.get('Acct-Status-Type', [None])[0] if not acctType: raise ModsqlError, 'Acct-Status-Type not found in request' debug ('Accounting %s message received' % acctType) supportedAcctTypes = ['Start', 'Alive', 'Stop'] if acctType not in supportedAcctTypes: return # translate "-" to "_" in request attributes attrs = translateAttrs(received) # Parse date and time from cisco format to datetime class when using # mysql. There are no problems with postgresql however. # This should be done for users who want to log call start and end times into # database. Since they can wish to log these attributes during any type of # request, we should always parse them. if radParsedConfig['ACCESS']['type'] != 'postgresql': tmp = {} # use temporary storage to avoid messing up received attributes tmp['h323_setup_time'] = parseDatetime(attrs.get('h323_setup_time', '')) tmp['h323_connect_time'] = parseDatetime(attrs.get('h323_connect_time', '')) tmp['h323_disconnect_time'] = parseDatetime(attrs.get('h323_disconnect_time', '')) for key, value in tmp.iteritems(): if value != None: attrs[key] = str(value) # get sql query template based on Acct-Status-Type parameter queryTpl = None if acctType == 'Start': queryTpl = radParsedConfig['ACCOUNTING'].get('acct_start_query', None) elif acctType == 'Alive': queryTpl = radParsedConfig['ACCOUNTING'].get('acct_update_query', None) elif acctType == 'Stop': queryTpl = radParsedConfig['ACCOUNTING'].get('acct_stop_query', None) # check and parse query template if queryTpl == None: return query = Template(queryTpl).substitute(attrs) # use request items for keyword replacement # execute query success = dbh.execute(query) if not success: raise ModsqlError, "Error executing accounting %s SQL query" % acctType
def testParseDatetime6(self): """Test CISCO datetime parsing""" input = "+12:04:59.002345 Western Pacific Mon Mar 2 2006" right = "2006-03-02 12:04:59.002345" self.failUnless(str(misc.parseDatetime(input)) == right)
def testParseDatetime4(self): """Test CISCO datetime parsing""" input = "12:04:59 UTC Mon Mar 2 2006" right = "2006-03-02 12:04:59" self.failUnless(str(misc.parseDatetime(input)) == right)
def testParseDatetime3(self): """Test ISO datetime parsing""" input = "2006-03-02 12:04:59.123456" right = "2006-03-02 12:04:59.123456" self.failUnless(str(misc.parseDatetime(input)) == right)