Python module for Accounting
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,
Sorry for rewriting except KafkaException as e: was except Exception as e:
On 13 Feb 2025, at 12:08, Erdal Emlik <erdalemlik@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,
On Feb 13, 2025, at 4:08 AM, Erdal Emlik via Freeradius-Users <freeradius-users@lists.freeradius.org> wrote:
I’m trying to send accounting logs to Kafka using the FreeRADIUS Python module (example.py).
IIRC, there's a third-party "rlm_kafka" on github somewhere. From what I remember, it didn't look too bad.
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.
That's really a python question. FreeRADIUS just sets up the Python interpreter, and calls it. Everything after that is Python magic, and we don't know anything about it.
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.
That's a question for the Kafka Python API. Alan DeKok.
You are right, Alan. When I sent the email, I realized that the issue wasn’t related to FreeRADIUS. I apologize for bothering you for no reason and thank you for your quick response.
On 13 Feb 2025, at 15:07, Alan DeKok <aland@deployingradius.com> wrote:
On Feb 13, 2025, at 4:08 AM, Erdal Emlik via Freeradius-Users <freeradius-users@lists.freeradius.org> wrote:
I’m trying to send accounting logs to Kafka using the FreeRADIUS Python module (example.py).
IIRC, there's a third-party "rlm_kafka" on github somewhere. From what I remember, it didn't look too bad.
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.
That's really a python question. FreeRADIUS just sets up the Python interpreter, and calls it. Everything after that is Python magic, and we don't know anything about it.
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.
That's a question for the Kafka Python API.
Alan DeKok.
participants (2)
-
Alan DeKok -
Erdal Emlik