fix sensitive values
This commit is contained in:
1 parent
169271a42f
commit
1ba0a7936f
1 file changed
+23
-22
@@ -18,7 +18,7 @@ class ZabbixAPI:
|
||||
self.url = url
|
||||
self.token = token
|
||||
self.request_id = 1
|
||||
|
||||
|
||||
def call(self, method, params):
|
||||
headers = {
|
||||
'Content-Type': 'application/json-rpc',
|
||||
@@ -30,23 +30,23 @@ class ZabbixAPI:
|
||||
'params': params,
|
||||
'id': self.request_id,
|
||||
}
|
||||
|
||||
|
||||
self.request_id += 1
|
||||
|
||||
|
||||
try:
|
||||
response = requests.post(self.url, json=payload, headers=headers, verify=False)
|
||||
response.raise_for_status()
|
||||
result = response.json()
|
||||
|
||||
|
||||
if 'error' in result:
|
||||
print(f"API Error: {result['error']}")
|
||||
return None
|
||||
|
||||
|
||||
return result.get('result')
|
||||
except Exception as e:
|
||||
print(f"Request failed: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def get_host_config(self, hostname):
|
||||
# Get host with all related information
|
||||
hosts = self.call('host.get', {
|
||||
@@ -57,11 +57,11 @@ class ZabbixAPI:
|
||||
'selectMacros': 'extend',
|
||||
'selectInventory': 'extend'
|
||||
})
|
||||
|
||||
|
||||
if not hosts:
|
||||
print(f"Host '{hostname}' not found")
|
||||
return None
|
||||
|
||||
|
||||
return hosts[0]
|
||||
|
||||
def format_host_info(host):
|
||||
@@ -69,13 +69,13 @@ def format_host_info(host):
|
||||
print(f"HOST CONFIGURATION: {host['host']}")
|
||||
print("=" * 80)
|
||||
print()
|
||||
|
||||
|
||||
# Basic info
|
||||
print(f"Host ID: {host['hostid']}")
|
||||
print(f"Name: {host['name']}")
|
||||
print(f"Status: {'Enabled' if host['status'] == '0' else 'Disabled'}")
|
||||
print()
|
||||
|
||||
|
||||
# Host Groups
|
||||
print("HOST GROUPS:")
|
||||
if host['groups']:
|
||||
@@ -84,7 +84,7 @@ def format_host_info(host):
|
||||
else:
|
||||
print(" (none)")
|
||||
print()
|
||||
|
||||
|
||||
# Templates
|
||||
print("TEMPLATES:")
|
||||
if host['parentTemplates']:
|
||||
@@ -93,7 +93,7 @@ def format_host_info(host):
|
||||
else:
|
||||
print(" (none)")
|
||||
print()
|
||||
|
||||
|
||||
# Interfaces
|
||||
print("INTERFACES:")
|
||||
if host['interfaces']:
|
||||
@@ -104,7 +104,7 @@ def format_host_info(host):
|
||||
'3': 'IPMI',
|
||||
'4': 'JMX'
|
||||
}.get(iface['type'], 'Unknown')
|
||||
|
||||
|
||||
print(f" [{iface_type}] {iface['ip']}:{iface['port']}")
|
||||
if iface['dns']:
|
||||
print(f" DNS: {iface['dns']}")
|
||||
@@ -112,45 +112,46 @@ def format_host_info(host):
|
||||
else:
|
||||
print(" (none)")
|
||||
print()
|
||||
|
||||
|
||||
# Proxy
|
||||
if host.get('proxyid') and host['proxyid'] != '0':
|
||||
print(f"PROXY ID: {host['proxyid']}")
|
||||
else:
|
||||
print("PROXY: (monitored directly by server)")
|
||||
print()
|
||||
|
||||
|
||||
# Macros
|
||||
print("MACROS:")
|
||||
if host['macros']:
|
||||
for macro in host['macros']:
|
||||
value = macro['value']
|
||||
if macro.get('type') == '1': # Secret macro
|
||||
value = '******'
|
||||
else:
|
||||
value = macro.get('value', '(no value)')
|
||||
print(f" {macro['macro']} = {value}")
|
||||
else:
|
||||
print(" (none)")
|
||||
print()
|
||||
|
||||
|
||||
print("=" * 80)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(f"Usage: {sys.argv[0]} <hostname>")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
hostname = sys.argv[1]
|
||||
|
||||
|
||||
# Initialize API
|
||||
zapi = ZabbixAPI(ZABBIX_URL, ZABBIX_TOKEN)
|
||||
|
||||
|
||||
# Get host configuration
|
||||
host = zapi.get_host_config(hostname)
|
||||
|
||||
|
||||
if host:
|
||||
format_host_info(host)
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
Reference in new issue
Block a user