Skip to content

Commit

Permalink
Improvements after feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Stringer committed Apr 19, 2017
1 parent 6c39365 commit cb5df86
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 37 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup, find_packages
import sys

VERSION = "0.3.2"
VERSION = "0.3.3"
PACKAGE_NAME = "hpilo-exporter"
SOURCE_DIR_NAME = "src"

Expand Down
13 changes: 5 additions & 8 deletions src/hpilo_exporter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@

def main():
# Add some args config
parser = argparse.ArgumentParser(
description='Exports ilo heath_at_a_glance state to prometheus')
parser.add_argument('--address', dest='address',
help='address to serve on')
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', dest='ilo_host', help='iLO hostname/ip')
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', dest='ilo_user', help='iLO user')
parser.add_argument(
'--ilo-password', dest='ilo_password', help='iLO password')
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')
args = parser.parse_args()

# Run exposing server
Expand Down
37 changes: 15 additions & 22 deletions src/hpilo_exporter/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,31 @@ def do_GET(self):

if url.path == '/metrics':

query_ilo_host = query_components.get(
'ilo_host', self.server.ilo_host)
query_ilo_host = query_components.get('ilo_host', [self.server.ilo_host])
if query_ilo_host:
ilo_host = ''.join(map(str, query_ilo_host))
ilo_host = query_ilo_host[0]

query_ilo_port = query_components.get(
'ilo_port', self.server.ilo_port)
query_ilo_port = query_components.get('ilo_port', [self.server.ilo_port])
if query_ilo_port:
ilo_port = ''.join(map(str, query_ilo_port))
ilo_port = int(query_ilo_port[0])

query_ilo_user = query_components.get(
'ilo_user', self.server.ilo_user)
query_ilo_user = query_components.get('ilo_user', [self.server.ilo_user])
if query_ilo_user:
ilo_user = ''.join(map(str, query_ilo_user))
ilo_user = query_ilo_user[0]

query_ilo_password = query_components.get(
'ilo_password', self.server.ilo_password)
query_ilo_password = query_components.get('ilo_password', [self.server.ilo_password])
if query_ilo_password:
ilo_password = ''.join(map(str, query_ilo_password))
ilo_password = query_ilo_password[0]

data = {}
try:
data = hpilo.Ilo(hostname=ilo_host, login=ilo_user, password=ilo_password, timeout=10, port=int(
ilo_port)).get_embedded_health()['health_at_a_glance']
data = hpilo.Ilo(hostname=ilo_host, login=ilo_user, password=ilo_password,
port=ilo_port, timeout=10).get_embedded_health()['health_at_a_glance']

for key, value in data.items():
for status in value.items():
if status[0] == 'status':
gauge = 'hpilo_' + key + '_gauge'
gauge = 'hpilo_{}_gauge'.format(key)

if status[1] == 'OK':
prometheus_metrics.gauges[gauge].set(0)
Expand Down Expand Up @@ -114,7 +110,7 @@ class iLOExporterServer(object):

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

Expand All @@ -127,17 +123,14 @@ def __init__(self, address=None, port=None, ilo_host=None, ilo_port=None, ilo_us
self._ilo_password = ilo_password or self.DEFAULT_ILO_PASSWORD

def print_info(self):
print("Starting exporter on: http://%s:%s/metrics" %
(self._address, self._port))
print("Default iLO: %s@%s:%s" %
(self._ilo_user, self._ilo_host, self._ilo_port))
print("Starting exporter on: http://{}:{}/metrics".format(self._address, self._port))
print("Default iLO: {}@{}:{}".format(self._ilo_user, self._ilo_host, self._ilo_port))
print("Press Ctrl+C to quit")

def run(self):
self.print_info()

server = ForkingHTTPServer(
(self._address, int(self._port)), RequestHandler)
server = ForkingHTTPServer((self._address, self._port), RequestHandler)

server.ilo_host = self._ilo_host
server.ilo_port = self._ilo_port
Expand Down
9 changes: 3 additions & 6 deletions src/hpilo_exporter/prometheus_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
hpilo_battery_gauge = Gauge('hpilo_battery', 'HP iLO battery status')
hpilo_storage_gauge = Gauge('hpilo_storage', 'HP iLO storage status')
hpilo_fans_gauge = Gauge('hpilo_fans', 'HP iLO fans status')
hpilo_bios_hardware_gauge = Gauge(
'hpilo_bios_hardware', 'HP iLO bios_hardware status')
hpilo_bios_hardware_gauge = Gauge('hpilo_bios_hardware', 'HP iLO bios_hardware status')
hpilo_memory_gauge = Gauge('hpilo_memory', 'HP iLO memory status')
hpilo_power_supplies_gauge = Gauge(
'hpilo_power_supplies', 'HP iLO power_supplies status')
hpilo_power_supplies_gauge = Gauge('hpilo_power_supplies', 'HP iLO power_supplies status')
hpilo_processor_gauge = Gauge('hpilo_processor', 'HP iLO processor status')
hpilo_network_gauge = Gauge('hpilo_network', 'HP iLO network status')
hpilo_temperature_gauge = Gauge(
'hpilo_temperature', 'HP iLO temperature status')
hpilo_temperature_gauge = Gauge('hpilo_temperature', 'HP iLO temperature status')

gauges = {
'hpilo_battery_gauge': hpilo_battery_gauge,
Expand Down

0 comments on commit cb5df86

Please sign in to comment.