Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes needed for Splunk 8.1 compatibility #1

Open
orion84 opened this issue Oct 22, 2020 · 2 comments
Open

Some changes needed for Splunk 8.1 compatibility #1

orion84 opened this issue Oct 22, 2020 · 2 comments

Comments

@orion84
Copy link

orion84 commented Oct 22, 2020

Recently started using this TA. Thanks for building it!

Today I upgraded my Splunk instance to 8.1 and after that the modular input failed (I guess due to switch to python 3?). I ran it through the Splunk Platform Upgrade Readiness app (https://splunkbase.splunk.com/app/4698/), which recommended below changes.

After applying those and additionally also removing the import md5 (since that also threw an error and didn't seem to be used), the modular input is now working again.

@@ -1,3 +1,4 @@
+from __future__ import print_function
 import sys
 import xml.dom.minidom, xml.sax.saxutils
 import json
@@ -7,6 +8,7 @@
 import requests
 import base64
 import app_config
+from io import open
 
 SCHEME = """<scheme>
     <title>Netatmo</title>
@@ -42,7 +44,7 @@
 #</arg>
 
 def do_scheme():
-    print SCHEME
+    print(SCHEME)
 
 
 def validate_arguments():
@@ -107,7 +109,7 @@
         response.raise_for_status()
         data = response.json()["body"]["devices"][0]
     except requests.exceptions.HTTPError as error:
-        print(error.response.status_code, error.response.text)
+        print((error.response.status_code, error.response.text))
 
     print(json.dumps(data, sort_keys=True))
@@ -148,7 +150,7 @@
             config["checkpoint_dir"] = checkpnt_node.firstChild.data
 
         if not config:
-            raise Exception, "Invalid configuration received from Splunk."
+            raise Exception("Invalid configuration received from Splunk.")
 
         # just some validation: make sure these keys are present (required)
         validate_conf(config, "client_id")
@@ -157,8 +159,8 @@
         validate_conf(config, "code")
         validate_conf(config, "checkpoint_dir")
 
-    except Exception, e:
-        raise Exception, "Error getting Splunk configuration via STDIN: %s" % str(e)
+    except Exception as e:
+        raise Exception("Error getting Splunk configuration via STDIN: %s" % str(e))
 
     return config

PS: I also found a fairly neat way of working with the json data that this TA ingests (which contains datapoints from multiple sensors in 1 event). I created a saved search that takes the json data, extracts the datapoints of the various modules to separate rows and stores it in a metrics index using mcollect. If you're interested I'm happy to share that, but not sure how I can best do that here?

@dominiquevocat
Copy link

@orion84 care to share your searches?

@orion84
Copy link
Author

orion84 commented Mar 17, 2022

@dominiquevocat the search I use to collect the raw data into a metrics index:

index=netatmo
| eval modules = mvappend("Main",'modules{}.module_name')
| spath output=metrics path=dashboard_data 
| spath output=module_metrics path=modules{}.dashboard_data
| eval module_metrics = mvzip(modules,mvappend(metrics,module_metrics))
| table _time,module_metrics
| mvexpand module_metrics
| rex field=module_metrics "(?<module>[^,]+),(?<metrics>.+)"
| spath input=metrics
| fields _time,module,AbsolutePressure,Pressure,CO2,Humidity,Noise,Temperature
| mcollect index=netatmo_metrics split=t module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants