Skip to content

Instantly share code, notes, and snippets.

@ccooke
Created November 1, 2016 18:08
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 ccooke/d0c31edfaa01f11bcc06f539f0bfee28 to your computer and use it in GitHub Desktop.
Save ccooke/d0c31edfaa01f11bcc06f539f0bfee28 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Zabbix LLD to show mounted filesystems that use true block devices (for use with items such as vfs.dev.read/write)
exec 3<"/proc/mounts"
echo -n '{"data":['
opts=( FSDEV FSNAME FSTYPE FSOPTS FSDUMPFREQ FSDUMPPASS )
linesep="" while read -u3 -a line; do
[[ -b "${line[0]}" ]] || continue echo -n "$linesep" linesep="},"
sep='{'
i=0
for field in "${opts[@]}"; do
printf '%s"{#%s}":"%s"' "$sep" "$field" "${line[i]}"
sep=','
(( i++ ))
done
done
echo "}]}"
@ccooke
Copy link
Author

ccooke commented Nov 1, 2016

Example:

charlescooke@molybdenum:~$ bash mounted_blockdev_lld.sh 
{"data":[{"{#FSDEV}":"/dev/dm-1","{#FSNAME}":"/","{#FSTYPE}":"ext4","{#FSOPTS}":"rw,relatime,errors=remount-ro,data=ordered","{#FSDUMPFREQ}":"0","{#FSDUMPPASS}":"0"},{"{#FSDEV}":"/dev/sda2","{#FSNAME}":"/boot","{#FSTYPE}":"ext2","{#FSOPTS}":"rw,relatime,block_validity,barrier,user_xattr,acl","{#FSDUMPFREQ}":"0","{#FSDUMPPASS}":"0"},{"{#FSDEV}":"/dev/sda1","{#FSNAME}":"/boot/efi","{#FSTYPE}":"vfat","{#FSOPTS}":"rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro","{#FSDUMPFREQ}":"0","{#FSDUMPPASS}":"0"}]}
charlescooke@molybdenum:~$ bash mounted_blockdev_lld.sh  | jq .
{
  "data": [
    {
      "{#FSDEV}": "/dev/dm-1",
      "{#FSNAME}": "/",
      "{#FSTYPE}": "ext4",
      "{#FSOPTS}": "rw,relatime,errors=remount-ro,data=ordered",
      "{#FSDUMPFREQ}": "0",
      "{#FSDUMPPASS}": "0"
    },
    {
      "{#FSDEV}": "/dev/sda2",
      "{#FSNAME}": "/boot",
      "{#FSTYPE}": "ext2",
      "{#FSOPTS}": "rw,relatime,block_validity,barrier,user_xattr,acl",
      "{#FSDUMPFREQ}": "0",
      "{#FSDUMPPASS}": "0"
    },
    {
      "{#FSDEV}": "/dev/sda1",
      "{#FSNAME}": "/boot/efi",
      "{#FSTYPE}": "vfat",
      "{#FSOPTS}": "rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro",
      "{#FSDUMPFREQ}": "0",
      "{#FSDUMPPASS}": "0"
    }
  ]
}
charlescooke@molybdenum:~$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment