Skip to content

Instantly share code, notes, and snippets.

@garo
Last active February 17, 2020 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garo/f3379c9d2260a0af7cd9ff46610c22b4 to your computer and use it in GitHub Desktop.
Save garo/f3379c9d2260a0af7cd9ff46610c22b4 to your computer and use it in GitHub Desktop.
#!/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