mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
libvirt/kvm_*: Simple regex to match VM name
On Debian Stretch the cmdline is something like: qemu-system-x86_64-enable-kvm-nameguest=vmname,debug-threads=on-S-[…] Without null characters: qemu-system-x86_64 -enable-kvm -name guest=vmname,debug-threads=on[…] We need to match only guest=vmname, so the regex "^.*guest=([a-zA-Z0-9.-_-]*).*$" is simpler and match the VM name. The precedent regex "^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$" was not matching it. BTW, It seems that \x00 does not match correctly null characters so I removed it.
This commit is contained in:
parent
33270dd198
commit
c4a08bfa53
3 changed files with 3 additions and 3 deletions
|
@ -68,7 +68,7 @@ def find_vm_names(pids):
|
||||||
result = {}
|
result = {}
|
||||||
for pid in pids:
|
for pid in pids:
|
||||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||||
result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline()))
|
result[pid] = clean_vm_name(re.sub(r"^.*guest=([a-zA-Z0-9.-_-]*).*$",r"\1", cmdline.readline()))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def list_pids():
|
def list_pids():
|
||||||
|
|
|
@ -85,7 +85,7 @@ def find_vm_names(pids):
|
||||||
result = {}
|
result = {}
|
||||||
for pid in pids:
|
for pid in pids:
|
||||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||||
result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline()))
|
result[pid] = clean_vm_name(re.sub(r"^.*guest=([a-zA-Z0-9.-_-]*).*$",r"\1", cmdline.readline()))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def list_pids():
|
def list_pids():
|
||||||
|
|
|
@ -82,7 +82,7 @@ def find_vm_names(pids):
|
||||||
result = {}
|
result = {}
|
||||||
for pid in pids:
|
for pid in pids:
|
||||||
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
||||||
result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-_-]*)\x00\-.*$",r"\1", cmdline.readline()))
|
result[pid] = clean_vm_name(re.sub(r"^.*guest=([a-zA-Z0-9.-_-]*).*$",r"\1", cmdline.readline()))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def list_pids():
|
def list_pids():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue