Skip to content

Commit

Permalink
Merge pull request #9 from Vaarlion/v3.0-branch
Browse files Browse the repository at this point in the history
V3.0 branch
  • Loading branch information
Vaarlion authored Mar 2, 2021
2 parents 95a2ace + 3e23fc0 commit 904020f
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 59 deletions.
4 changes: 2 additions & 2 deletions pepperboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
60 changes: 30 additions & 30 deletions pepperboard/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import getopt
Expand All @@ -13,15 +13,15 @@


def usage():
print "USAGE: " + sys.argv[0] + " [OPTIONS]"
print "Pepperboard : neat and simple salt dashboards"
print "--help|-h : Prints an awesome help message"
print "--output=|-o : comma separated values of files to write dashboards given with the \"-d\" argument"
print "--dashboards=|-d : comma separated values of dashboards"
print "--threads=|-t : comma separated values of threads count to be used (must be greater than 0). Prefix the number by \"f\" if you want more threads than CPU core count"
print "--grains=|-g : comma separated values of grains to be used with the mgrains dashboard. This argument implies \"-d 'mgrains'\""
print "--dellapikey=|-a : Dell API key used by the dellwarranty dashboard. This argument implies \"-d 'mgrains'\""
print "--list|-l : List available dashboards"
print("USAGE: " + sys.argv[0] + " [OPTIONS]")
print("Pepperboard : neat and simple salt dashboards")
print("--help|-h : Prints an awesome help message")
print("--output=|-o : comma separated values of files to write dashboards given with the \"-d\" argument")
print("--dashboards=|-d : comma separated values of dashboards")
print("--threads=|-t : comma separated values of threads count to be used (must be greater than 0). Prefix the number by \"f\" if you want more threads than CPU core count")
print("--grains=|-g : comma separated values of grains to be used with the mgrains dashboard. This argument implies \"-d 'mgrains'\"")
print("--dellapikey=|-a : Dell API key used by the dellwarranty dashboard. This argument implies \"-d 'mgrains'\"")
print("--list|-l : List available dashboards")


def getmasterstatus():
Expand All @@ -44,25 +44,25 @@ def countminions():

def pepper_main():
if getmasterstatus() == 1:
print "Error : Your Salt Master isn't running. Exiting..."
print("Error : Your Salt Master isn't running. Exiting...")
usage()
sys.exit(2)

if countminions() == 0:
print "Error : You don't have any minions registered to the Salt Master. Exiting..."
print("Error : You don't have any minions registered to the Salt Master. Exiting...")
usage()
sys.exit(2)

if not sys.argv[1:]:
print "Error : Pepperboard wrongly called"
print("Error : Pepperboard wrongly called")
usage()
sys.exit(2)

try:
opts, args = getopt.getopt(sys.argv[1:], 'o:d:t:g:a:lh',
['output=', 'dashboards=', 'threads=', 'grains=', 'dellapikey=', 'list', 'help'])
except getopt.GetoptError as err:
print str(err)
print(str(err))
usage()
sys.exit(2)

Expand All @@ -78,14 +78,14 @@ def pepper_main():
for o, a in opts:
if o in ("-o", "--output"):
if not a:
print "Error : missing output file"
print("Error : missing output file")
usage()
sys.exit(2)
else:
outputs = a.split(',')
elif o in ("-t", "--threads"):
if not a:
print "Error : Missing thread number"
print("Error : Missing thread number")
usage()
sys.exit(2)
else:
Expand All @@ -99,28 +99,28 @@ def pepper_main():
except ImportError:
raise ImportError("You need psutil python module")
if int(th) > cpu_count(logical=True):
print "Error : threads count cannot be greater than CPU core count unless you force it with \"f\" before the number"
print("Error : threads count cannot be greater than CPU core count unless you force it with \"f\" before the number")
sys.exit(2)
elif int(th) == 0:
print "Error : threads count must be greater than 0"
print("Error : threads count must be greater than 0")
usage()
sys.exit(2)
else:
nthreads.append(int(th))
elif o in ("-d", "--dashboards"):
if not a:
print "Error : Missing dashboards list"
print("Error : Missing dashboards list")
usage()
sys.exit(2)
else:
dashs = a.split(',')
for dash in dashs:
if dash not in available_dashboards:
print "Error : Dashboard " + dash + " not available."
print("Error : Dashboard " + dash + " not available.")
sys.exit(2)
elif o in ("-g", "--grains"):
if not a:
print "Error : mgrains argument must be a CSV list"
print("Error : mgrains argument must be a CSV list")
usage()
sys.exit(2)
else:
Expand All @@ -129,44 +129,44 @@ def pepper_main():
grains = a.split(',')
elif o in ("-a", "--dellapikey"):
if not a:
print "Error : dellapikey argument can't be empty"
print("Error : dellapikey argument can't be empty")
usage()
sys.exit(2)
else:
if not "dellwarranty" in dashs:
dashs.append("dellwarranty")
dellapikey = a
elif o in ("-l", "--list"):
print "\n".join(available_dashboards)
print("\n".join(available_dashboards))
elif o in ("-h", "--help"):
usage()
sys.exit(0)
else:
print "Unhandled option"
print("Unhandled option")

if 'mgrains' in dashs and len(grains) == 0:
print "Error : You must the grains list when using the mgrains dashboard"
print("Error : You must the grains list when using the mgrains dashboard")
sys.exit(2)

if 'dellwarranty' in dashs and not dellapikey:
print "Error : You must set the dellapikey when using the dellwarranty dashboard"
print("Error : You must set the dellapikey when using the dellwarranty dashboard")
sys.exit(2)

if len(nthreads) == 0:
if not len(outputs) == len(dashs):
print "Error : All lists aren't the same size"
print("Error : All lists aren't the same size")
sys.exit(2)
else:
for dash, out in zip(dashs, outputs):
if dash == 'mgrains':
pepperboard.dashboards.gendashboard(dash, out, None, grains)
pepperboard.dashboards.gendashboard(dash, out, input=grains)
elif dash == 'dellwarranty':
pepperboard.dashboards.gendashboard(dash, out, None, dellapikey)
pepperboard.dashboards.gendashboard(dash, out, input=dellapikey)
else:
pepperboard.dashboards.gendashboard(dash, out)
else:
if not len(outputs) == len(nthreads) == len(dashs):
print "Error : All lists aren't the same size"
print("Error : All lists aren't the same size")
sys.exit(2)
else:
for dash, out, nth in zip(dashs, outputs, nthreads):
Expand Down
6 changes: 3 additions & 3 deletions pepperboard/dashboards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import importlib
Expand All @@ -14,7 +14,7 @@ def gendashboard(ident, output, nthreads=None, input=None):
elif "gendash" in dir(mod):
mod.gendash(output, nthreads)
else:
print "Error : gendata() or gendash() methods not found in "+mod.__name__
print("Error : gendata() or gendash() methods not found in "+mod.__name__)
sys.exit(2)


Expand All @@ -35,7 +35,7 @@ def gentable(input, output):
for header in input['headers']:
foutput.write('<th>'+header+'</th>')
foutput.write('</tr></thead><tbody>\n')
for k, v in input['data'].iteritems():
for k, v in input['data'].items():
if input['ncol'] == 2:
foutput.write('<tr><td valign=\"top\">'+str(k)+'</td><td>')
if isinstance(v,dict):
Expand Down
2 changes: 1 addition & 1 deletion pepperboard/dashboards/dellwarranty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding:utf-8 -*-


Expand Down
6 changes: 3 additions & 3 deletions pepperboard/dashboards/highstates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding:utf-8 -*-


Expand All @@ -24,7 +24,7 @@ def simhighstate(server):
if server in hst:
minionos = c.cmd(server, 'grains.items')[server]['os'].lower()
if isinstance(hst[server], dict):
for k, v in hst[server].iteritems():
for k, v in hst[server].items():
if not v['result']:
tbc.append("<li>" + v['name'] + "</li>")
processedserver.append(server)
Expand Down Expand Up @@ -60,7 +60,7 @@ def simhighstate(server):
)
foutput.write('<script src=\"//www.kryogenix.org/code/browser/sorttable/sorttable.js\"></script>')
foutput.write('<style>table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after {content: \" \\25B4\\25BE\"}')
for os, logo in core.logos.iteritems():
for os, logo in core.logos.items():
foutput.write('#'+os+'{background:url(data:image/png;base64,'+logo+') left no-repeat;height:20px;width:20px;float:left;padding-right:5px}')
foutput.write('</style>')
foutput.write('<link rel=\"stylesheet\" href=\"//yui-s.yahooapis.com/pure/0.6.0/pure-min.css\">')
Expand Down
18 changes: 10 additions & 8 deletions pepperboard/dashboards/mgrains.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import sys
import concurrent.futures
import salt.client
import salt.runner
import collections
import warnings


def gendata(grains, nthreads):
import sys
import concurrent.futures
import salt.client
import salt.runner
import collections
import warnings

warnings.simplefilter("ignore", DeprecationWarning)
result = {}
toreturn = {}
if nthreads is None:
nthreads = 8
if grains is None:
print "Error : Grains must be specified"
print("Error : Grains must be specified")
sys.exit(2)

def getgrainscontent(grains, server):
Expand Down
6 changes: 3 additions & 3 deletions pepperboard/dashboards/upgrades.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding:utf-8 -*-


Expand Down Expand Up @@ -35,7 +35,7 @@ def checkupdates(server):
len(upd[
server])) + '</a><div class=\"pkglist\" id=\"' + server + '\" style=\"display:none\"><ul>' + ''.join(
['<li>{} : {}</li>'.format(k, v) for k, v in
collections.OrderedDict(sorted(upd[server].items())).iteritems()]) + '</ul></div>'
collections.OrderedDict(sorted(upd[server].items())).items()]) + '</ul></div>'
result[server] = '<tr><td valign=\"top\">' + displogo + server + '</td><td>' + displaypkgs + '</td></tr>\n'
else:
result[server] = '<tr><td valign=\"top\">' + displogo + server + '</td><td>Error during upgrades retrieveing (' + upd[server] + ')</td></tr>\n'
Expand All @@ -55,7 +55,7 @@ def checkupdates(server):
)
foutput.write('<script src=\"//www.kryogenix.org/code/browser/sorttable/sorttable.js\"></script>')
foutput.write('<style>table.sortable th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after {content: \" \\25B4\\25BE\"}')
for os, logo in core.logos.iteritems():
for os, logo in core.logos.items():
foutput.write('#'+os+'{background:url(data:image/png;base64,'+logo+') left no-repeat;height:20px;width:20px;float:left;padding-right:5px}')
foutput.write('</style>')
foutput.write('<link rel=\"stylesheet\" href=\"//yui-s.yahooapis.com/pure/0.6.0/pure-min.css\">')
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
futures>=3
psutil
salt
salt
2 changes: 1 addition & 1 deletion scripts/pepperboard
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from pepperboard import core
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from setuptools import setup
Expand All @@ -8,11 +8,11 @@

setup(
name='pepperboard',
version='2.4',
version='3.0',
packages=['pepperboard', 'pepperboard.core', 'pepperboard.dashboards'],
scripts=['scripts/pepperboard'],
url='https://github.com/webedia-dev/pepperboard',
download_url='https://github.com/webedia-dev/pepperboard/releases/tag/v2.4',
download_url='https://github.com/webedia-dev/pepperboard/releases/tag/v3.0',
license='Apache',
author='Cyril LAVIER',
author_email='cyril.lavier@webedia-group.com',
Expand All @@ -22,9 +22,9 @@
'Development Status :: 5 - Production/Stable',
'Intended Audience :: System Administrators',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'License :: OSI Approved :: Apache Software License',
'Topic :: System :: Monitoring',
],
)
)

0 comments on commit 904020f

Please sign in to comment.