Skip to content

Commit

Permalink
v1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidaho12 committed Jun 16, 2024
1 parent f6811f6 commit 0a33a0d
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 18 deletions.
7 changes: 2 additions & 5 deletions app/modules/db/smon.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,11 @@ def add_sec_to_state_time(time, smon_id):
out_error(e)


def insert_smon_history(smon_id: int, resp_time: float, status: int, check_id: int, mes='') -> datetime:
get_date = roxy_wi_tools.GetDate()
cur_date = get_date.return_date('regular')
def insert_smon_history(smon_id: int, resp_time: float, status: int, check_id: int, mes: str, now_utc: datetime):
try:
SmonHistory.insert(smon_id=smon_id, response_time=resp_time, status=status, date=cur_date, check_id=check_id, mes=mes).execute()
SmonHistory.insert(smon_id=smon_id, response_time=resp_time, status=status, date=now_utc, check_id=check_id, mes=mes).execute()
except Exception as e:
out_error(e)
return cur_date


def insert_smon_history_http_metrics(date, **kwargs) -> None:
Expand Down
2 changes: 1 addition & 1 deletion app/modules/tools/smon.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def change_smon_port(new_port: int) -> None:
server_mod.subprocess_execute(cmd)


def get_ssl_expire_date(date: int) -> int:
def get_ssl_expire_date(date: str) -> int:
present = common.get_present_time()
ssl_expire_date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
return (ssl_expire_date - present).days
Expand Down
1 change: 0 additions & 1 deletion app/modules/tools/smon_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ def send_http_checks(agent_id: int, server_ip: str) -> None:
json_data['header_req'] = json.dumps(check.headers)
else:
json_data['header_req'] = ''
print(json_data)
api_path = f'check/{check.smon_id}'
try:
send_post_request_to_agent(agent_id, server_ip, api_path, json_data)
Expand Down
8 changes: 6 additions & 2 deletions app/routes/smon/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def get_groups():
groups = smon_sql.select_smon_groups(g.user_params['group_id'])
smon_groups = ''
for group in groups:
smon_groups += f'{group.name}\n'
group_name = group.name.replace("'", "")
smon_groups += f'{group_name}\n'
return smon_groups


Expand Down Expand Up @@ -415,6 +416,7 @@ def smon_history_metric_chart(check_id, check_type_id):
Returns:
- A Flask Response object with the streaming event chart.
"""

def get_chart_data():
"""
Return a generator that continuously yields chart data in JSON format for the specified check ID and check type ID.
Expand All @@ -429,6 +431,7 @@ def get_chart_data():
interval = 120
while True:
json_metric = {}
is_enabled = 1
chart_metrics = smon_sql.select_smon_history(check_id, 1)
uptime = smon_mod.check_uptime(check_id)
smon = smon_sql.select_one_smon(check_id, check_type_id)
Expand All @@ -439,6 +442,7 @@ def get_chart_data():
json_metric['updated_at'] = common.get_time_zoned_date(s.smon_id.updated_at)
json_metric['name'] = str(s.smon_id.name)
interval = s.interval
is_enabled = s.smon_id.en
if s.smon_id.ssl_expire_date is not None:
json_metric['ssl_expire_date'] = smon_mod.get_ssl_expire_date(s.smon_id.ssl_expire_date)
else:
Expand All @@ -454,11 +458,11 @@ def get_chart_data():
for i in chart_metrics:
json_metric['time'] = common.get_time_zoned_date(i.date, '%H:%M:%S')
json_metric['value'] = "{:.3f}".format(i.response_time)
json_metric['status'] = str(i.status)
json_metric['mes'] = str(i.mes)
json_metric['uptime'] = uptime
json_metric['avg_res_time'] = avg_res_time
json_metric['interval'] = interval
json_metric['status'] = str(i.status) if is_enabled else 4
if check_type_id == 2:
json_metric['name_lookup'] = str(i.name_lookup)
json_metric['connect'] = str(i.connect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
name: pip
executable: pip3
state: latest
extra_args: --upgrade
extra_args: --upgrade --ignore-installed

- name: Install RMON Agent python requirements
ansible.builtin.pip:
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/ansible/roles/rmon_agent/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
owner: "{{ansible_user}}"
group: "{{ansible_user}}"
state: directory
with_items: ["/etc/rmon", "/var/lib/rmon", "/var/lib/rmon/rmon-agent", "/var/log/rmon", "/etc/pki/tls/certs"]
with_items: ["/etc/rmon", "/var/lib/rmon/rmon-agent/modules/db", "/var/log/rmon", "/etc/pki/tls/certs"]
ignore_errors: yes

- name: Copy RMON Agent files
Expand All @@ -14,7 +14,7 @@
owner: "{{ansible_user}}"
group: "{{ansible_user}}"
mode: '0644'
with_items: ["rmon_agent.py", "rmon_agent_common.py", "rmon_checks.py", "http_check.py", "wsgi.py", "requirements.txt"]
with_items: ["rmon_agent.py", "rmon_agent_common.py", "rmon_checks.py", "http_check.py", "wsgi.py", "requirements.txt", "modules/db/check_result.py", "modules/db/db_models.py"]

- name: Copy RMON Agent service file
template:
Expand Down
2 changes: 1 addition & 1 deletion app/static/css/style-6.3.9.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pre {
margin-right: 20px;
width: 368px;
float: left;
margin-left: 26%;
margin-left: 30%;
}
.footer-link, .footer-copyright {
color: var(--blue-color);
Expand Down
16 changes: 13 additions & 3 deletions app/static/js/smon.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ function getCheckSettings(smon_id, check_type) {
$('#new-smon-mm').val(data['mm']).change();
$('#new-smon-mm').selectmenu("refresh");
}
if (data['method']) {
$('#new-smon-method').val(data['method']).change();
$('#new-smon-method').selectmenu("refresh");
}
$('#new-smon-agent-id').selectmenu("refresh");
if (data['enabled']) {
$('#new-smon-enable').prop('checked', true)
Expand Down Expand Up @@ -1025,18 +1029,24 @@ function stream_chart(chart_id, check_id, check_type_id) {
}
}
function update_cur_statues(check_id, data) {
if (status == "4") {
return false;
}
let status = data.status;
let last_resp_time = data.value;
let time = data.time;
let mes = data.mes;
let add_class = 'serverUp';
let cur_status = 'UP';
if (status === "0") {
add_class = 'serverDown'
cur_status = 'DOWN'
add_class = 'serverDown';
cur_status = 'DOWN';
} else if (status == "4") {
add_class = 'serverNone';
cur_status = 'DISABLED';
}
if (last_resp_time.length === 0) {
last_resp_time = 'N/A'
last_resp_time = 'N/A';
} else {
last_resp_time = last_resp_time + 'ms'
}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/ajax/smon/smon_dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
{% for group in smon_groups %}
<div class="smon_group">
<div class="group_name">
<span class="smon_group_name">{{ group.name }}</span>
<span class="smon_group_name">{{ group.name.replace("'", "") }}</span>
<span id="show-smon-group-{{ group.id }}" class="plus switcher_table_metric smon_group_switcher" onclick="showSmonGroup('{{ group.id }}')" title="{{lang.words.open|title()}} {{lang.words.group}}"></span>
<span id="hide-smon-group-{{ group.id }}" class="minus switcher_table_metric smon_group_switcher" onclick="hideSmonGroup('{{ group.id }}')" style="display: none;" title="{{lang.words.hide}}"></span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/include/smon/add_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<tr class="smon_http_check">
<td class="padding20">HTTP {{lang.words.method}}</td>
<td>
{% set http_methods = {'get': 'GET', 'post': 'POST', 'put': 'PUT', 'head': 'HEAD'} %}
{% set http_methods = {'get': 'GET', 'post': 'POST', 'put': 'PUT', 'head': 'HEAD', 'patch': 'PATCH', 'delete': 'DELETE', 'options': 'OPTIONS'} %}
{{ select('new-smon-method', values=http_methods, selected='get') }}
</td>
</tr>
Expand Down
14 changes: 14 additions & 0 deletions app/templates/include/smon/smon_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ <h4>{{lang.words.checking|title()}}</h4>
<p class="smon_stats">({{lang.words.type|title()}})</p>
<span class="smon_value" title="{{last_resp_time}}">{{checking_types[check_id|string()]}}</span>
</div>
{% if check_id == 2 %}
<div class="col">
<h4>{{lang.words.method|title()}}</h4>
<p class="smon_stats">HTTP</p>
<span class="smon_value" title="HTTP {{lang.words.method}}">{{s.method.upper()}}</span>
</div>
{% endif %}
{% if check_id == 5 %}
<div class="col">
<h4>Resolver</h4>
<p class="smon_stats">DNS {{ lang.words.server }}</p>
<span class="smon_value" title="DNS {{ lang.words.server }}">{{s.resolver}}</span>
</div>
{% endif %}
<div class="col">
<h4>{{lang.words.response|title()}}</h4>
<p class="smon_stats">({{lang.words.current|title()}})</p>
Expand Down

0 comments on commit 0a33a0d

Please sign in to comment.