forked from allburov/zabbixtools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ZabbixAgentYAMLtoJSON.py
48 lines (33 loc) · 1.08 KB
/
ZabbixAgentYAMLtoJSON.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Aleksey Burov, DevOpsHG
# This script get convert YAML to JSON and send to Zabbix.
import yaml
import json
from ZabbixCommon import parser, DebugMsg
import ZabbixCommon
@PtZabbixCommon.MainDecorator
def Main(pathToFile):
with open(pathToFile, 'r') as f:
yamlData = yaml.load(f)
data = yamlData['data']
yamlDataNew = {'data': []}
dataNew = yamlDataNew['data']
# Перебираем каждый элемент
for item in data:
dict = {}
# Изменяем каждый ключ с KEYNAME на {#KEYNAME} (требует Zabbix)
for key in item:
newkey = "{{#{}}}".format(key.upper())
dict[newkey] = item[key]
dataNew.append(dict)
jsonData = json.dumps(yamlDataNew)
DebugMsg("JSON data is:")
print(jsonData)
if __name__ == "__main__":
parser.add_argument("-f", "--PathToFile", help="Path to yaml file", required=True)
args = parser.parse_args()
PtZabbixCommon.Debug = args.verbose
Main(
args.PathToFile
)