Skip to content

[bug] Monitor break when disk resource is mapped with nfs share #168

@rysiulg

Description

@rysiulg

Describe the bug
After install no data is sent to openWISP -in logread on Openwrt v.24 response error status 400 and error parsing nil values

Steps To Reproduce
Mount nfs share -or usb share?

Expected behavior
Add control of parsed value to check if is vallid

Screenshots
If applicable, add screenshots to help explain your problem.

System Informatioon:

  • OpenWrt 24 on Banana PI 8GB

After change on installatioon file /usr/lib/lua/openwisp-monitoring/resources.lua (added checkoing for nil -monitor starts sending data):
Original funkcjiion:

function resources.parse_disk_usage_org()
  local disk_usage_info = {}
  local disk_usage_file = io.popen('df')
  local disk_usage = disk_usage_file:read("*a")
  disk_usage_file:close()
  for _, line in ipairs(utils.split(disk_usage, "\n")) do
    if line:sub(1, 10) ~= 'Filesystem' then
      local filesystem, size, used, available, percent, location = line:match(
        '(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)')
      if filesystem ~= 'tmpfs' and not string.match(filesystem, 'overlayfs') then
        percent = percent:gsub('%W', '')
        -- available, size and used are in KiB
        table.insert(disk_usage_info, {
          filesystem = filesystem,
          available_bytes = tonumber(available) * 1024,
          size_bytes = tonumber(size) * 1024,
          used_bytes = tonumber(used) * 1024,
          used_percent = tonumber(percent),
          mount_point = location
        })
      end
    end
  end
  return disk_usage_info
end

Modified funkction:

function resources.parse_disk_usage()
  local disk_usage_info = {}
  local disk_usage_file = io.popen('df')
  local disk_usage = disk_usage_file:read("*a")
  disk_usage_file:close()

  for _, line in ipairs(utils.split(disk_usage, "\n")) do
    if line:sub(1, 10) ~= 'Filesystem' then
      local filesystem, size, used, available, percent, location = line:match(
        '(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)%s+(%S+)')

      -- ....... Zabezpieczenie przed nil:
      if filesystem and size and used and available and percent and location then
        if filesystem ~= 'tmpfs' and not string.match(filesystem, 'overlayfs') then
          percent = percent:gsub('%W', '')
          table.insert(disk_usage_info, {
            filesystem = filesystem,
            available_bytes = tonumber(available) * 1024,
            size_bytes = tonumber(size) * 1024,
            used_bytes = tonumber(used) * 1024,
            used_percent = tonumber(percent),
            mount_point = location
          })
        end
      else
        -- (opcjonalnie) logowanie b....dnej linii:
        -- print("Unable to parse line: " .. line)
      end
    end
  end

  return disk_usage_info
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions