Last active
February 17, 2020 10:03
-
-
Save garo/f3379c9d2260a0af7cd9ff46610c22b4 to your computer and use it in GitHub Desktop.
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/ruby | |
require 'json' | |
str = `zfs list -t snapshot -o name,creation -H -p`.split("\n") | |
zabbix_server = "..." | |
hostname = `hostname` | |
filesystems = {} | |
str.each do |line| | |
parts = line.split(/\t/) | |
n = parts[0].split("@") # Extract the filesystem base name without the snapshot name | |
name = n[0] | |
filesystems[name] ||= [] | |
filesystems[name] << parts | |
end | |
zabbix_discovery = { | |
:data => [] | |
} | |
filesystems.each do |name, snapshots| | |
zabbix_discovery[:data] << { | |
"{#SNAPSHOTNAME}": name | |
} | |
end | |
puts `zabbix_sender -v -z #{zabbix_server} -k snapshots.discovery_list -o '#{zabbix_discovery.to_json}' -s #{hostname}` | |
filesystems.each do |name, snapshots| | |
ordered = snapshots.sort_by { |x| x[1] } | |
age = Time.now.getutc.to_i - ordered.last[1].to_i | |
puts "Filesystem #{name} has #{snapshots.length} snapshots. latest snapshot #{ordered.last} is #{age} seconds old" | |
`zabbix_sender -v -z #{zabbix_server} -k snapshots.age[#{name}] -o '#{age}' -s #{hostname}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment