Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import os
- import re
- import json
- import csv
- from datetime import datetime
- wd_path = os.getcwd()
- json_file = os.path.join(wd_path, 'event.json')
- with open(json_file, 'r') as f:
- j_result = json.load(f)
- csv_path = os.path.join(wd_path, 'event.csv')
- with open(csv_path, 'w') as f:
- writer = csv.writer(f,lineterminator='\n')
- for rec in j_result['result']:
- lst_data = []
- # clockを変換(unixtime -> date and time)
- s_date = datetime.fromtimestamp(int(rec['clock'])).date()
- s_time = datetime.fromtimestamp(int(rec['clock'])).time()
- # descriptionの不要部分削除
- int_name=re.sub(r'^.*interface|\ |\t','',rec['relatedObject']['description'])
- #
- if int(rec['value'])==0:
- continue ## value=OK skip
- lst_data.append(s_date)
- lst_data.append(s_time)
- lst_data.append(rec['relatedObject']['description'])
- lst_data.append(rec['hosts'][0]['name'])
- lst_data.append(int_name)
- lst_data.append(rec['value'])
- writer.writerow(lst_data)
Add Comment
Please, Sign In to add comment