Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

host&port support read from config-file #125

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rrd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def get_locale():
def get_timezone():
return app.config.get("BABEL_DEFAULT_TIMEZONE")

def start():
app.run(host=app.config.get("PORTAL_HOST", "0.0.0.0"), port=app.config.get("PORTAL_PORT", 8081), debug=False)

from view import index
from view.auth import auth
from view.user import user
Expand Down
2 changes: 2 additions & 0 deletions rrd/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
SECRET_KEY = os.environ.get("SECRET_KEY","secret-key")
PERMANENT_SESSION_LIFETIME = os.environ.get("PERMANENT_SESSION_LIFETIME",3600 * 24 * 30)
SITE_COOKIE = os.environ.get("SITE_COOKIE","open-falcon-ck")
PORTAL_HOST = os.environ.get("PORTAL_HOST","127.0.0.1")
PORTAL_PORT = os.environ.get("PORTAL_PORT",8081)

# Falcon+ API
API_ADDR = os.environ.get("API_ADDR","http://127.0.0.1:18080/api/v1")
Expand Down
6 changes: 3 additions & 3 deletions rrd/model/portal/bean.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def select(cls, cols=None, where=None, params=None, order=None, limit=None, page
@classmethod
def select_vs(cls, where=None, params=None, order=None, limit=None, page=None, offset=None):
rows = cls.select(where=where, params=params, order=order, limit=limit, page=page, offset=offset)
return [cls(*row) for row in rows]
return [cls(*row) for row in rows] if rows is not None else None

@classmethod
def read(cls, where=None, params=None):
Expand All @@ -123,7 +123,7 @@ def get(cls, id_val):
@classmethod
def column(cls, col=None, where=None, params=None, order=None, limit=None, page=None, offset=None):
rows = cls.select(col, where, params, order, limit, page, offset)
return [row[0] for row in rows]
return [row[0] for row in rows] if rows is not None else None

@classmethod
def total(cls, where=None, params=None):
Expand All @@ -134,7 +134,7 @@ def total(cls, where=None, params=None):

sql += ' WHERE ' + where
ret = cls._db.query_column(sql, params)
return ret[0]
return ret[0] if ret and len(ret) > 0 else None

@classmethod
def exists(cls, where=None, params=None):
Expand Down
4 changes: 4 additions & 0 deletions rrd/static/js/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ function batch_add_host() {
}, "json");
}

function goto_url(url) {
window.location = url;
}

function host_unbind_group(host_id, group_id) {
$.getJSON('/portal/host/unbind', {'host_id': host_id, 'group_id': group_id}, function (json) {
handle_quietly(json, function () {
Expand Down
15 changes: 8 additions & 7 deletions rrd/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def __init__(self, cfg):
self.config = cfg
self.conn = None

def get_conn(self):
if self.conn is None:
def get_conn(self, reset=False):
if self.conn is None or reset:
self.conn = connect_db(self.config)
return self.conn

Expand All @@ -67,9 +67,10 @@ def execute(self, *a, **kw):
cursor.execute(*a, **kw)
except (AttributeError, MySQLdb.OperationalError):
self.conn and self.conn.close()
self.conn = None
cursor = self.get_conn().cursor()
cursor.execute(*a, **kw)
self.conn = self.get_conn(True)
if self.conn:
cursor = self.conn.cursor()
cursor.execute(*a, **kw)
return cursor

# insert one record in a transaction
Expand All @@ -78,7 +79,7 @@ def insert(self, *a, **kw):
cursor = None
try:
cursor = self.execute(*a, **kw)
row_id = cursor.lastrowid
row_id = cursor.lastrowid if cursor else None
self.commit()
return row_id
except MySQLdb.IntegrityError:
Expand All @@ -104,7 +105,7 @@ def query_all(self, *a, **kw):
cursor = None
try:
cursor = self.execute(*a, **kw)
return cursor.fetchall()
return cursor.fetchall() if cursor else None
finally:
cursor and cursor.close()

Expand Down
72 changes: 38 additions & 34 deletions rrd/templates/portal/alarm/case.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,51 @@ <h4 class="panel-title">{{_('alerting cases')}}
</div>
<div class="panel-body">
<div class="alarms">
{%for case in cases%}
<div class="alarm">
<input type="checkbox" alarm="{{case.id}}">
{{case.status}} P{{case.priority}}
[第<span class="orange">#{{case.current_step}}</span>次/最大{{case.max_step}}次]
<span class="orange">{{case.timestamp|time_duration}}</span>
<span class="gray">[</span>
<a href="/portal/template/view/{{case.template_id}}" target="_blank">template</a>
{% if cases is not none %}
{%for case in cases%}
<div class="alarm">
<input type="checkbox" alarm="{{case.id}}">
{{case.status}} P{{case.priority}}
[第<span class="orange">#{{case.current_step}}</span>次/最大{{case.max_step}}次]
<span class="orange">{{case.timestamp|time_duration}}</span>
<span class="gray">[</span>
<a href="/portal/template/view/{{case.template_id}}" target="_blank">template</a>

{%if case.strategy_id>0%}
<span class="cut-line">¦</span>
<a href="/portal/strategy/{{case.strategy_id}}" target="_blank">strategy</a>
{%endif%}
{%if case.strategy_id>0%}
<span class="cut-line">¦</span>
<a href="/portal/strategy/{{case.strategy_id}}" target="_blank">strategy</a>
{%endif%}

{%if case.expression_id>0%}
<span class="cut-line">¦</span>
<a href="/portal/expression/view/{{case.expression_id}}" target="_blank">expression</a>
{%endif%}
{%if case.expression_id>0%}
<span class="cut-line">¦</span>
<a href="/portal/expression/view/{{case.expression_id}}" target="_blank">expression</a>
{%endif%}

<span class="cut-line">¦</span>
<a href="javascript:alarm_case_rm('{{case.id}}');">delete</a>
<span class="cut-line">¦</span>
<a href="/portal/alarm-dash/case/event?case_id={{case.id}}">{{_('event list')}}</a>
<span class="gray">]</span>
</br>
<span class="cut-line">¦</span>
<a href="javascript:alarm_case_rm('{{case.id}}');">delete</a>
<span class="cut-line">¦</span>
<a href="/portal/alarm-dash/case/event?case_id={{case.id}}">{{_('event list')}}</a>
<span class="gray">]</span>
</br>

<span style="padding-left:17px;"> {{case.endpoint}}
<span class="cut-line">¦</span>
{{case.metric}}
<span class="cut-line">¦</span>
{{case.func}}
<span class="cut-line">¦</span>
{{case.cond}}</span>
<span class="cut-line">¦</span>
<span class="gray">note: {{case.note}}</span>
</div>
<hr>
{%endfor%}
<span style="padding-left:17px;"> {{case.endpoint}}
<span class="cut-line">¦</span>
{{case.metric}}
<span class="cut-line">¦</span>
{{case.func}}
<span class="cut-line">¦</span>
{{case.cond}}</span>
<span class="cut-line">¦</span>
<span class="gray">note: {{case.note}}</span>
</div>
<hr>
{%endfor%}
<a href="javascript:alarm_case_all_select();">{{_('select all')}}</a>/
<a href="javascript:alarm_case_reverse_select();">{{_('reverse select')}}</a>
<button class="btn btn-warning btn-sm" onclick="alarm_case_batch_rm();">{{_('batch delete')}}</button>
{% else %}
list fail, view logs for more.
{% endif %}
</div>
</div>

Expand Down
63 changes: 34 additions & 29 deletions rrd/templates/portal/expression/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,46 @@
</div>

<div>
{% set left = '{' %}
{% set right = '}' %}
{% for v in data.vs %}
{% if data.vs is not none %}
{% set left = '{' %}
{% set right = '}' %}
{% for v in data.vs %}

<hr>
<hr>

<div class="">{{ v.expression }}</div>
<div class="mt10">
<span class="gray">if {{ v.func }}{{ v.op }}{{ v.right_value }}
{{ left }}{{ v.action.html()|safe }}{{ right }}</span>
<div class="">{{ v.expression }}</div>
<div class="mt10">
<span class="gray">if {{ v.func }}{{ v.op }}{{ v.right_value }}
{{ left }}{{ v.action.html()|safe }}{{ right }}</span>

{% if v.writable(g.user) %}
<div class="pull-right">
<button onclick="pause_expression('{{v.id}}')" class="btn btn-default">
<span id="i-{{v.id}}" class="glyphicon glyphicon-{% if v.pause %}play{% else %}pause{% endif %} orange"></span>
</button>
<a href="{{ url_for('expression_add_get', id=v.id) }}" class="btn btn-default"
style="text-decoration: none;">
<span class="glyphicon glyphicon-edit orange"></span>
</a>
<button onclick="delete_expression('{{ v.id }}');" class="btn btn-default">
<span class="glyphicon glyphicon-trash orange"></span>
</button>
</div>
{% endif %}
</div>
<div class="mt10 gray">
note: {{ v.note }} (Max:{{ v.max_step }}, P{{ v.priority }})
by {{ v.create_user }}
</div>
{% if v.writable(g.user) %}
<div class="pull-right">
<button onclick="pause_expression('{{v.id}}')" class="btn btn-default">
<span id="i-{{v.id}}" class="glyphicon glyphicon-{% if v.pause %}play{% else %}pause{% endif %} orange"></span>
</button>
<a href="{{ url_for('expression_add_get', id=v.id) }}" class="btn btn-default"
style="text-decoration: none;">
<span class="glyphicon glyphicon-edit orange"></span>
</a>
<button onclick="delete_expression('{{ v.id }}');" class="btn btn-default">
<span class="glyphicon glyphicon-trash orange"></span>
</button>
</div>
{% endif %}
</div>
<div class="mt10 gray">
note: {{ v.note }} (Max:{{ v.max_step }}, P{{ v.priority }})
by {{ v.create_user }}
</div>

{% else %}
<hr>
no records
{% endfor %}
{% else %}
<hr>
no records
{% endfor %}
list fail, view logs for more.
{% endif %}
</div>

{% import "portal/blocks.html" as blocks %}
Expand Down
54 changes: 30 additions & 24 deletions rrd/templates/portal/group/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,39 @@
</tr>
</thead>
<tbody>
{% for v in data.vs %}
<tr>
<td>{{ v.grp_name }}</td>
<td>{{ v.create_user }}</td>
<td>
<a href="{{ url_for('group_templates_get', grp_id=v.id) }}">templates</a>
<span class="cut-line">¦</span>
<a href="{{ url_for('group_hosts_list', group_id=v.id) }}">hosts</a>
<span class="cut-line">¦</span>
<a href="{{ url_for('plugin_list_get', group_id=v.id) }}">plugins</a>
<span class="cut-line">¦</span>
<a href="{{ url_for('cluster_list_get', group_id=v.id) }}">aggregator</a>
{% if v.writable(g.user) %}
{% if data.vs is not none %}
{% for v in data.vs %}
<tr>
<td>{{ v.grp_name }}</td>
<td>{{ v.create_user }}</td>
<td>
<a href="{{ url_for('group_templates_get', grp_id=v.id) }}">templates</a>
<span class="cut-line">¦</span>
<a href="javascript:edit_hostgroup('{{ v.id }}', '{{ v.grp_name }}');" style="text-decoration: none;">
<span class="glyphicon glyphicon-edit orange"></span>
</a>
<a href="{{ url_for('group_hosts_list', group_id=v.id) }}">hosts</a>
<span class="cut-line">¦</span>
<a href="javascript:delete_hostgroup('{{ v.id }}');" style="text-decoration: none;">
<span class="glyphicon glyphicon-trash orange"></span>
</a>
{% endif %}
</td>
</tr>
<a href="{{ url_for('plugin_list_get', group_id=v.id) }}">plugins</a>
<span class="cut-line">¦</span>
<a href="{{ url_for('cluster_list_get', group_id=v.id) }}">aggregator</a>
{% if v.writable(g.user) %}
<span class="cut-line">¦</span>
<a href="javascript:edit_hostgroup('{{ v.id }}', '{{ v.grp_name }}');" style="text-decoration: none;">
<span class="glyphicon glyphicon-edit orange"></span>
</a>
<span class="cut-line">¦</span>
<a href="javascript:delete_hostgroup('{{ v.id }}');" style="text-decoration: none;">
<span class="glyphicon glyphicon-trash orange"></span>
</a>
{% endif %}
</td>
</tr>
{% else %}
<tr><td colspan="3">no records</td></tr>
{% endfor %}
{% else %}
<tr><td colspan="3">no records</td></tr>
{% endfor %}
<tr>
<td colspan="4">list fail, view logs for more.</td>
</tr>
{% endif %}
</tbody>
</table>
{% import "portal/blocks.html" as blocks %}
Expand Down
2 changes: 1 addition & 1 deletion rrd/templates/portal/host/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<span class="glyphicon glyphicon-plus"></span>
Add Host
</button>
<button class="btn btn-default" onclick="history.go(-1);">
<button class="btn btn-default" onclick="goto_url('{{ url_for('group_hosts_list', group_id=group.id) }}');">
<span class="glyphicon glyphicon-arrow-left"></span>
Back
</button>
Expand Down
49 changes: 27 additions & 22 deletions rrd/templates/portal/nodata/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,35 @@

</div>
<div>
{% for v in data.vs %}
<hr/>
<div>{{ v.name }}; {{ v.obj_type }} [{{ v.obj }}]/{{ v.metric }}/{{ v.tags }};&nbsptype={{ v.dstype }},step={{ v.step }}</div>
<div class="mt10 gray">
<span class="gray">默认值: {{ v.mock }}</span>
{% if v.writable(g.user) %}
<div class="pull-right">
<a href="{{ url_for('nodata_add_get', id=v.id) }}" class="btn btn-default"
style="text-decoration: none;">
<span class="glyphicon glyphicon-edit orange"></span>
</a>
<button onclick="delete_nodata('{{ v.id }}');" class="btn btn-default">
<span class="glyphicon glyphicon-trash orange"></span>
</button>
</div>
{% endif %}
</div>
<div class="mt10 gray">
<p> 创建人: {{ v.creator }}, 最后更改时间: {{ v.t_modify }}</p>
</div>
{% if data.vs is not none %}
{% for v in data.vs %}
<hr/>
<div>{{ v.name }}; {{ v.obj_type }} [{{ v.obj }}]/{{ v.metric }}/{{ v.tags }};&nbsptype={{ v.dstype }},step={{ v.step }}</div>
<div class="mt10 gray">
<span class="gray">默认值: {{ v.mock }}</span>
{% if v.writable(g.user) %}
<div class="pull-right">
<a href="{{ url_for('nodata_add_get', id=v.id) }}" class="btn btn-default"
style="text-decoration: none;">
<span class="glyphicon glyphicon-edit orange"></span>
</a>
<button onclick="delete_nodata('{{ v.id }}');" class="btn btn-default">
<span class="glyphicon glyphicon-trash orange"></span>
</button>
</div>
{% endif %}
</div>
<div class="mt10 gray">
<p> 创建人: {{ v.creator }}, 最后更改时间: {{ v.t_modify }}</p>
</div>
{% else %}
<hr/>
no records
{% endfor %}
{% else %}
<hr/>
no records
{% endfor %}
list fail, view logs for more.
{% endif %}
</div>

{% import "portal/blocks.html" as blocks %}
Expand Down
Loading