Using TIPCommon.write_content (and read_content) in a connector

Hi, I'm trying to wrote and read ids (json format) using TIPCommon package, but unable to make it work.

I've created the following test connector in an existing integration, and running it test mode (I've also tried running it in live mode):

 

from __future__ import annotations

import datetime
import json
import uuid
import os

from SiemplifyConnectors import SiemplifyConnectorExecution
from SiemplifyConnectorsDataModel import CaseInfo
from SiemplifyUtils import output_handler, unix_now
from TIPCommon import read_content, write_content

OFFENSE_EVENTS_FILE = "offense_events_test.json"
IDS_DB_KEY = 'seenids'

class TestFileIO:
    def __init__(self):
        self.siemplify = SiemplifyConnectorExecution()
        self.siemplify.script_name = "TestFileIO"
        self.logger = self.siemplify.LOGGER
        self.offense_events = {
            "last_offense_padding_period": 60,
            "offenses": {
                "261723": {
                    "last_update_time": 1750151974649,
                    "no_new_events_timer_start_time": -1,
                    "events": {
                        "e9f716b1a5b7c2a458649b19d6116c": {
                            "rules": [174399],
                            "timestamp": 1750156011530,
                        },
                        "a670d274bbba7e04f1da02772f8df8": {
                            "rules": [174399],
                            "timestamp": 1750156011530,
                        }
                    },
                },
                "261737": {
                    "last_update_time": 1750152957273,
                    "no_new_events_timer_start_time": -1,
                    "events": {
                        "f7e862851ba61927696bf4555d91aa": {
                            "rules": [174399],
                            "timestamp": 1750156037272,
                        },
                        "70d8a608849454a2daa2a73335fb6e": {
                            "rules": [174399],
                            "timestamp": 1750156037272,
                        }
                    },
                },
            }
        }

    
    def load_offense_events(self):
        self.logger.info("Reading content")

        try:
            file_contents = read_content(self.siemplify, OFFENSE_EVENTS_FILE, IDS_DB_KEY, default_value_to_return={"default":"test"})
        except Exception as e:
            self.logger.error(e)

        print(file_contents)
        self.logger.info(file_contents)

        self.logger.info("End load file")

    def save_offense_events_file(self):
        self.logger.info("Saving content to file")

        try:
            write_content(self.siemplify, self.offense_events, OFFENSE_EVENTS_FILE, IDS_DB_KEY)
        except Exception as e:
            self.logger.error(e)
        
        self.logger.info("End save file")

if __name__ == "__main__":
    instance = TestFileIO()

    instance.save_offense_events_file()
    instance.load_offense_events()

 

The log lines display as expected, but no content in written or read from database. Here's the debug output:

 

[2025-06-18,18:12:32,000 INFO] No data found for property key: overflow_settings
[2025-06-18,18:12:32,000 INFO] Saving content to file
[2025-06-18,18:12:32,000 INFO] End save file
[2025-06-18,18:12:32,000 INFO] Reading content
LOGGER: loadConfigFromFile FAILED[2025-06-18,18:12:32,000 INFO] End load file

 

 What could be the problem here?

Thanks!

1 1 241
1 REPLY 1

Hi @moinsoar. You are so close! You just need to convert the python dictionary to a JSON string on line 73 when you are calling the write_content method. It should look something like this: 

write_content(self.siemplify, json.dumps(self.offense_events), OFFENSE_EVENTS_FILE, IDS_DB_KEY)
 
Let me know if you continue to run into issue.