Splunk Custom Module - python

I am new in Splunk - as well as in Python and start working on Splunk Custom Module and I have taken reference from Splunk Site Custom Module. When I have created Same file structure using Visual Studio 2017 -> Python3 then its give me an error
import controllers.module not found
import splunk not found
import splunk.search not found
import splunk.util not found
import splunk.entity not found
import json from splunk.appserver.mrsparkle.lib not found
import lib.util as util not found
Note: I have already imported Splunk SDK using "pip install splunk-sdk" Still, I can't find any package in the project.
Please, anyone, guide me how to resolve above custom module package error.
If there is any readymade samples are available then please suggest a link.
Thanks in advance

You may be wasting your time. Splunk Modules have been deprecated for over a year and may become unsupported at any time.
The packages you are looking for should be part of Splunk. Have you installed it?
I believe Splunk does not support Python 3. Try 2.7.

Have you tried taking a look to simple_xml_exaples app for sourcecodeviewer implementation. I think it is a good approach for adding custom HTML + CCS + third party.js.
Furthermore it can be implemented in a custom dashboard.js
edit
Download Simple xml examples APP; in every example dashboard it can be seen that it has a custom component called sourceviewer, that is injected after the load time in every dashboard page.
For that a custom
dashboard.js
is created and inserted in APP/appserver/static so this will override the original
so then you can insert in every dashboard page the new needed components without even afecting the dashboard xml part and its functionalities as pdf generator.
I used that way in order to implement custom Nav as a SideBar.

Related

Is it possible to load a Google Ads custom report via API into production DB

Looking through the API documentation it seems that there's currently no way to access a custom report via the API. If this is, in fact, the case, is there a workaround to make this possible?
The goal is to get a modified version of this report shown on the web interface:
No, you need to build the report yourself and call it with the API unfortunately.
Depending on how complex the report is, it can be done pretty quickly. You can quickly generate the GAQL needed for your APU query using this tool: https://developers.google.com/google-ads/api/fields/v7/overview_query_builder
This will save you typing out all the resources manually, and will even validate it for you.
If you're stuck, let us know what report you're trying to generate and we can help with the GAQL.

How can I extend CKAN API?

I would like to ask how can I extend CKAN's API by writing my own extension for CKAN. I could not find anything in the documentation.
Could you give some simple example please?
In the OP's defence, the documentation does seem to be a bit opaque. I've been looking at this in an attempt to get a custom API action for supplying JSON news feed to work, and finally came up with this:
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
# Required so that GET requests work
#toolkit.side_effect_free
def get_news(context,data_dict=None):
# The actual custom API method
return {"hello":"world"}
class CustomAPIPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.interfaces.IActions)
def get_actions(self):
# Registers the custom API method defined above
return {'get_news': get_news}
The tutorial which describes creating an authentication plugin is here:
http://docs.ckan.org/en/latest/extensions/tutorial.html#creating-a-new-extension
What I've done is to plagiarise that, but using IActions rather than IAuthFunctions:
http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html
It's working on an installation of CKAN 2.2.1.

GAE Import of OAuth failing

I am trying to set up my first ever API connection with Yelp, I am using GAE on Python. To do so, I used the following example: https://github.com/Yelp/yelp-api/blob/master/v2/python/search.py
At first I simply try to run the code by the following definition in my app.yaml
handlers:
- url: /search
script: search.py
However when I load the page it gives the following error: No module named oauth2. I have read through many of the topics that seem to cover this error but none really helped in resolving it. I also tried importing oauth2client which was mentioned in some answers however this was also not accepted.
The only thing that was accepted by the system was
from google.appengine.api import oauth
Therefore I tried to work with this module, but immediately ran into another problem. I filled out my credentials (consumer_key, consumer_secret, token, token_secret) by defining them as default value in the parser definition. To replicate the examples request on https://github.com/Yelp/yelp-api/tree/master/v2/python I also added a default value for 'term' (bars) and 'location' (sf).
When loading the page with this it however gives me the error 'module' object has no attribute 'Consumer', so this also doesn't seem to be the solution. As said this is my first time setting up such a system, so probably I am missing something obvious. Thanks a lot for your thoughts.
You cannot replace modules just like that, the script you are referring to works with the oauth2 library, which is different from GAE OAuth API (that's why you were getting the 'module' object has no attribute 'Consumer').
As explained in the README of the yelp-api, first you need to install the oauth2 module. Note that you need to copy the installed module (or source) to your GAE project in order to upload it to GAE when deploying.

How can I update a plone page via a script?

I have a large amount of automatically generated html files that I would like to push to my Plone website with a script. I currently generate the files, log into Plone, click edit on each individual page and copy and paste the html into the editor. I'd like to automate this. It would be nice to retain the plone versioning, have a auto generated comment for the edit, and come from a specific user.
I've read and tried Webdav with little luck at getting it working consistently and know that there is a way to connect to plone via ftp, but haven't tried it. I'm not sure if these are the methods that I need.
My google searches aren't leading me to anything useful. Any ideas on where to start looking for a solution to this? Or any tips on implementing it?
You can script anything in Plone via the following methods:
Through-the-web via API calls (e.g. XML-RPC, wsapi, etc.)
The bin/instance run script provided by plone.recipe.zope2instance (See charm for an example of this).
You can also use a migration framework like:
collective.transmogrifier
which allows you to write migration code, and trigger it via GenericSetup or Browser view. Additionally, there are applications written on top of Transmogrifier aimed roughly at what you are describing, the most popular of which is:
funnelweb
I would recommend that you consider using or writing a Transmogrifier "blueprint(s)" to do your import, and execute the pipeline with a tool that makes that easy:
mr.migrator
You can find blueprints by searching PyPI for "transmogrify". One popular set of blueprints is:
quintagroup.transmogrifier
One of the main attractions to the Transmogrifier approach, aside from getting the job done, is the ability to share useful blueprints with others.
I think transmogrifier is the best tool for this job, but this will definitely be a programming task no matter how you do it. It's used for many such migration jobs such as migrating from drupal.
There's an add-on, wsapi4plone.core that pumazi at WebLion started that provides web services for portals which you can then hook into. You can create, modify, delete content via XML-RPC calls. The only caveat is that it doesn't yet work with Collections (criteria specifically).
project: http://pypi.python.org/pypi/wsapi4plone.core
docs: http://packages.python.org/wsapi4plone.core/
You can also do it programmatically by hooking into the ZODB via Python (zopepy or some other method).
These should get you started:
http://plone.org/documentation/kb/manipulating-plone-objects-programmatically/reading-and-writing-field-values - you should be able to get an understanding of accessors and mutators (setters and getters), in your case you are going to be more than likely working with obj.Text (getter) and obj.setText (setter).
https://weblion.psu.edu/trac/weblion/wiki/AutomatingObjectCreation - lots of examples (slightly outdated but still relevant)
http://plone.org/documentation/faq/upload-images-files
Try to enable Webdav or ftp in Plone, then you can access Plone via webdav or ftp clients, pushing the html files. Plone (Zope) will recognises the html files as Pages.

Noob Question: Python + Twitter + App Engine - Oauth

I'm sorry but I'm having some trouble implementing Oauth within my app engine python project.
I've been working from http://github.com/tav/tweetapp, but I don't think I have a strong enough grasp on this platform to understand how to implement this class within my main.py I'm building the rest of my app in.
This maybe a feeble attempt, but here is what I have so far:
twa = twitter_auth
client = twa.OAuthClient('twitter')
I've created a source folder within my project called "twitter_auth" and that contains a file within it called "twitter_auth.py" which contains the above linked library, and a file called __ init__.py (no space) which is completely empty.
I really have no idea what to do from here :/
Let me recommend taking a look at the tweepy library and some example tweepy apps. Specifically here: http://github.com/wasauce/tweepy-examples
This shows how to use oauth to authenticate a user: http://github.com/wasauce/tweepy-examples/tree/master/appengine/oauth_example/
As Hagge said, it sounds like your issue is more with the tweetapp library than with App Engine. However, if you would like to know more about OAuth on App Engine and if I may be allowed to link to myself, my two articles on the topic seem to be reasonably popular.
The tweetapp library was a an early prototype for Twitter OAuth on twitter. Tav did the heavy lifting and I deployed the site http://twitteroauth.appspot.com , using some of the tweetapp library. The actual source of that site is here (I need to update the site to point here): http://github.com/ryanwi/twitteroauth
I am still using it in production, but, it has aged and does not work for all API calls. I'd recommend trying a different, more up to date and maintained library as others have mentioned.
But, take a look at the twitteroauth source if you want to try to get a first attempt working.
These two are on Twitter's list
http://github.com/brosner/python-oauth2
http://code.google.com/p/oauth-python-twitter2/
I'm not familiar with that library, but after a quick look and seeing the warning that it is not maintained I'd search for something better. I implemented a simple Twitter connection based on Tornado's auth: see an example of how to make Twitter API calls here (and an authentication example here). In case you don't want to use tipfy, I recommend implementing the python-twitter library in your framework of choice.

Categories