Ansible Script 추가

This commit is contained in:
ByeonJungHun
2023-12-19 13:36:16 +09:00
parent 0273450ff6
commit 05cb8d9269
2610 changed files with 281893 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
import os
from zabbix_api import ZabbixAPI
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('zabbix_agent')
def authenticate():
zapi = ZabbixAPI(server='http://zabbix-server-centos/api_jsonrpc.php')
zapi.login("Admin", "zabbix")
return zapi
def test_psk_host(host):
zapi = authenticate()
hostname = host.check_output('hostname -s')
host_name = "zabbix-agent-ubuntu"
server_data = zapi.host.get({'output': 'extend', 'selectInventory': 'extend', 'filter': {'host': [hostname]}})
if hostname == host_name:
assert server_data[0]['tls_psk'] == "b7e3d380b9d400676d47198ecf3592ccd4795a59668aa2ade29f0003abbbd40d"
assert server_data[0]['tls_psk_identity'] == "myhost PSK"
assert server_data[0]['tls_accept'] == "2"
else:
assert server_data[0]['tls_psk'] == ""
assert server_data[0]['tls_psk_identity'] == ""
assert server_data[0]['tls_accept'] == "1"
def test_zabbix_agent_psk(host):
hostname = host.check_output('hostname -s')
host_name = "zabbix-agent-ubuntu"
psk_file = host.file("/etc/zabbix/zabbix_agent_pskfile.psk")
if hostname == host_name:
assert psk_file.user == "zabbix"
assert psk_file.group == "zabbix"
assert psk_file.mode == 0o400
assert psk_file.contains("b7e3d380b9d400676d47198ecf3592ccd4795a59668aa2ade29f0003abbbd40d")
else:
assert not psk_file.exists

View File

@@ -0,0 +1,41 @@
import os
from zabbix_api import ZabbixAPI
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('zabbix_server')
def authenticate():
zapi = ZabbixAPI(server='http://zabbix-server-centos/api_jsonrpc.php')
zapi.login("Admin", "zabbix")
return zapi
def get_hosts():
return [
"zabbix-agent-debian",
"zabbix-agent-ubuntu",
"zabbix-agent-centos",
"zabbix-agent-docker-centos"
]
def test_hosts():
zapi = authenticate()
hosts = get_hosts()
servers = zapi.host.get({'output': ["hostid", "name"]})
for server in servers:
if server['name'] != 'Zabbix server':
assert server['name'] in hosts
def test_hosts_status():
zapi = authenticate()
servers = zapi.host.get({'output': ["status", "name"]})
for server in servers:
if server['name'] != 'Zabbix server':
assert int(server['status']) == 0