|
28 | 28 | import os.path |
29 | 29 | from adagios import settings |
30 | 30 | import adagios.utils |
31 | | -from pynag import Model, Control |
| 31 | +from pynag import Model |
32 | 32 | from django.core.mail import EmailMultiAlternatives |
33 | 33 | import pynag.Parsers |
34 | 34 | import pynag.Control.Command |
| 35 | +import adagios.daemon |
35 | 36 |
|
36 | 37 |
|
37 | 38 | TOPIC_CHOICES = ( |
@@ -120,8 +121,12 @@ class AdagiosSettingsForm(forms.Form): |
120 | 121 | required=False, initial=settings.destination_directory, help_text=_("Where to save new objects that adagios creates.")) |
121 | 122 | nagios_url = forms.CharField(required=False, initial=settings.nagios_url, |
122 | 123 | help_text=_("URL (relative or absolute) to your nagios webcgi. Adagios will use this to make it simple to navigate from a configured host/service directly to the cgi.")) |
| 124 | + nagios_service = forms.CharField( |
| 125 | + required=False, |
| 126 | + help_text=_("The name of the nagios service, commonly nagios or nagios3. Adagios will use this when stopping/starting/reloading nagios")) |
123 | 127 | nagios_init_script = forms.CharField( |
124 | | - help_text=_("Path to you nagios init script. Adagios will use this when stopping/starting/reloading nagios")) |
| 128 | + required=False, |
| 129 | + help_text=_("You should define either 'Nagios service' or 'Nagios init script'. Path to you nagios init script. Adagios will use this when stopping/starting/reloading nagios")) |
125 | 130 | nagios_binary = forms.CharField( |
126 | 131 | help_text=_("Path to you nagios daemon binary. Adagios will use this to verify config with 'nagios -v nagios_config'")) |
127 | 132 | livestatus_path = forms.CharField( |
@@ -204,7 +209,7 @@ def clean_nagios_init_script(self): |
204 | 209 | filename = self.cleaned_data['nagios_init_script'] |
205 | 210 | if filename.startswith('sudo'): |
206 | 211 | self.check_file_exists(filename.split()[1]) |
207 | | - else: |
| 212 | + elif filename: |
208 | 213 | self.check_file_exists(filename) |
209 | 214 | return filename |
210 | 215 |
|
@@ -499,31 +504,31 @@ class NagiosServiceForm(forms.Form): |
499 | 504 |
|
500 | 505 | def save(self): |
501 | 506 | #nagios_bin = self.cleaned_data['nagios_bin'] |
| 507 | + daemon = adagios.daemon.Daemon() |
502 | 508 | if "reload" in self.data: |
503 | | - command = "reload" |
| 509 | + command = daemon.reload |
| 510 | + self.command = "reload" |
504 | 511 | elif "restart" in self.data: |
505 | | - command = "restart" |
| 512 | + command = daemon.restart |
| 513 | + self.command = "restart" |
506 | 514 | elif "stop" in self.data: |
507 | | - command = "stop" |
| 515 | + command = daemon.stop |
| 516 | + self.command = "stop" |
508 | 517 | elif "start" in self.data: |
509 | | - command = "start" |
| 518 | + command = daemon.start |
| 519 | + self.command = "start" |
510 | 520 | elif "status" in self.data: |
511 | | - command = "status" |
| 521 | + command = daemon.status |
| 522 | + self.command = "status" |
512 | 523 | elif "verify" in self.data: |
513 | | - command = "verify" |
| 524 | + command = daemon.verify_config |
| 525 | + self.command = "verify" |
514 | 526 | else: |
515 | 527 | raise Exception(_("Unknown command")) |
516 | | - self.command = command |
517 | | - nagios_init = settings.nagios_init_script |
518 | | - nagios_binary = settings.nagios_binary |
519 | | - nagios_config = settings.nagios_config or pynag.Model.config.cfg_file |
520 | | - if command == "verify": |
521 | | - command = "%s -v '%s'" % (nagios_binary, nagios_config) |
522 | | - else: |
523 | | - command = "%s %s" % (nagios_init, command) |
524 | | - code, stdout, stderr = pynag.Utils.runCommand(command) |
525 | | - self.stdout = stdout or "" |
526 | | - self.stderr = stderr or "" |
| 528 | + |
| 529 | + code = command() |
| 530 | + self.stdout = daemon.stdout or "" |
| 531 | + self.stderr = daemon.stderr or "" |
527 | 532 | self.exit_code = code |
528 | 533 |
|
529 | 534 | def verify(self): |
|
0 commit comments