Skip to content

Commit

Permalink
Basic handling of poller registration
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mortimer committed Sep 28, 2016
1 parent b2dc741 commit b99d6e7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
22 changes: 19 additions & 3 deletions controller/app/mod_pollers/controllers.py
@@ -1,10 +1,26 @@
#!/usr/bin/env python3

from flask import Blueprint, render_template
from flask import Blueprint, render_template, jsonify, request
from libs.pollers import Poller

mod_pollers = Blueprint('pollers', __name__, url_prefix='/pollers')

pollers = []


@mod_pollers.route('/', methods=['GET'])
def home():
return render_template('pollers/pollers.html')
def get_pollers():
return render_template('pollers/pollers.html', pollers=pollers)


@mod_pollers.route('/register', methods=['POST'])
def register():
if not request.json:
print('hit')
return render_template('pollers/pollers.html', pollers=pollers)

poller = Poller(request.json['ip'],
request.json['port'],
request.json['name'])
pollers.append(poller)
return jsonify({'status': 'poller created'}), 201
4 changes: 2 additions & 2 deletions controller/app/templates/navigation.html
Expand Up @@ -119,8 +119,8 @@ <h5 class="media-heading"><strong>John Smith</strong>
<li {%- if request.path == url_for('tasks.get_tasks') %} class="active" {% endif %}>
<a href="{{ url_for('tasks.get_tasks') }}"><i class="fa fa-fw fa-bar-chart-o"></i> Tasks</a>
</li>
<li {%- if request.path == url_for('pollers.home') %} class="active" {% endif %}>
<a href="{{ url_for('pollers.home') }}"><i class="fa fa-fw fa-bar-chart-o"></i> Pollers</a>
<li {%- if request.path == url_for('pollers.get_pollers') %} class="active" {% endif %}>
<a href="{{ url_for('pollers.get_pollers') }}"><i class="fa fa-fw fa-bar-chart-o"></i> Pollers</a>
</li>
<li {%- if request.path == url_for('configuration.home') %} class="active" {% endif %}>
<a href="{{ url_for('configuration.home') }}"><i class="fa fa-fw fa-bar-chart-o"></i> Configuration</a>
Expand Down
14 changes: 10 additions & 4 deletions controller/app/templates/pollers/pollers.html
Expand Up @@ -15,16 +15,22 @@ <h2>All Pollers</h2>
<th>Port</th>
<th>Status</th>
<th>Online since</th>
<th>Last healthpoll</th>
<th>Last keepalive</th>
</tr>
{% for poller in pollers %}
<tr>
<td>{{ poller.name }}</td>
<td>{{ poller.ip }}</td>
<td>{{ poller.port }}</td>
<td></td>
<td></td>
<td></td>
<td>
{% if poller.online %}
<span class="label label-success">Online</span>
{% else %}
<span class="label label-danger">Offline</span>
{% endif %}
</td>
<td>{{ poller.online_since }}</td>
<td>{{ poller.last_keepalive }}</td>
</tr>
{% else %}
<tr><td colspan=6>No pollers found</td></tr>
Expand Down
7 changes: 6 additions & 1 deletion controller/libs/pollers.py
@@ -1,5 +1,8 @@
#!/usr/bin/env python3

from time import time


class Poller:
"""A single poller connection"""

Expand All @@ -12,4 +15,6 @@ def __init__(self, ip, port, name=None):
"""
self.ip = ip
self.port = port
self.port = name
self.name = name
self.online_since = time()
self.last_keepalive = None

0 comments on commit b99d6e7

Please sign in to comment.