#!/usr/bin/luaweb
json = require("json")
omg = require("omg")

function execute(command)
   local jsonResult
   local handle = io.popen(command)
   local result = handle:read("*a")
   handle:close()
  
   if result ~= nil then
      result = string.gsub(result,"\n","")
   end

   if result ~= nil then
      jsonResult=json.decode(result)
   end

   return jsonResult
end

local ret={}
ret.os={}
ret.os.name=omg.getOsType()
ret.os.version=omg.getOsVersion(ret.os.name)
ret.os.versionName=omg.getOsVersionName(ret.os.name)

ret.fw={}
ret.fw.packages=omg.getPackages(ret.os.name)
ret.fw.featureversion=omg.getFeatureversion()

ret.hw={}
ret.hw.host={}
ret.hw.host.vendor=omg.getHwVendor()
ret.hw.host.product=omg.getHwProduct()
ret.hw.host.uuid=omg.getSystemUuid()
ret.hw.host.processor={}
ret.hw.host.processor.version=omg.getHwProcessorVersion()
ret.hw.host.processor.frequency=omg.getHwProcessorFrequency()
ret.hw.host.processor.family=omg.getHwProcessorFamily()
ret.hw.host.processor.manufacturer=omg.getHwProcessorManufacturer()

ret.ip=omg.ipConfig()

ret.product=execute("omgproductinfo --all -json")

omg.runScript(ret,arg,"collects system information\n")


