This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run with no arguments: | |
$ check_load | |
OK - load1=1 load5=5 load15=15 | 'load1'=1;;;; 'load5'=5;;;; 'load15'=15;;;; | |
# Run with 1 warning threshold: | |
$ check_load --warning 'load1 > 5' | |
OK - load1=1 load5=5 load15=15 | 'load1'=1;;;; 'load5'=5;;;; 'load15'=15;;;; | |
* OK: load1 > 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- In the top navigation bar somewhere --> | |
<ul> | |
<li><a href="" onclick='adagios.rest.status.toggle_backend({"backend":"localhost:6559"});'>localhost</a></li> | |
<li><a href="" onclick='adagios.rest.status.toggle_backend({"backend":"backend1:6559"});'>backend1</a></li> | |
<li><a href="" onclick='adagios.rest.status.toggle_backend({"backend":"backend2:6559"});'>backend2</a></li> | |
</ul> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Find all nagios hosts that belong to hostgroup HG1: | |
import pynag.Model | |
hostgroup_name = "HG1" | |
hostgroup = pynag.Model.Hostgroup.objects.get_by_shortname(hostgroup_name) | |
hosts = hostgroup.get_effective_hosts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pynag.Model | |
new_threshold = "5" | |
myservices = pynag.Model.Service.objects.filter(name="some-template") | |
for i in myservices: | |
i.set_attribute('__WARNING_THRESHOLD') = new_threshold | |
i.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> nagios = FakeNagiosEnvironment() | |
>>> nagios.update_model() # Update the global variables in pynag.Model | |
>>> pynag.Model.Host(host_name="foo",use="generic-host").save() # Create new host | |
>>> nagios.configure_livestatus() | |
>>> nagios.start() # Start up nagios | |
>>> config = nagios.get_config() # Returns Parsers.Config instance | |
>>> livestatus = nagios.get_livestatus() # Returns Parsers.Livestatus instance | |
>>> nagios.terminate() # Stop nagios and clean up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (02:12:42 PM) samkottler: dnsmichi: yeah I'll definitely submit that. | |
# and probably something about monitoring millions of resources in the public cloud. | |
define service { | |
use generic-service | |
host_name localhost | |
service_description Millions of services in the cloud | |
check_command execute!$USER1$/check_millions_of_services | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import pynag.Model | |
services = pynag.Model.Service.objects.filter(host_name__exists=True, service_description__exists=True) | |
for service in services: | |
if not '$' in service.service_description: | |
continue | |
expanded_description = service._resolve_macros(service.service_description) | |
service.service_description = expanded_description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Find all nagios services with description "check_webserver" and give them | |
# the same notification period as their host | |
import pynag.Model | |
services = pynag.Model.Service.objects.filter(service_description="check_webserver") | |
for service in services: | |
host = pynag.Model.Host.objects.get_by_shortname(service.host_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SshConfig(pynag.Parsers.config): | |
""" Parse object configuration files from remote host via ssh """ | |
def __init__(self, host, username, password=None, cfg_file=None): | |
import paramiko | |
self.ssh = paramiko.SSHClient() | |
self.ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() ) | |
self.ssh.connect(host, username=username, password=password) | |
self.ftp = self.ssh.open_sftp() | |
pynag.Parsers.config.__init__(self, cfg_file=cfg_file) |