<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Duplicate logs via modular input in Deployment Architecture</title>
    <link>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690126#M28261</link>
    <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;We are using modular input to ingest the logs into splunk, we have checkpoint file, but we see duplicate logs are ingested into splunk. How to eliminate duplicates?&lt;BR /&gt;application from which the logs are ingested - Tyk analytics&lt;/P&gt;</description>
    <pubDate>Sun, 09 Jun 2024 11:38:52 GMT</pubDate>
    <dc:creator>VijaySrrie</dc:creator>
    <dc:date>2024-06-09T11:38:52Z</dc:date>
    <item>
      <title>Duplicate logs via modular input</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690126#M28261</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;We are using modular input to ingest the logs into splunk, we have checkpoint file, but we see duplicate logs are ingested into splunk. How to eliminate duplicates?&lt;BR /&gt;application from which the logs are ingested - Tyk analytics&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jun 2024 11:38:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690126#M28261</guid>
      <dc:creator>VijaySrrie</dc:creator>
      <dc:date>2024-06-09T11:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate logs via modular input</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690157#M28268</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/164779"&gt;@VijaySrrie&lt;/a&gt;&amp;nbsp;... you have given only very least details.&amp;nbsp;&lt;/P&gt;&lt;P&gt;pls provide us the modular input script.. the config files..&amp;nbsp;&lt;/P&gt;&lt;P&gt;is the modular input working fine previously and just recently it started the duplicates?&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jun 2024 19:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690157#M28268</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2024-06-09T19:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate logs via modular input</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690196#M28270</link>
      <description>&lt;P&gt;#!/usr/bin/env python&lt;BR /&gt;# coding=utf-8&lt;/P&gt;&lt;P&gt;from __future__ import print_function&lt;BR /&gt;import sys, os&lt;BR /&gt;import xml.dom.minidom, xml.sax.saxutils&lt;BR /&gt;from pymongo import MongoClient&lt;BR /&gt;from datetime import datetime&lt;BR /&gt;import base64&lt;BR /&gt;import json&lt;BR /&gt;import re&lt;/P&gt;&lt;P&gt;import logging&lt;BR /&gt;from io import open&lt;BR /&gt;import six&lt;BR /&gt;logging.root&lt;BR /&gt;logging.root.setLevel(logging.DEBUG)&lt;BR /&gt;formatter = logging.Formatter('%(levelname)s %(message)s')&lt;BR /&gt;handler = logging.StreamHandler()&lt;BR /&gt;handler.setFormatter(formatter)&lt;BR /&gt;logging.root.addHandler(handler)&lt;/P&gt;&lt;P&gt;SCHEME = """&amp;lt;scheme&amp;gt;&lt;BR /&gt;&amp;lt;title&amp;gt;API Gateway Analytics&amp;lt;/title&amp;gt;&lt;BR /&gt;&amp;lt;description&amp;gt;Ingest data from API Gateway mongodb tyk_analytics database&amp;lt;/description&amp;gt;&lt;BR /&gt;&amp;lt;streaming_mode&amp;gt;xml&amp;lt;/streaming_mode&amp;gt;&lt;BR /&gt;&amp;lt;endpoint&amp;gt;&lt;BR /&gt;&amp;lt;args&amp;gt;&lt;BR /&gt;&amp;lt;arg name="mongodb_uri"&amp;gt;&lt;BR /&gt;&amp;lt;title&amp;gt;MongoDB URI&amp;lt;/title&amp;gt;&lt;BR /&gt;&amp;lt;description&amp;gt;mongodb://USER:PASS@SERVER1:27017,SERVER2:27017/tyk_analytics?replicaSet=mongo-replica&amp;lt;/description&amp;gt;&lt;BR /&gt;&amp;lt;/arg&amp;gt;&lt;BR /&gt;&amp;lt;/args&amp;gt;&lt;BR /&gt;&amp;lt;/endpoint&amp;gt;&lt;BR /&gt;&amp;lt;/scheme&amp;gt;&lt;BR /&gt;"""&lt;/P&gt;&lt;P&gt;def do_scheme():&lt;BR /&gt;print(SCHEME)&lt;/P&gt;&lt;P&gt;# Empty validation routine. This routine is optional.&lt;BR /&gt;def validate_arguments():&lt;BR /&gt;pass&lt;/P&gt;&lt;P&gt;def get_config():&lt;BR /&gt;config = {}&lt;/P&gt;&lt;P&gt;try:&lt;BR /&gt;# read everything from stdin&lt;BR /&gt;config_str = sys.stdin.read()&lt;/P&gt;&lt;P&gt;# parse the config XML&lt;BR /&gt;doc = xml.dom.minidom.parseString(config_str)&lt;BR /&gt;root = doc.documentElement&lt;BR /&gt;conf_node = root.getElementsByTagName("configuration")[0]&lt;BR /&gt;if conf_node:&lt;BR /&gt;stanza = conf_node.getElementsByTagName("stanza")[0]&lt;BR /&gt;if stanza:&lt;BR /&gt;stanza_name = stanza.getAttribute("name")&lt;BR /&gt;if stanza_name:&lt;BR /&gt;logging.debug("XML: found stanza " + stanza_name)&lt;BR /&gt;config["name"] = stanza_name&lt;BR /&gt;params = stanza.getElementsByTagName("param")&lt;BR /&gt;for param in params:&lt;BR /&gt;param_name = param.getAttribute("name")&lt;BR /&gt;logging.debug("XML: found param '%s'" % param_name)&lt;BR /&gt;if param_name and param.firstChild and param.firstChild.nodeType == param.firstChild.TEXT_NODE:&lt;BR /&gt;data = param.firstChild.data&lt;BR /&gt;config[param_name] = data&lt;BR /&gt;logging.debug("XML: '%s' -&amp;gt; '%s'" % (param_name, data))&lt;/P&gt;&lt;P&gt;checkpnt_node = root.getElementsByTagName("checkpoint_dir")[0]&lt;BR /&gt;if checkpnt_node and checkpnt_node.firstChild and checkpnt_node.firstChild.nodeType == checkpnt_node.firstChild.TEXT_NODE:&lt;BR /&gt;config["checkpoint_dir"] = checkpnt_node.firstChild.data&lt;/P&gt;&lt;P&gt;if not config:&lt;BR /&gt;raise Exception("Invalid configuration received from Splunk.")&lt;/P&gt;&lt;P&gt;except Exception as e:&lt;BR /&gt;raise Exception("Error getting Splunk configuration via STDIN: %s" % str(e))&lt;/P&gt;&lt;P&gt;return config&lt;/P&gt;&lt;P&gt;def save_checkpoint(config, checkpoint):&lt;BR /&gt;checkpoint_file = "checkpoint-" + config["name"]&lt;BR /&gt;checkpoint_file = re.sub('[\\/\s]', '', checkpoint_file)&lt;BR /&gt;checkpoint_file_new = checkpoint_file + ".new"&lt;BR /&gt;chk_file = os.path.join(config["checkpoint_dir"], checkpoint_file)&lt;BR /&gt;chk_file_new = os.path.join(config["checkpoint_dir"], checkpoint_file_new)&lt;/P&gt;&lt;P&gt;checkpoint_rfc3339=checkpoint.strftime('%Y-%m-%d %H:%M:%S.%f')&lt;BR /&gt;logging.debug("Saving checkpoint=%s (checkpoint_rfc3339=%s) to file=%s", checkpoint, checkpoint_rfc3339, chk_file)&lt;/P&gt;&lt;P&gt;f = open(chk_file_new, "w")&lt;BR /&gt;f.write("%s" % checkpoint_rfc3339)&lt;BR /&gt;f.close()&lt;BR /&gt;os.rename(chk_file_new, chk_file)&lt;/P&gt;&lt;P&gt;def load_checkpoint(config):&lt;BR /&gt;checkpoint_file = "checkpoint-" + config["name"]&lt;BR /&gt;checkpoint_file = re.sub('[\\/\s]', '', checkpoint_file)&lt;BR /&gt;chk_file = os.path.join(config["checkpoint_dir"], checkpoint_file)&lt;BR /&gt;#chk_file = os.path.join(config["checkpoint_dir"], "checkpoint")&lt;BR /&gt;# try to open this file&lt;BR /&gt;try:&lt;BR /&gt;f = open(chk_file, "r")&lt;BR /&gt;checkpoint_rfc3339=f.readline().split("\n")[0]&lt;BR /&gt;logging.info("Read checkpoint_rfc3339=%s from file=%s", checkpoint_rfc3339, chk_file)&lt;BR /&gt;checkpoint = datetime.strptime(checkpoint_rfc3339, '%Y-%m-%d %H:%M:%S.%f')&lt;BR /&gt;f.close()&lt;BR /&gt;except:&lt;BR /&gt;# assume that this means the checkpoint is not there (Use 2000/1/1)&lt;BR /&gt;checkpoint_rfc3339='2000-01-01 00:00:00.000000'&lt;BR /&gt;checkpoint = datetime.strptime(checkpoint_rfc3339, '%Y-%m-%d %H:%M:%S.%f')&lt;BR /&gt;logging.error("Failed to read checkpoint from file=%s using checkpoint_rfc3339=%s", chk_file, checkpoint_rfc3339)&lt;/P&gt;&lt;P&gt;logging.debug("Checkpoint value is: checkpoint=%s", checkpoint)&lt;/P&gt;&lt;P&gt;return checkpoint&lt;/P&gt;&lt;P&gt;# Routine to index data&lt;BR /&gt;def run():&lt;BR /&gt;config = get_config()&lt;BR /&gt;mongodb_uri = config["mongodb_uri"]&lt;/P&gt;&lt;P&gt;checkpoint = load_checkpoint(config)&lt;/P&gt;&lt;P&gt;client = MongoClient(mongodb_uri)&lt;BR /&gt;database = client["tyk_analytics"]&lt;BR /&gt;collection = database["tyk_analytics"]&lt;/P&gt;&lt;P&gt;cursor = collection.find({'timestamp': {'$gt': checkpoint} })&lt;/P&gt;&lt;P&gt;sys.stdout.write("&amp;lt;stream&amp;gt;")&lt;BR /&gt;#logging.info("H: Before Document")&lt;BR /&gt;for document in cursor:&lt;BR /&gt;#logging.info("After1 Before Document")&lt;BR /&gt;new_checkpoint=document['timestamp']&lt;BR /&gt;#logging.info("After2 Before Document")&lt;BR /&gt;#document['timestamp'] is in GMT, so we can do a straight epoc conversion, and not be concerned with timezones&lt;BR /&gt;epoc_timestamp = (new_checkpoint - datetime(1970,1,1,0,0,0,0)).total_seconds()&lt;BR /&gt;#logging.debug("Calculated epoc_timestamp=%s, from ['timestamp']=%s", str(epoc_timestamp), checkpoint)&lt;/P&gt;&lt;P&gt;outputdata={}&lt;BR /&gt;outputdata['timestamp'] = six.text_type(document['timestamp'])&lt;BR /&gt;outputdata['apiname'] = document['apiname']&lt;BR /&gt;outputdata['ipaddress'] = document['ipaddress']&lt;BR /&gt;outputdata['id'] = six.text_type(document['_id'])&lt;BR /&gt;outputdata['requesttime'] = str(document['requesttime'])&lt;BR /&gt;outputdata['responsecode'] = str(document['responsecode'])&lt;BR /&gt;outputdata['method'] = document['method']&lt;BR /&gt;outputdata['path'] = document['path']&lt;/P&gt;&lt;P&gt;request=base64.b64decode(document['rawrequest'])&lt;BR /&gt;try:&lt;BR /&gt;request.decode('utf-8')&lt;BR /&gt;#print "string is UTF-8, length %d bytes" % len(request)&lt;BR /&gt;except UnicodeError:&lt;BR /&gt;request = "(SPLUNK SCRIPTED INPUT ERROR) input is not UTF-8 unicode"&lt;/P&gt;&lt;P&gt;m = re.search('(?s)^(.+)\r\n\r\n(.*)', request.decode('utf-8'))&lt;BR /&gt;if m:&lt;BR /&gt;#Strip any Authorization header&lt;BR /&gt;outputdata['requestheader']=re.sub('\nAuthorization: [^\n]+','',m.group(1))&lt;BR /&gt;outputdata['requestbody']=m.group(2)&lt;BR /&gt;else:&lt;BR /&gt;outputdata['request'] = request&lt;/P&gt;&lt;P&gt;response=base64.b64decode(document['rawresponse'])&lt;BR /&gt;try:&lt;BR /&gt;response.decode('utf-8')&lt;BR /&gt;#print "string is UTF-8, length %d bytes" % len(response)&lt;BR /&gt;except UnicodeError:&lt;BR /&gt;response = "(SPLUNK SCRIPTED INPUT ERROR) input is not UTF-8 unicode"&lt;/P&gt;&lt;P&gt;if response != "":&lt;BR /&gt;m = re.search('(?s)^(.+)\r\n\r\n(.*)', response.decode('utf-8'))&lt;BR /&gt;if m:&lt;BR /&gt;outputdata['responseheader']=m.group(1)&lt;BR /&gt;outputdata['responsebody']=m.group(2)&lt;BR /&gt;else:&lt;BR /&gt;outputdata['response'] = response.decode('utf-8')&lt;BR /&gt;&lt;BR /&gt;sys.stdout.write("&amp;lt;event&amp;gt;")&lt;BR /&gt;sys.stdout.write("&amp;lt;time&amp;gt;")&lt;BR /&gt;sys.stdout.write(str(epoc_timestamp))&lt;BR /&gt;sys.stdout.write("&amp;lt;/time&amp;gt;")&lt;BR /&gt;sys.stdout.write("&amp;lt;data&amp;gt;")&lt;BR /&gt;logging.info("Before Json dumps")&lt;BR /&gt;sys.stdout.write(xml.sax.saxutils.escape(json.dumps(outputdata)))&lt;BR /&gt;logging.info("After1 Json dumps")&lt;BR /&gt;sys.stdout.write("&amp;lt;/data&amp;gt;&amp;lt;done/&amp;gt;&amp;lt;/event&amp;gt;\n")&lt;/P&gt;&lt;P&gt;if new_checkpoint &amp;gt; checkpoint:&lt;BR /&gt;checkpoint_delta = (new_checkpoint - checkpoint).total_seconds()&lt;BR /&gt;checkpoint=new_checkpoint&lt;BR /&gt;if checkpoint_delta &amp;gt; 60:&lt;BR /&gt;save_checkpoint(config, checkpoint)&lt;BR /&gt;#End for block&lt;/P&gt;&lt;P&gt;save_checkpoint(config, checkpoint)&lt;BR /&gt;sys.stdout.write("&amp;lt;/stream&amp;gt;")&lt;BR /&gt;sys.stdout.flush()&lt;/P&gt;&lt;P&gt;# Script must implement these args: scheme, validate-arguments&lt;BR /&gt;if __name__ == '__main__':&lt;BR /&gt;if len(sys.argv) &amp;gt; 1:&lt;BR /&gt;if sys.argv[1] == "--scheme":&lt;BR /&gt;do_scheme()&lt;BR /&gt;elif sys.argv[1] == "--validate-arguments":&lt;BR /&gt;validate_arguments()&lt;BR /&gt;else:&lt;BR /&gt;pass&lt;BR /&gt;else:&lt;BR /&gt;run()&lt;/P&gt;&lt;P&gt;sys.exit(0)&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 09:32:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690196#M28270</guid>
      <dc:creator>VijaySrrie</dc:creator>
      <dc:date>2024-06-10T09:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: Duplicate logs via modular input</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690197#M28271</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/80737"&gt;@inventsekar&lt;/a&gt;&amp;nbsp;&amp;nbsp;- This is the python code we use to pull the loigs&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 09:25:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/Duplicate-logs-via-modular-input/m-p/690197#M28271</guid>
      <dc:creator>VijaySrrie</dc:creator>
      <dc:date>2024-06-10T09:25:46Z</dc:date>
    </item>
  </channel>
</rss>

