Skip to content

Commit a33a19e

Browse files
author
Davide Schiera
authored
Merge pull request #9 from draios/teams-api
Teams functionality for the Python wrapper
2 parents cd3bb18 + 8072aa3 commit a33a19e

File tree

11 files changed

+1280
-51
lines changed

11 files changed

+1280
-51
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ script:
1111
- examples/dashboard.py XXX
1212
- examples/create_dashboard.py XXX
1313
- examples/delete_dashboard.py XXX
14-
- examples/get_data_advanced.py XXX ip-10-0-2-180.ec2.internal
14+
- examples/get_data_advanced.py XXX ip-10-0-1-213.ec2.internal
1515
- examples/get_data_datasource.py XXX
1616
- examples/get_data_simple.py XXX
1717
- examples/list_alerts.py XXX
@@ -28,8 +28,9 @@ script:
2828
- examples/print_explore_grouping.py XXX
2929
- examples/print_user_info.py XXX
3030
- examples/list_sysdig_captures.py XXX
31-
- examples/create_sysdig_capture.py XXX ip-10-0-1-110.ec2.internal apicapture 10
31+
- examples/create_sysdig_capture.py XXX ip-10-0-1-213.ec2.internal apicapture 10
3232
- examples/notification_channels.py XXX
33+
- examples/user_team_mgmt.py XXX example-team [email protected]
3334
- echo "Testing pip version"
3435
- rm -rf sdcclient
3536
- pip install sdcclient

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ Every method in the SdcClient class returns **a list with two entries**. The fir
5151
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)
5252

5353
Function List
54-
-------
54+
-------------
5555

56-
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.
56+
Please Refer to the [Python Script Library documentation page](http://python-sdc-client.readthedocs.io/en/latest/) for the list of functions available.

doc/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SPHINXPROJ = python-sdc-client
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
21+

doc/conf.py

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# python-sdc-client documentation build configuration file, created by
4+
# sphinx-quickstart on Thu Dec 22 11:59:02 2016.
5+
#
6+
# This file is execfile()d with the current directory set to its
7+
# containing dir.
8+
#
9+
# Note that not all possible configuration values are present in this
10+
# autogenerated file.
11+
#
12+
# All configuration values have a default; values that are commented out
13+
# serve to show the default.
14+
15+
# If extensions (or modules to document with autodoc) are in another directory,
16+
# add these directories to sys.path here. If the directory is relative to the
17+
# documentation root, use os.path.abspath to make it absolute, like shown here.
18+
#
19+
import os
20+
import sys
21+
sys.path.insert(0, os.path.abspath('..'))
22+
23+
24+
# -- General configuration ------------------------------------------------
25+
26+
# If your documentation needs a minimal Sphinx version, state it here.
27+
#
28+
# needs_sphinx = '1.0'
29+
30+
# Add any Sphinx extension module names here, as strings. They can be
31+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32+
# ones.
33+
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.linkcode' ]
34+
35+
# Add any paths that contain templates here, relative to this directory.
36+
templates_path = ['_templates']
37+
38+
# The suffix(es) of source filenames.
39+
# You can specify multiple suffix as a list of string:
40+
#
41+
# source_suffix = ['.rst', '.md']
42+
source_suffix = '.rst'
43+
44+
# The master toctree document.
45+
master_doc = 'index'
46+
47+
# General information about the project.
48+
project = u'python-sdc-client'
49+
copyright = u'2016, Sysdig Inc.'
50+
author = u'Sysdig Inc.'
51+
52+
# The version info for the project you're documenting, acts as replacement for
53+
# |version| and |release|, also used in various other places throughout the
54+
# built documents.
55+
#
56+
# The short X.Y version.
57+
version = u''
58+
# The full version, including alpha/beta/rc tags.
59+
release = u''
60+
61+
# The language for content autogenerated by Sphinx. Refer to documentation
62+
# for a list of supported languages.
63+
#
64+
# This is also used if you do content translation via gettext catalogs.
65+
# Usually you set "language" from the command line for these cases.
66+
language = None
67+
68+
# List of patterns, relative to source directory, that match files and
69+
# directories to ignore when looking for source files.
70+
# This patterns also effect to html_static_path and html_extra_path
71+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
72+
73+
# The name of the Pygments (syntax highlighting) style to use.
74+
pygments_style = 'sphinx'
75+
76+
# If true, `todo` and `todoList` produce output, else they produce nothing.
77+
todo_include_todos = False
78+
79+
80+
# -- Options for HTML output ----------------------------------------------
81+
82+
# The theme to use for HTML and HTML Help pages. See the documentation for
83+
# a list of builtin themes.
84+
#
85+
html_theme = 'classic'
86+
87+
# Theme options are theme-specific and customize the look and feel of a theme
88+
# further. For a list of options available for each theme, see the
89+
# documentation.
90+
#
91+
# html_theme_options = {}
92+
93+
# Add any paths that contain custom static files (such as style sheets) here,
94+
# relative to this directory. They are copied after the builtin static files,
95+
# so a file named "default.css" will overwrite the builtin "default.css".
96+
html_static_path = ['_static']
97+
98+
99+
# -- Options for HTMLHelp output ------------------------------------------
100+
101+
# Output file base name for HTML help builder.
102+
htmlhelp_basename = 'python-sdc-clientdoc'
103+
104+
105+
# -- Options for LaTeX output ---------------------------------------------
106+
107+
latex_elements = {
108+
# The paper size ('letterpaper' or 'a4paper').
109+
#
110+
# 'papersize': 'letterpaper',
111+
112+
# The font size ('10pt', '11pt' or '12pt').
113+
#
114+
# 'pointsize': '10pt',
115+
116+
# Additional stuff for the LaTeX preamble.
117+
#
118+
# 'preamble': '',
119+
120+
# Latex figure (float) alignment
121+
#
122+
# 'figure_align': 'htbp',
123+
}
124+
125+
# Grouping the document tree into LaTeX files. List of tuples
126+
# (source start file, target name, title,
127+
# author, documentclass [howto, manual, or own class]).
128+
latex_documents = [
129+
(master_doc, 'python-sdc-client.tex', u'python-sdc-client Documentation',
130+
u'Sysdig Inc.', 'manual'),
131+
]
132+
133+
134+
# -- Options for manual page output ---------------------------------------
135+
136+
# One entry per manual page. List of tuples
137+
# (source start file, name, description, authors, manual section).
138+
man_pages = [
139+
(master_doc, 'python-sdc-client', u'python-sdc-client Documentation',
140+
[author], 1)
141+
]
142+
143+
144+
# -- Options for Texinfo output -------------------------------------------
145+
146+
# Grouping the document tree into Texinfo files. List of tuples
147+
# (source start file, target name, title, author,
148+
# dir menu entry, description, category)
149+
texinfo_documents = [
150+
(master_doc, 'python-sdc-client', u'python-sdc-client Documentation',
151+
author, 'python-sdc-client', 'One line description of project.',
152+
'Miscellaneous'),
153+
]
154+
155+
156+
def linkcode_resolve(domain, info):
157+
def find_line():
158+
obj = sys.modules[info['module']]
159+
for part in info['fullname'].split('.'):
160+
obj = getattr(obj, part)
161+
import inspect
162+
fn = inspect.getsourcefile(obj)
163+
source, lineno = inspect.findsource(obj)
164+
return lineno + 1
165+
166+
if domain != 'py' or not info['module']:
167+
return None
168+
#tag = 'master' if 'dev' in release else ('v' + release)
169+
url = "https://github.com/draios/python-sdc-client/blob/master/sdcclient/_client.py"
170+
try:
171+
return url + '#L%d' % find_line()
172+
except Exception:
173+
return url

doc/index.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. python-sdc-client documentation master file, created by
2+
sphinx-quickstart on Thu Dec 22 11:59:02 2016.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Sysdig Cloud Python Script Library
7+
==================================
8+
9+
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/>`_.
10+
11+
* :ref:`genindex`
12+
* :ref:`search`
13+
14+
15+
16+
Function List
17+
=============
18+
.. py:module:: sdcclient
19+
.. autoclass:: SdcClient
20+
:members:
21+
:undoc-members:

doc/make.bat

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
set SPHINXPROJ=python-sdc-client
13+
14+
if "%1" == "" goto help
15+
16+
%SPHINXBUILD% >NUL 2>NUL
17+
if errorlevel 9009 (
18+
echo.
19+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
20+
echo.installed, then set the SPHINXBUILD environment variable to point
21+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
22+
echo.may add the Sphinx directory to PATH.
23+
echo.
24+
echo.If you don't have Sphinx installed, grab it from
25+
echo.http://sphinx-doc.org/
26+
exit /b 1
27+
)
28+
29+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
30+
goto end
31+
32+
:help
33+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
34+
35+
:end
36+
popd

examples/download_dashboards.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python
2+
#
3+
# Save/restore dashboards
4+
#
5+
6+
import os
7+
import sys
8+
import zipfile
9+
import json
10+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
11+
from sdcclient import SdcClient
12+
13+
def zipdir(path, ziph):
14+
# ziph is zipfile handle
15+
for root, dirs, files in os.walk(path):
16+
for file in files:
17+
ziph.write(os.path.join(root, file))
18+
19+
def cleanup_dir(path):
20+
if os.path.exists(path) == False:
21+
return
22+
if os.path.isdir(path) == False:
23+
print 'Provided path is not a directory'
24+
sys.exit(-1)
25+
26+
for file in os.listdir(path):
27+
file_path = os.path.join(path, file)
28+
try:
29+
if os.path.isfile(file_path):
30+
os.unlink(file_path)
31+
else:
32+
print 'Cannot clean the provided directory due to delete failure on %s' % file_path
33+
except Exception as e:
34+
print(e)
35+
os.rmdir(path)
36+
37+
#
38+
# Parse arguments
39+
#
40+
if len(sys.argv) != 3:
41+
print 'usage: %s <sysdig-token> <file-name>' % sys.argv[0]
42+
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
43+
sys.exit(1)
44+
45+
sdc_token = sys.argv[1]
46+
dashboard_state_file = sys.argv[2]
47+
sysdig_dashboard_dir = 'sysdig-dashboard-dir'
48+
49+
#
50+
# Instantiate the SDC client
51+
#
52+
sdclient = SdcClient(sdc_token, sdc_url='https://app-staging.sysdigcloud.com')
53+
54+
#
55+
# Fire the request.
56+
#
57+
res = sdclient.get_dashboards()
58+
59+
#
60+
# Show the list of dashboards
61+
#
62+
if res[0]:
63+
data = res[1]
64+
else:
65+
print res[1]
66+
sys.exit(1)
67+
68+
69+
# Clean up any state in the tmp directory
70+
cleanup_dir(sysdig_dashboard_dir)
71+
72+
# Creating sysdig dashboard directory to store dashboards
73+
if not os.path.exists(sysdig_dashboard_dir):
74+
os.makedirs(sysdig_dashboard_dir)
75+
76+
77+
for db in data['dashboards']:
78+
file_path = os.path.join(sysdig_dashboard_dir, str(db['id']))
79+
f = open(file_path, 'w')
80+
f.write(json.dumps(db))
81+
print "Name: %s, # Charts: %d" % (db['name'], len(db['items']))
82+
83+
84+
zipf = zipfile.ZipFile(dashboard_state_file, 'w', zipfile.ZIP_DEFLATED)
85+
zipdir(sysdig_dashboard_dir, zipf)
86+
zipf.close()
87+
88+
# Clean up any state in the directory
89+
cleanup_dir(sysdig_dashboard_dir)

0 commit comments

Comments
 (0)