Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
palisadian committed Jan 8, 2020
1 parent 3ce3a3c commit 5b00e3a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 17 deletions.
20 changes: 12 additions & 8 deletions pattoo_web/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"""Pattoo classes that manage various configurations."""

# Import project libraries
from pattoo_shared import configuration, files
from pattoo_shared.configuration import search
from pattoo_shared import files
from pattoo_shared.configuration import search, agent_config_filename
from pattoo_shared.configuration import Config as _Config
from pattoo_web.constants import PATTOO_WEBD_NAME


class Config(object):
class Config(_Config):
"""Class gathers all configuration information.
Only processes the following YAML keys in the configuration file:
Expand All @@ -26,10 +27,12 @@ def __init__(self):
None
"""
# Instantiate inheritance
_Config.__init__(self)

# Get the configuration directory
config_file = configuration.agent_config_filename(
PATTOO_WEBD_NAME)
self._configuration = files.read_yaml_file(config_file)
config_file = agent_config_filename(PATTOO_WEBD_NAME)
self._daemon_configuration = files.read_yaml_file(config_file)

def ip_listen_address(self):
"""Get ip_listen_address.
Expand All @@ -44,7 +47,7 @@ def ip_listen_address(self):
# Get result
key = PATTOO_WEBD_NAME
sub_key = 'ip_listen_address'
result = search(key, sub_key, self._configuration, die=False)
result = search(key, sub_key, self._daemon_configuration, die=False)

# Default to 0.0.0.0
if result is None:
Expand All @@ -66,7 +69,8 @@ def ip_bind_port(self):
sub_key = 'ip_bind_port'

# Get result
intermediate = search(key, sub_key, self._configuration, die=False)
intermediate = search(
key, sub_key, self._daemon_configuration, die=False)
if intermediate is None:
result = 20200
else:
Expand Down
6 changes: 3 additions & 3 deletions pattoo_web/web/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def route_data():

# Process the data
if points.valid is True:
# Initialize key variables
# Render data from database
table = home.table(points)
return render_template('home.html', main_table=table)

# Otherwise abort
abort(404)
# No database
return render_template('no-api.html')


@PATTOO_WEB_HOME.route('/status')
Expand Down
25 changes: 21 additions & 4 deletions pattoo_web/web/query/datapoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
"""Pattoo classes that manage GraphQL datapoint related queries."""

import sys
from pattoo_shared import log
from pattoo_web.phttp import get


Expand Down Expand Up @@ -50,10 +52,15 @@ def __init__(self, data):
"""
# Initialize the class
self._nodes = []

# Check for validity
if bool(data) is True:
self._nodes = data['data']['allDatapoints']['edges']
else:
self._nodes = []
try:
self._nodes = data['data']['allDatapoints']['edges']
except:
log_message = ('Invalid datapoint data to process.')
log.log2warning(80012, log_message)
self.valid = bool(self._nodes)

def datapoints(self):
Expand Down Expand Up @@ -333,6 +340,16 @@ def datapoint(graphql_id):
'''.replace('IDENTIFIER', graphql_id)

# Get data from API server
data = get(query)
data = None

# Get data from remote system
try:
data = get(query)
except:
_exception = sys.exc_info()
log_message = ('Cannot connect to pattoo web API')
log.log2exception(80013, _exception, message=log_message)

# Return
result = DataPoint(data)
return result
4 changes: 2 additions & 2 deletions pattoo_web/web/theme/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
{% block body %}

<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800">Available DataPoints</h1>
<h1 class="h3 mb-4 text-gray-800">Pattoo Home</h1>

<!-- Table -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">DataTables Example</h6>
<h6 class="m-0 font-weight-bold text-primary">Available Datapoints</h6>
</div>
<div class="card-body">
<div class="table-responsive">
Expand Down
24 changes: 24 additions & 0 deletions pattoo_web/web/theme/templates/no-api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends 'base.html' %}
{% block body %}

<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800">Available DataPoints</h1>

<!-- Table -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Error</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<p>General error. Please follow these and other troubleshooting steps.</p>
<ul>
<li>Cannot connect to pattoo API server. Check whether the pattoo_apid daemon is running. Check network connectivity.</li>
<li>Pattoo API server database is empty. Please start pattoo_ingesterd on the pattoo server.</li>
</ul>
</div>
</div>
</div>


{% endblock %}

0 comments on commit 5b00e3a

Please sign in to comment.