Skip to content

Commit

Permalink
Simplifying the defaults and tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Stringer committed Apr 20, 2017
1 parent cb5df86 commit 47f870c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
18 changes: 9 additions & 9 deletions src/hpilo_exporter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@


def main():
# Add some args config
parser = argparse.ArgumentParser(description='Exports ilo heath_at_a_glance state to prometheus')
parser.add_argument('--address', type=str, dest='address', help='address to serve on')
parser.add_argument('--port', type=int, dest='port', help='port to bind')
parser.add_argument('--ilo-host', type=str, dest='ilo_host', help='iLO hostname/ip')
parser.add_argument('--ilo-port', type=int, dest='ilo_port', help='iLO port')
parser.add_argument('--ilo-user', type=str, dest='ilo_user', help='iLO user')
parser.add_argument('--ilo-password', type=str, dest='ilo_password', help='iLO password')
parser = argparse.ArgumentParser(description='Exports ilo heath_at_a_glance state to Prometheus')

parser.add_argument('--address', type=str, dest='address', default='0.0.0.0', help='address to serve on')
parser.add_argument('--port', type=int, dest='port', default='8080', help='port to bind')
parser.add_argument('--ilo-host', type=str, dest='ilo_host', default='127.0.0.1', help='iLO hostname/ip')
parser.add_argument('--ilo-port', type=int, dest='ilo_port', default='443', help='iLO port')
parser.add_argument('--ilo-user', type=str, dest='ilo_user', default='user', help='iLO user')
parser.add_argument('--ilo-password', type=str, dest='ilo_password', default='pass', help='iLO password')

args = parser.parse_args()

# Run exposing server
exposer = iLOExporterServer(**vars(args))
exposer.run()
28 changes: 8 additions & 20 deletions src/hpilo_exporter/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import hpilo
import prometheus_metrics
import sys
import traceback

from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer
Expand Down Expand Up @@ -80,7 +79,6 @@ def do_GET(self):
except:
self.send_response(500)
self.end_headers()
self.wfile.write(traceback.format_exc())

elif url.path == '/':
self.send_response(200)
Expand All @@ -101,26 +99,16 @@ def do_GET(self):

class iLOExporterServer(object):
"""
Basic server implementation that exposes metrics to Prometheus fetcher.
Basic server implementation that exposes metrics to Prometheus
"""

# server config
DEFAULT_HOST = "0.0.0.0"
DEFAULT_PORT = 8080

# exporter config
DEFAULT_ILO_HOST = "127.0.0.1"
DEFAULT_ILO_PORT = 443
DEFAULT_ILO_USER = "user"
DEFAULT_ILO_PASSWORD = "pass"

def __init__(self, address=None, port=None, ilo_host=None, ilo_port=None, ilo_user=None, ilo_password=None):
self._address = address or self.DEFAULT_HOST
self._port = port or self.DEFAULT_PORT
self._ilo_host = ilo_host or self.DEFAULT_ILO_HOST
self._ilo_port = ilo_port or self.DEFAULT_ILO_PORT
self._ilo_user = ilo_user or self.DEFAULT_ILO_USER
self._ilo_password = ilo_password or self.DEFAULT_ILO_PASSWORD
def __init__(self, address, port, ilo_host, ilo_port, ilo_user, ilo_password):
self._address = address
self._port = port
self._ilo_host = ilo_host
self._ilo_port = ilo_port
self._ilo_user = ilo_user
self._ilo_password = ilo_password

def print_info(self):
print("Starting exporter on: http://{}:{}/metrics".format(self._address, self._port))
Expand Down

0 comments on commit 47f870c

Please sign in to comment.