Skip to content

Commit

Permalink
Merge pull request #9 from draios/teams-api
Browse files Browse the repository at this point in the history
Teams functionality for the Python wrapper
  • Loading branch information
davideschiera authored Jan 4, 2017
2 parents cd3bb18 + 8072aa3 commit a33a19e
Show file tree
Hide file tree
Showing 11 changed files with 1,280 additions and 51 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ script:
- examples/dashboard.py XXX
- examples/create_dashboard.py XXX
- examples/delete_dashboard.py XXX
- examples/get_data_advanced.py XXX ip-10-0-2-180.ec2.internal
- examples/get_data_advanced.py XXX ip-10-0-1-213.ec2.internal
- examples/get_data_datasource.py XXX
- examples/get_data_simple.py XXX
- examples/list_alerts.py XXX
Expand All @@ -28,8 +28,9 @@ script:
- examples/print_explore_grouping.py XXX
- examples/print_user_info.py XXX
- examples/list_sysdig_captures.py XXX
- examples/create_sysdig_capture.py XXX ip-10-0-1-110.ec2.internal apicapture 10
- examples/create_sysdig_capture.py XXX ip-10-0-1-213.ec2.internal apicapture 10
- examples/notification_channels.py XXX
- examples/user_team_mgmt.py XXX example-team [email protected]
- echo "Testing pip version"
- rm -rf sdcclient
- pip install sdcclient
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ Every method in the SdcClient class returns **a list with two entries**. The fir
For an example on how to parse this output, take a look at a simple example like [get_data_simple.py](examples/get_data_simple.py)

Function List
-------
-------------

Please Refer to the [Python Script Library documentation page](https://sysdig.gitbooks.io/sysdig-cloud-api/content/python/function_list.html) for the list of functions available.
Please Refer to the [Python Script Library documentation page](http://python-sdc-client.readthedocs.io/en/latest/) for the list of functions available.
21 changes: 21 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = python-sdc-client
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

173 changes: 173 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# -*- coding: utf-8 -*-
#
# python-sdc-client documentation build configuration file, created by
# sphinx-quickstart on Thu Dec 22 11:59:02 2016.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.linkcode' ]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'python-sdc-client'
copyright = u'2016, Sysdig Inc.'
author = u'Sysdig Inc.'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u''
# The full version, including alpha/beta/rc tags.
release = u''

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'classic'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'python-sdc-clientdoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'python-sdc-client.tex', u'python-sdc-client Documentation',
u'Sysdig Inc.', 'manual'),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'python-sdc-client', u'python-sdc-client Documentation',
[author], 1)
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'python-sdc-client', u'python-sdc-client Documentation',
author, 'python-sdc-client', 'One line description of project.',
'Miscellaneous'),
]


def linkcode_resolve(domain, info):
def find_line():
obj = sys.modules[info['module']]
for part in info['fullname'].split('.'):
obj = getattr(obj, part)
import inspect
fn = inspect.getsourcefile(obj)
source, lineno = inspect.findsource(obj)
return lineno + 1

if domain != 'py' or not info['module']:
return None
#tag = 'master' if 'dev' in release else ('v' + release)
url = "https://github.com/draios/python-sdc-client/blob/master/sdcclient/_client.py"
try:
return url + '#L%d' % find_line()
except Exception:
return url
21 changes: 21 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. python-sdc-client documentation master file, created by
sphinx-quickstart on Thu Dec 22 11:59:02 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Sysdig Cloud Python Script Library
==================================

This page documents the functions available in the `Python Script Library <https://sysdig.gitbooks.io/sysdig-cloud-api/content/python.html>`_ for `Sysdig Cloud <https://sysdig.com/>`_. It is is a wrapper around the `Sysdig Cloud API <https://sysdig.gitbooks.io/sysdig-cloud-api/content/>`_.

* :ref:`genindex`
* :ref:`search`



Function List
=============
.. py:module:: sdcclient
.. autoclass:: SdcClient
:members:
:undoc-members:
36 changes: 36 additions & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
set SPHINXPROJ=python-sdc-client

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%

:end
popd
89 changes: 89 additions & 0 deletions examples/download_dashboards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python
#
# Save/restore dashboards
#

import os
import sys
import zipfile
import json
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
from sdcclient import SdcClient

def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))

def cleanup_dir(path):
if os.path.exists(path) == False:
return
if os.path.isdir(path) == False:
print 'Provided path is not a directory'
sys.exit(-1)

for file in os.listdir(path):
file_path = os.path.join(path, file)
try:
if os.path.isfile(file_path):
os.unlink(file_path)
else:
print 'Cannot clean the provided directory due to delete failure on %s' % file_path
except Exception as e:
print(e)
os.rmdir(path)

#
# Parse arguments
#
if len(sys.argv) != 3:
print 'usage: %s <sysdig-token> <file-name>' % sys.argv[0]
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
sys.exit(1)

sdc_token = sys.argv[1]
dashboard_state_file = sys.argv[2]
sysdig_dashboard_dir = 'sysdig-dashboard-dir'

#
# Instantiate the SDC client
#
sdclient = SdcClient(sdc_token, sdc_url='https://app-staging.sysdigcloud.com')

#
# Fire the request.
#
res = sdclient.get_dashboards()

#
# Show the list of dashboards
#
if res[0]:
data = res[1]
else:
print res[1]
sys.exit(1)


# Clean up any state in the tmp directory
cleanup_dir(sysdig_dashboard_dir)

# Creating sysdig dashboard directory to store dashboards
if not os.path.exists(sysdig_dashboard_dir):
os.makedirs(sysdig_dashboard_dir)


for db in data['dashboards']:
file_path = os.path.join(sysdig_dashboard_dir, str(db['id']))
f = open(file_path, 'w')
f.write(json.dumps(db))
print "Name: %s, # Charts: %d" % (db['name'], len(db['items']))


zipf = zipfile.ZipFile(dashboard_state_file, 'w', zipfile.ZIP_DEFLATED)
zipdir(sysdig_dashboard_dir, zipf)
zipf.close()

# Clean up any state in the directory
cleanup_dir(sysdig_dashboard_dir)
Loading

0 comments on commit a33a19e

Please sign in to comment.