Skip to content

Commit

Permalink
v1.2.2: Change ignore_unreachable to ignore_errors and add region and…
Browse files Browse the repository at this point in the history
… country routes

Updated Ansible task files to use `ignore_errors` instead of `ignore_unreachable` for better error handling. Added new routes and templates to handle region and country details and their respective checks in the monitoring system.
  • Loading branch information
Aidaho12 committed Nov 20, 2024
1 parent caadd76 commit 37c63dd
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 124 deletions.
16 changes: 16 additions & 0 deletions app/modules/db/smon.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,22 @@ def select_checks_for_agent_by_check_type(agent_id: int, check_type: str) -> dic
out_error(e)


def select_checks_for_region_by_check_type(region_id: int, check_type: str) -> dict:
correct_model = tool_common.get_model_for_check(check_type=check_type)
try:
return correct_model.select(correct_model, SMON).join(SMON).where(SMON.region_id == region_id).objects().execute()
except Exception as e:
out_error(e)


def select_checks_for_country_by_check_type(country_id: int, check_type: str) -> dict:
correct_model = tool_common.get_model_for_check(check_type=check_type)
try:
return correct_model.select(correct_model, SMON).join(SMON).where(SMON.country_id == country_id).objects().execute()
except Exception as e:
out_error(e)


def get_smon_group_by_name(group_id: int, name: str) -> int:
try:
return SmonGroup.select().where((SmonGroup.name == name) & (SmonGroup.group_id == group_id)).get().id
Expand Down
1 change: 0 additions & 1 deletion app/modules/roxywi/class_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ class RegionRequest(BaseModel):
shared: Optional[bool] = 0
enabled: Optional[bool] = 1
group_id: Optional[int] = None
country_id: Optional[int] = None
agents: Optional[list[int]] = None


Expand Down
34 changes: 34 additions & 0 deletions app/routes/smon/agent_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,40 @@ def get_agent(agent_id):
return render_template('smon/agent.html', **kwargs)


@bp.get('/region/<int:region_id>')
@jwt_required()
@get_user_params()
def get_region(region_id):
kwargs = {
'region': region_sql.get_region_with_group(region_id, g.user_params['group_id']),
'lang': roxywi_common.get_user_lang_for_flask(),
'smon_status': tools_common.is_tool_active('rmon-server'),
'region_id': region_id
}

for check_type in ('http', 'tcp', 'dns', 'ping', 'smtp', 'rabbitmq'):
kwargs[f'{check_type}_checks'] = smon_sql.select_checks_for_region_by_check_type(region_id, check_type)

return render_template('smon/region.html', **kwargs)


@bp.get('/country/<int:country_id>')
@jwt_required()
@get_user_params()
def get_country(country_id):
kwargs = {
'country': country_sql.get_country_with_group(country_id, g.user_params['group_id']),
'lang': roxywi_common.get_user_lang_for_flask(),
'smon_status': tools_common.is_tool_active('rmon-server'),
'country_id': country_id
}

for check_type in ('http', 'tcp', 'dns', 'ping', 'smtp', 'rabbitmq'):
kwargs[f'{check_type}_checks'] = smon_sql.select_checks_for_country_by_check_type(country_id, check_type)

return render_template('smon/country.html', **kwargs)


@bp.post('/agent/hello')
def agent_get_checks():
json_data = request.json
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/ansible/roles/rmon_agent/tasks/install-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
executable: pip3
state: latest
extra_args: --upgrade --break-system-packages
ignore_unreachable: true
ignore_errors: true

- name: Install RMON Agent python requirements for new Debian
ansible.builtin.pip:
requirements: /var/lib/rmon/rmon-agent/requirements.txt
extra_args: --break-system-packages
ignore_unreachable: true
ignore_errors: true

- name: Upgrade pip3 for old Debian
pip:
name: pip
executable: pip3
state: latest
extra_args: --upgrade
ignore_unreachable: true
ignore_errors: true

- name: Install RMON Agent python requirements for old Debian
ansible.builtin.pip:
requirements: /var/lib/rmon/rmon-agent/requirements.txt
ignore_unreachable: true
ignore_errors: true
2 changes: 1 addition & 1 deletion app/templates/ajax/smon/country.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="server-name">
<span class="overflow" style="width: 192px;">
<span id="country-name-{{country.id}}" style="margin-top: 4px;display: inline-block;">
{{country.name.replace("'","")}}
<a href="/rmon/country/{{ country.id }}" title="{{ lang.words.open|title() }} {{ country.name.replace("'","") }}">{{country.name.replace("'","")}}</a>
</span>
<span id="country-desc-{{country.id}}">{% if country.description %} ({{country.description.replace("'", "")}}) {% endif %}</span>
</span>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/ajax/smon/region.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="server-name">
<span class="overflow" style="width: 192px;">
<span id="region-name-{{region.id}}" style="margin-top: 4px;display: inline-block;">
{{region.name.replace("'","")}}
<a href="/rmon/region/{{ region.id }}" title="{{ lang.words.open|title() }} {{ region.name.replace("'","") }}">{{region.name.replace("'","")}}</a>
</span>
<span id="region-desc-{{region.id}}">{% if region.description %} ({{region.description.replace("'", "")}}) {% endif %}</span>
</span>
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 @@ -43,7 +43,7 @@
{% set down = [] %}
{% set up = [] %}
{% set dis = [] %}
{% for s in smon %}
{% for s in multi_checks %}
{% if s.enabled == 1 %}
{% if s.status == 1 and s.body_status == 1 %}
{% if up.append('1') %} {% endif %}
Expand Down
116 changes: 116 additions & 0 deletions app/templates/include/smon/checks_for_overview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<div class="overview-checks">
<div class="overview-checks-type">
<div class="server-name">{{ lang.words.checks|title() }} {{ lang.words.on }} {{ lang.words.the }} {{ lang.words.agent3 }}</div>
{% if http_checks %}
<div class="overview-check-type">HTTP:</div>
<div class="overview-checks-div">
{% for check in http_checks %}
<div class="overview-check" id="check-{{ check.multi_check_id }}">
<span class="overview-check-name"><b>{{ lang.words.name|title() }}:</b>
<a href="/rmon/dashboard/{{ check.multi_check_id }}/{{ checking_types[check.check_type] }}" target="_blank">{{ check.name|replace("'", "") }}</a>
</span>
<span class="overview-check-col"><b>{{ lang.words.interval|title() }}:</b> {{ check.interval }}</span>
<span class="check-name-tile overview-check-hostname"><b>URL:</b> <a href="{{ check.url }}" target="_blank">{{ check.url }}</a></span>
<span class="overview-check-col"><b>{{ lang.words.method|title() }}:</b> {{ check.method|upper() }}</span>
<span class="overview-check-col">
<a class="edit edit-button-fa" title="{{ lang.words.edit|title() }} {{ lang.words.this }} {{ lang.words.check }}" onclick="editSmon('{{check.multi_check_id}}', 'http')"></a>
</span>
</div>
{% endfor %}
</div>
{% endif %}
{% if tcp_checks %}
<div class="overview-check-type">TCP:</div>
<div class="overview-checks-div">
{% for check in tcp_checks %}
<div class="overview-check" id="check-{{ check.multi_check_id }}">
<span class="overview-check-name"><b>{{ lang.words.name|title() }}:</b>
<a href="/rmon/dashboard/{{ check.multi_check_id }}/{{ checking_types[check.check_type] }}" target="_blank">{{ check.name|replace("'", "") }}</a>
</span>
<span class="overview-check-col"><b>{{ lang.words.interval|title() }}:</b> {{ check.interval }}</span>
<span class="check-name-tile overview-check-hostname"><b>{{ lang.words.Hostname }}:</b> {{ check.ip }}</span>
<span class="overview-check-col"><b>{{ lang.words.port|title() }}:</b> {{ check.port }}</span>
<span class="overview-check-col">
<a class="edit edit-button-fa" title="{{ lang.words.edit|title() }} {{ lang.words.this }} {{ lang.words.check }}" onclick="editSmon('{{check.multi_check_id}}', 'tcp')"></a>
</span>
</div>
{% endfor %}
</div>
{% endif %}
{% if dns_checks %}
<div class="overview-check-type">DNS:</div>
<div class="overview-checks-div">
{% for check in dns_checks %}
<div class="overview-check" id="check-{{ check.multi_check_id }}">
<span class="overview-check-name"><b>{{ lang.words.name|title() }}:</b>
<a href="/rmon/dashboard/{{ check.multi_check_id }}/{{ checking_types[check.check_type] }}" target="_blank">{{ check.name|replace("'", "") }}</a>
</span>
<span class="overview-check-col"><b>{{ lang.words.interval|title() }}:</b> {{ check.interval }}</span>
<span class="check-name-tile overview-check-hostname"><b>{{ lang.words.record|title() }}:</b> {{ check.ip }}</span>
<span class="overview-check-col"> <b>Resolver:</b>{{ check.resolver }}</span>
<span class="overview-check-col"><b>{{ lang.words.record_type|title() }}:</b> {{ check.record_type|upper() }}</span>
<span class="overview-check-col"> <b>{{ lang.words.port|title() }}:</b> {{ check.port }}</span>
<span class="overview-check-col">
<a class="edit edit-button-fa" title="{{ lang.words.edit|title() }} {{ lang.words.this }} {{ lang.words.check }}" onclick="editSmon('{{check.multi_check_id}}', 'dns')"></a>
</span>
</div>
{% endfor %}
</div>
{% endif %}
{% if ping_checks %}
<div class="overview-check-type">Ping:</div>
<div class="overview-checks-div">
{% for check in ping_checks %}
<div class="overview-check" id="check-{{ check.multi_check_id }}">
<span class="overview-check-name"><b>{{ lang.words.name|title() }}:</b>
<a href="/rmon/dashboard/{{ check.multi_check_id }}/{{ checking_types[check.check_type] }}" target="_blank">{{ check.name|replace("'", "") }}</a>
</span>
<span class="overview-check-col"><b>{{ lang.words.interval|title() }}:</b> {{ check.interval }}</span>
<span class="check-name-tile overview-check-hostname"><b>{{ lang.words.Hostname }}:</b> {{ check.ip }} </span>
<span class="overview-check-col"><b>{{ lang.smon_page.desc.packet_size }}:</b> {{ check.packet_size }}</span>
<span class="overview-check-col">
<a class="edit edit-button-fa" title="{{ lang.words.edit|title() }} {{ lang.words.this }} {{ lang.words.check }}" onclick="editSmon('{{check.multi_check_id}}', 'ping')"></a>
</span>
</div>
{% endfor %}
</div>
{% endif %}
{% if smtp_checks %}
<div class="overview-check-type">SMTP:</div>
<div class="overview-checks-div">
{% for check in smtp_checks %}
<div class="overview-check" id="check-{{ check.multi_check_id }}">
<span class="overview-check-name"><b>{{ lang.words.name|title() }}:</b>
<a href="/rmon/dashboard/{{ check.multi_check_id }}/{{ checking_types[check.check_type] }}" target="_blank">{{ check.name|replace("'", "") }}</a>
</span>
<span class="overview-check-col"><b>{{ lang.words.interval|title() }}:</b> {{ check.interval }}</span>
<span class="check-name-tile overview-check-hostname"><b>{{ lang.words.Hostname }}:</b> {{ check.ip }} </span>
<span class="overview-check-col"><b>{{ lang.words.port|title() }}:</b> {{ check.port }} </span>
<span class="overview-check-col">
<a class="edit edit-button-fa" title="{{ lang.words.edit|title() }} {{ lang.words.this }} {{ lang.words.check }}" onclick="editSmon('{{check.multi_check_id}}', 'smtp')"></a>
</span>
</div>
{% endfor %}
</div>
{% endif %}
{% if rabbitmq_checks %}
<div class="overview-check-type">RabbitMQ:</div>
<div class="overview-checks-div">
{% for check in rabbitmq_checks %}
<div class="overview-check" id="check-{{ check.multi_check_id }}">
<span class="overview-check-name"><b>{{ lang.words.name|title() }}:</b>
<a href="/rmon/dashboard/{{ check.multi_check_id }}/{{ checking_types[check.check_type] }}" target="_blank">{{ check.name|replace("'", "") }}</a>
</span>
<span class="overview-check-col"><b>{{ lang.words.interval|title() }}:</b> {{ check.interval }}</span>
<span class="check-name-tile overview-check-hostname"><b>{{ lang.words.Hostname }}:</b> {{ check.ip }} </span>
<span class="overview-check-col"><b>VHost:</b> {{ check.vhost }}</span>
<span class="overview-check-col"><b>{{ lang.words.port|title() }}:</b> {{ check.port }} </span>
<span class="overview-check-col">
<a class="edit edit-button-fa" title="{{ lang.words.edit|title() }} {{ lang.words.this }} {{ lang.words.check }}" onclick="editSmon('{{check.multi_check_id}}', 'rabbitmq')"></a>
</span>
</div>
{% endfor %}
</div>
{% endif %}
</div>
</div>
Loading

0 comments on commit 37c63dd

Please sign in to comment.