Created
December 26, 2024 20:38
-
-
Save thanegill/da75b9ed79e6c5d9e5874b9ef17a10b3 to your computer and use it in GitHub Desktop.
LibreNMS/Nagios Oxidized check with http auth
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 ruby | |
## contrib via https://github.com/ytti/oxidized/issues/67 | |
require 'open-uri' | |
require 'json' | |
critical = false | |
pending = false | |
critical_nodes = [] | |
pending_nodes = [] | |
args = Hash[ ARGV.join(' ').scan(/--?([^=\s]+)(?:=(\S+))?/) ] | |
endpoint = "https://#{args['H']}/nodes.json" | |
response = URI.open(endpoint, :http_basic_authentication=>[args['username'], args['password']]).read() | |
json = JSON.parse(response) | |
json.each do |node| | |
if not node['last'].nil? | |
if node['last']['status'] != 'success' | |
critical_nodes << node['name'] | |
critical = true | |
end | |
else | |
pending_nodes << node['name'] | |
pending = true | |
end | |
end | |
if critical | |
puts '[CRIT] Unable to backup: ' + critical_nodes.join(',') | |
exit 2 | |
elsif pending | |
puts '[WARN] Pending backup: ' + pending_nodes.join(',') | |
exit 1 | |
else | |
puts '[OK] Backup of all nodes completed successfully.' | |
exit 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment