Last active
July 26, 2019 12:48
-
-
Save pere3/57ba52ac625e53e35adce952bb69da1b to your computer and use it in GitHub Desktop.
saltstack custom runner, proxmox themed, lvm-thin overprovisioning check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
Proxmox runner | |
''' | |
import json | |
import salt.utils.event | |
import salt.client | |
def lvm_check(): | |
''' | |
Proxmox LVM-thin overprovisioning check | |
''' | |
schema = {} | |
client = salt.client.LocalClient(__opts__['conf_file']) | |
event = salt.utils.event.get_master_event(__opts__, __opts__['sock_dir'], listen=False) | |
lv_data = client.cmd('*proxmox*', 'lvm.lvdisplay', timeout=1) | |
vg_data = client.cmd('*proxmox*', 'lvm.vgdisplay', timeout=1) | |
for minion in vg_data: | |
if vg_data[minion]: | |
schema[minion] = {} | |
for vg in vg_data[minion]: | |
schema[minion][vg] = {} | |
schema[minion][vg]['allocated'] = 0 | |
schema[minion][vg]['total'] = int(vg_data[minion][vg]['Volume Group Size (kB)']) | |
for minion in lv_data: | |
if minion in schema: | |
for lv in lv_data[minion]: | |
if 'vm' in lv: | |
vg = lv_data[minion][lv]['Volume Group Name'] | |
size = int(lv_data[minion][lv]['Logical Volume Size']) / 2 # With --colon option lvdisplay shows size always in sectors (512 bytes units). | |
schema[minion][vg]['allocated'] += size | |
for minion in schema: | |
for vg in schema[minion]: | |
volume = schema[minion][vg] | |
if volume['allocated'] > volume['total']: | |
percent = volume['allocated'] / volume['total'] | |
data = {'host': minion, | |
'volumeGroup': vg, | |
'bytesTotal': volume['total'], | |
'bytesAllocated': volume['allocated'], | |
'over': '{:.0%}'.format(percent)} | |
event.fire_event({'post': data}, 'salt/runner/proxmox.lvm_check/msg') | |
return json.dumps(schema, indent=4, sort_keys=True, ensure_ascii=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment