aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2023-02-13 09:49:05 +0000
committerterminaldweller <thabogre@gmail.com>2023-02-13 09:49:05 +0000
commit3d864c067471c657b95979b30c2e5cdc603ad17b (patch)
tree81aec07b3c310a00b50634349838cef345a4a7bf /bin
parentupdates (diff)
downloadscripts-3d864c067471c657b95979b30c2e5cdc603ad17b.tar.gz
scripts-3d864c067471c657b95979b30c2e5cdc603ad17b.zip
update
Diffstat (limited to 'bin')
-rwxr-xr-xbin/clipd24
-rwxr-xr-xbin/virttop33
2 files changed, 44 insertions, 13 deletions
diff --git a/bin/clipd b/bin/clipd
index 6c6d40e..bf3d1f3 100755
--- a/bin/clipd
+++ b/bin/clipd
@@ -8,9 +8,7 @@ local string = require("string")
local signal = require("posix.signal")
local argparse = require("argparse")
local sys_stat = require("posix.sys.stat")
-local unistd_getuid = require("posix.unistd.getuid")
-local unistd_getgid = require("posix.unistd.getgid")
-local unistd_getpid = require("posix.unistd.getpid")
+local unistd = require("posix.unistd")
local posix_syslog = require("posix.syslog")
local function default_luarocks_modules()
@@ -50,8 +48,8 @@ local function log_to_syslog(log_str, log_priority)
end
local function check_clip_hist_perms(clip_hist)
- local uid = unistd_getuid()
- local gid = unistd_getgid()
+ local uid = unistd.getuid()
+ local gid = unistd.getgid()
for k, v in pairs(sys_stat.stat(clip_hist)) do
if k == "st_uid" then
if v ~= uid then
@@ -70,7 +68,8 @@ local function check_clip_hist_perms(clip_hist)
end
end
if k == "st_mode" then
- if v & sys_stat.S_IRWXU ~= 0 then
+ if v and (sys_stat.S_IRUSR or sys_stat.S_IWUSR) ~=
+ (sys_stat.S_IRUSR or sys_stat.S_IWUSR) then
log_to_syslog(
"file permissions are too open. they need to be 0600.",
posix_syslog.LOG_CRIT)
@@ -81,16 +80,21 @@ local function check_clip_hist_perms(clip_hist)
end
local function check_pid_file()
- local f = sys_stat("/var/run/clipd.pid")
+ local f = sys_stat.stat("/var/run/clipd.pid")
if f ~= nil then
log_to_syslog("clipd is already running", posix_syslog.LOG_CRIT)
os.exit(1)
end
end
+-- FIXME- we cant write to /var/run since we are running as non-root user
local function write_pid_file()
- local f = io.open("/var/run/clipd.pid")
- f.write(unistd_getpid())
+ local f = io.open("/var/run/clipd.pid", "w")
+ if f == nil then
+ log_to_syslog("cant open pid file for writing", posix_syslog.LOG_CRIT)
+ os.exit(1)
+ end
+ f.write(unistd.getpid())
end
local function remove_pid_file() end
@@ -145,7 +149,7 @@ local function main()
local args = parser:parse()
check_clip_hist_perms(args["hist_file"])
check_pid_file()
- write_pid_file()
+ -- write_pid_file()
local status, err = pcall(loop(args["hist_file"], args["hist_size"]))
if ~status then log_to_syslog(err, posix_syslog.LOG_CRIT) end
remove_pid_file()
diff --git a/bin/virttop b/bin/virttop
index 24c4bb8..4d8943b 100755
--- a/bin/virttop
+++ b/bin/virttop
@@ -9,11 +9,14 @@ import argparse
import csv
import dataclasses
import enum
+import os
import signal
import sys
import time
import typing
-from xml.dom.minidom import Document
+
+# we are only using this for type annotation
+from xml.dom.minidom import Document # nosec
from defusedxml import ElementTree # type:ignore
from defusedxml import minidom
@@ -90,6 +93,11 @@ class VirtData:
disk_writes: typing.List[str] = dataclasses.field(default_factory=list)
snapshot_counts: typing.List[str] = dataclasses.field(default_factory=list)
uri: typing.List[str] = dataclasses.field(default_factory=list)
+ memory_pool: typing.List[str] = dataclasses.field(default_factory=list)
+
+ pools: typing.List[libvirt.virStoragePool] = dataclasses.field(
+ default_factory=list
+ )
def get_network_info(
@@ -249,7 +257,10 @@ def fill_virt_data_uri(
virt_data.name.append(dom.name())
mem_stats = dom.memoryStats()
- virt_data.mem_actual.append(size_abr(mem_stats["actual"], 1000))
+ if "actual" in mem_stats:
+ virt_data.mem_actual.append(size_abr(mem_stats["actual"], 1000))
+ else:
+ virt_data.mem_actual.append("n/a")
# BSD guests dont support mem balloons?
try:
@@ -263,6 +274,18 @@ def fill_virt_data_uri(
virt_data.write_bytes.append(size_abr(stats[4], 1))
virt_data.read_bytes.append(size_abr(stats[0], 1))
+ found_the_pool: bool = False
+ disk = tree.find("devices/disk/source").get("file")
+ for pool in virt_data.pools:
+ if os.path.basename(disk) in pool.listVolumes():
+ virt_data.memory_pool.append(pool.name())
+ found_the_pool = True
+ # you could delete the pool but keep the volumes inside
+ # which results in a functional VM but it wont have a
+ # volume inside a pool that we can detect
+ if not found_the_pool:
+ virt_data.memory_pool.append("N/A")
+
disk_info = get_disk_info(xml_doc)
image_name = disk_info["file"]
_, rd_bytes, _, wr_bytes, _ = dom.blockStats(image_name)
@@ -290,7 +313,9 @@ def main() -> None:
conn = libvirt.openReadOnly(hv_host)
active_hosts = conn.listDomainsID()
if len(active_hosts) > 0:
- # pools = conn.listAllStoragePools()
+ virt_data.pools = conn.listAllStoragePools()
+ # for pool in virt_data.pools:
+ # print(pool.listVolumes())
# networks = conn.listAllNetworks()
# print([pool.name() for pool in conn.listAllStoragePools()])
# print([net.name() for net in conn.listAllNetworks()])
@@ -321,6 +346,7 @@ def main() -> None:
"IO_WRITE_B",
"SNAPSHOTS",
"URI",
+ "STORAGE_POOL",
],
False,
virt_data.vm_id,
@@ -336,6 +362,7 @@ def main() -> None:
virt_data.disk_writes,
virt_data.snapshot_counts,
virt_data.uri,
+ virt_data.memory_pool,
)
for line in lines:
print(line)