more work on script checks
This commit is contained in:
parent
7da264842a
commit
465ec57a34
|
@ -15,6 +15,7 @@ from .models import (
|
||||||
WinServiceCheckEmail,
|
WinServiceCheckEmail,
|
||||||
ScriptCheck,
|
ScriptCheck,
|
||||||
ScriptCheckEmail,
|
ScriptCheckEmail,
|
||||||
|
Script,
|
||||||
)
|
)
|
||||||
|
|
||||||
admin.site.register(DiskCheck)
|
admin.site.register(DiskCheck)
|
||||||
|
@ -31,3 +32,4 @@ admin.site.register(WinServiceCheck)
|
||||||
admin.site.register(WinServiceCheckEmail)
|
admin.site.register(WinServiceCheckEmail)
|
||||||
admin.site.register(ScriptCheck)
|
admin.site.register(ScriptCheck)
|
||||||
admin.site.register(ScriptCheckEmail)
|
admin.site.register(ScriptCheckEmail)
|
||||||
|
admin.site.register(Script)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.2 on 2020-02-03 04:52
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('checks', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='script',
|
||||||
|
name='shell',
|
||||||
|
field=models.CharField(choices=[('powershell', 'Powershell'), ('cmd', 'Batch (CMD)'), ('python', 'Python')], default='powershell', max_length=100),
|
||||||
|
),
|
||||||
|
]
|
|
@ -19,7 +19,7 @@ STANDARD_CHECK_CHOICES = [
|
||||||
|
|
||||||
SCRIPT_CHECK_SHELLS = [
|
SCRIPT_CHECK_SHELLS = [
|
||||||
("powershell", "Powershell"),
|
("powershell", "Powershell"),
|
||||||
("batch", "Batch"),
|
("cmd", "Batch (CMD)"),
|
||||||
("python", "Python"),
|
("python", "Python"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -89,6 +89,14 @@ class Script(models.Model):
|
||||||
max_length=100, choices=SCRIPT_CHECK_SHELLS, default="powershell"
|
max_length=100, choices=SCRIPT_CHECK_SHELLS, default="powershell"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def filepath(self):
|
||||||
|
return f"salt://scripts//userdefined//{self.filename}"
|
||||||
|
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.filename
|
||||||
|
|
||||||
class ScriptCheck(models.Model):
|
class ScriptCheck(models.Model):
|
||||||
agent = models.ForeignKey(
|
agent = models.ForeignKey(
|
||||||
Agent, related_name="scriptchecks", on_delete=models.CASCADE
|
Agent, related_name="scriptchecks", on_delete=models.CASCADE
|
||||||
|
@ -111,14 +119,14 @@ class ScriptCheck(models.Model):
|
||||||
def send_email(self):
|
def send_email(self):
|
||||||
send_mail(
|
send_mail(
|
||||||
f"Script Check Fail on {self.agent.hostname}",
|
f"Script Check Fail on {self.agent.hostname}",
|
||||||
f"Script check {self.name} is failing on {self.agent.hostname}",
|
f"Script check {self.script.name} is failing on {self.agent.hostname}",
|
||||||
settings.EMAIL_HOST_USER,
|
settings.EMAIL_HOST_USER,
|
||||||
settings.EMAIL_ALERT_RECIPIENTS,
|
settings.EMAIL_ALERT_RECIPIENTS,
|
||||||
fail_silently=False,
|
fail_silently=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.agent.hostname} - {self.name}"
|
return f"{self.agent.hostname} - {self.script.filename}"
|
||||||
|
|
||||||
class ScriptCheckEmail(models.Model):
|
class ScriptCheckEmail(models.Model):
|
||||||
email = models.ForeignKey(ScriptCheck, on_delete=models.CASCADE)
|
email = models.ForeignKey(ScriptCheck, on_delete=models.CASCADE)
|
||||||
|
|
|
@ -7,6 +7,7 @@ from .models import (
|
||||||
PingCheck,
|
PingCheck,
|
||||||
CpuHistory,
|
CpuHistory,
|
||||||
WinServiceCheck,
|
WinServiceCheck,
|
||||||
|
Script,
|
||||||
ScriptCheck,
|
ScriptCheck,
|
||||||
)
|
)
|
||||||
from agents.models import Agent
|
from agents.models import Agent
|
||||||
|
@ -42,10 +43,40 @@ class PingCheckSerializer(serializers.ModelSerializer):
|
||||||
model = PingCheck
|
model = PingCheck
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class ScriptSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Script
|
||||||
|
fields = (
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"description",
|
||||||
|
"filename",
|
||||||
|
"shell",
|
||||||
|
"filepath",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ScriptCheckSerializer(serializers.ModelSerializer):
|
class ScriptCheckSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
script = ScriptSerializer(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ScriptCheck
|
model = ScriptCheck
|
||||||
fields = "__all__"
|
fields = (
|
||||||
|
"id",
|
||||||
|
"check_type",
|
||||||
|
"timeout",
|
||||||
|
"failures",
|
||||||
|
"status",
|
||||||
|
"failure_count",
|
||||||
|
"email_alert",
|
||||||
|
"text_alert",
|
||||||
|
"more_info",
|
||||||
|
"last_run",
|
||||||
|
"agent",
|
||||||
|
"script",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class WinServiceCheckSerializer(serializers.ModelSerializer):
|
class WinServiceCheckSerializer(serializers.ModelSerializer):
|
||||||
|
|
|
@ -520,6 +520,7 @@ echo "${celerybeatservice}" | sudo tee /etc/systemd/system/celerybeat.service >
|
||||||
sudo mkdir -p /srv/salt
|
sudo mkdir -p /srv/salt
|
||||||
sudo cp -r /home/${USER}/rmm/_modules /srv/salt/
|
sudo cp -r /home/${USER}/rmm/_modules /srv/salt/
|
||||||
sudo cp -r /home/${USER}/rmm/scripts /srv/salt/
|
sudo cp -r /home/${USER}/rmm/scripts /srv/salt/
|
||||||
|
sudo mkdir /srv/salt/scripts/userdefined
|
||||||
sudo chown root:root -R /srv/salt/
|
sudo chown root:root -R /srv/salt/
|
||||||
sudo chown root:${USER} -R /srv/salt/scripts/
|
sudo chown root:${USER} -R /srv/salt/scripts/
|
||||||
sudo chmod 770 -R /srv/salt/scripts/
|
sudo chmod 770 -R /srv/salt/scripts/
|
||||||
|
|
Loading…
Reference in New Issue