Merge pull request #18628 from mcb30/openconnect-proxy
authorNikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
Sun, 7 Aug 2022 20:15:11 +0000 (22:15 +0200)
committerGitHub <noreply@github.com>
Sun, 7 Aug 2022 20:15:11 +0000 (22:15 +0200)
OpenConnect proxy support

utils/prometheus-node-exporter-lua/Makefile
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/hostapd_stations.lua
utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/selinux.lua [new file with mode: 0644]

index f78db55ad6198774f496c24b164abd9637815284..812a7bd74a6e703dbf1339d0eac72898223fa37a 100644 (file)
@@ -4,7 +4,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=prometheus-node-exporter-lua
-PKG_VERSION:=2022.06.12
+PKG_VERSION:=2022.08.07
 PKG_RELEASE:=1
 
 PKG_MAINTAINER:=Etienne CHAMPETIER <champetier.etienne@gmail.com>
@@ -41,6 +41,7 @@ define Package/prometheus-node-exporter-lua/install
        $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/loadavg.lua     $(1)/usr/lib/lua/prometheus-collectors/
        $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/meminfo.lua     $(1)/usr/lib/lua/prometheus-collectors/
        $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/netdev.lua      $(1)/usr/lib/lua/prometheus-collectors/
+       $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/selinux.lua     $(1)/usr/lib/lua/prometheus-collectors/
        $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/time.lua        $(1)/usr/lib/lua/prometheus-collectors/
        $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/uname.lua       $(1)/usr/lib/lua/prometheus-collectors/
        $(INSTALL_BIN) ./files/usr/lib/lua/prometheus-collectors/netclass.lua    $(1)/usr/lib/lua/prometheus-collectors/
index f843dda18dec5e036a3a3c735fc9674b2f5b08d2..2b97c70523cbdc89974b900dbffaa58a8fff0cf0 100644 (file)
@@ -1,52 +1,78 @@
 local ubus = require "ubus"
 local bit32 = require "bit32"
 
+local function get_wifi_interfaces()
+  local conn = ubus.connect()
+  local ubuslist = conn:objects()
+  local interfaces = {}
+
+  for _,net in ipairs(ubuslist) do
+    if net.find(net,"hostapd.") then
+      local ifname = net:gsub("hostapd.", "")
+      table.insert(interfaces, ifname);
+    end
+  end
+  conn:close()
+  return interfaces;
+end
+
+local function is_ubus_interface(ubus_interfaces, interface)
+  for i=1,#ubus_interfaces do
+    if ubus_interfaces[i] == interface then return true end
+  end
+  return false
+end
+
 local function get_wifi_interface_labels()
   local u = ubus.connect()
   local status = u:call("network.wireless", "status", {})
   local interfaces = {}
+  local ubus_interfaces = get_wifi_interfaces()
 
   for _, dev_table in pairs(status) do
     for _, intf in ipairs(dev_table['interfaces']) do
       local cfg = intf['config']
 
-      -- Migrate this to ubus interface once it exposes all interesting labels
-      local handle = io.popen("hostapd_cli -i " .. cfg['ifname'] .." status")
-      local hostapd_status = handle:read("*a")
-      handle:close()
-
-      local hostapd = {}
-      local bss_idx = -1
-      for line in hostapd_status:gmatch("[^\r\n]+") do
-        local name, value = string.match(line, "(.+)=(.+)")
-        if name == "freq" then
-          hostapd["freq"] = value
-        elseif name == "channel" then
-          hostapd["channel"] = value
-        -- hostapd gives us all bss on the relevant phy, find the one we're interested in
-        elseif string.match(name, "bss%[%d%]") then
-          if value == cfg['ifname'] then
-            bss_idx = tonumber(string.match(name, "bss%[(%d)%]"))
-          end
-        elseif bss_idx >= 0 then
-          if name == "bssid[" .. bss_idx .. "]" then
-            hostapd["bssid"] = value
-          elseif name == "ssid[" .. bss_idx .. "]" then
-            hostapd["ssid"] = value
+      if is_ubus_interface(ubus_interfaces, cfg['ifname']) then
+
+        -- Migrate this to ubus interface once it exposes all interesting labels
+        local handle = io.popen("hostapd_cli -i " .. cfg['ifname'] .." status")
+        local hostapd_status = handle:read("*a")
+        handle:close()
+
+        local hostapd = {}
+        local bss_idx = -1
+        for line in hostapd_status:gmatch("[^\r\n]+") do
+          local name, value = string.match(line, "(.+)=(.+)")
+          if name == "freq" then
+            hostapd["freq"] = value
+          elseif name == "channel" then
+            hostapd["channel"] = value
+          -- hostapd gives us all bss on the relevant phy, find the one we're interested in
+          elseif string.match(name, "bss%[%d%]") then
+            if value == cfg['ifname'] then
+              bss_idx = tonumber(string.match(name, "bss%[(%d)%]"))
+            end
+          elseif bss_idx >= 0 then
+            if name == "bssid[" .. bss_idx .. "]" then
+              hostapd["bssid"] = value
+            elseif name == "ssid[" .. bss_idx .. "]" then
+              hostapd["ssid"] = value
+            end
           end
         end
-      end
 
-      local labels = {
-        vif = cfg['ifname'],
-        ssid = hostapd['ssid'],
-        bssid = hostapd['bssid'],
-        encryption = cfg['encryption'], -- In a mixed scenario it would be good to know if A or B was used
-        frequency = hostapd['freq'],
-        channel = hostapd['channel'],
-      }
+        local labels = {
+          vif = cfg['ifname'],
+          ssid = hostapd['ssid'],
+          bssid = hostapd['bssid'],
+          encryption = cfg['encryption'], -- In a mixed scenario it would be good to know if A or B was used
+          frequency = hostapd['freq'],
+          channel = hostapd['channel'],
+        }
 
-      table.insert(interfaces, labels)
+        table.insert(interfaces, labels)
+      end
     end
   end
 
diff --git a/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/selinux.lua b/utils/prometheus-node-exporter-lua/files/usr/lib/lua/prometheus-collectors/selinux.lua
new file mode 100644 (file)
index 0000000..9bfb6c8
--- /dev/null
@@ -0,0 +1,12 @@
+local function scrape()
+  local enforcing_mode = get_contents("/sys/fs/selinux/enforce")
+
+  if enforcing_mode ~= nil then
+    metric("node_selinux_enabled", "gauge", nil, 0)
+  else
+    metric("node_selinux_enabled", "gauge", nil, 1)
+    metric("node_selinux_current_mode", "gauge", nil, enforcing_mode)
+  end
+end
+
+return { scrape = scrape }