Python module for Accounting
Erdal Emlik
erdalemlik at icloud.com
Thu Feb 13 09:10:36 UTC 2025
Sorry for rewriting except KafkaException as e: was except Exception as e:
> On 13 Feb 2025, at 12:08, Erdal Emlik <erdalemlik at icloud.com> wrote:
>
> Hi List,
> I’m trying to send accounting logs to Kafka using the FreeRADIUS Python module (example.py). I’ve implemented a callback and exception handling, but when I manually stop the Kafka service, I can’t catch any errors—neither in the callback nor in the exception block.
>
> def delivery_report(err,msg):
> if err is not None:
> logstash_logger.add_info_log(f"Failed Message, Key : {msg.key()} Value : {msg.value()} Err : {err}")
>
> def accounting(p):
> try:
> record = create_record(p)
> logstash_logger.add_info_log("accounting started 1")
>
> if len(record.User_Name) == 0:
> raise Exception("User-Name can not be found in request!")
>
> key_for_record = create_key_for_record(record)
> logstash_logger.add_info_log("accounting started 2")
> kafka_producer.produce(kafka_topic, key=key_for_record, value=json.dumps(record.__dict__),callback=delivery_report)
> kafka_producer.poll(0)
> logstash_logger.add_info_log("accounting started 3")
> except KafkaException as e:
> logstash_logger.add_info_log(f"accounting started 4 {err}")
>
> logstash_logger.add_info_log("accounting started 5")
> return radiusd.RLM_MODULE_OK
>
> I can see logs 1-2-3-5, but my goal is to detect when a message fails to send and store it for later retries. However, I’m not sure if I’m on the right path.
>
>
>
> If needed, I can provide more details, debug output, and code snippets.
>
>
>
> Looking forward to your guidance.
>
>
>
> Best regards,
>
More information about the Freeradius-Users
mailing list