-
Notifications
You must be signed in to change notification settings - Fork 0
/
jmp_main.py
executable file
·167 lines (153 loc) · 6.89 KB
/
jmp_main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#! /usr/bin/env python
#####################################################
# Test script for detecting JSB and add Zabbix #
# Host, Log items, screens #
#####################################################
import logging
import zabbix_api
import socket
import os
import sys
import json
import socket
import jmp_constants
from zabbix_api import ZabbixAPI, ZabbixAPIException
import jmp_zabbix
import jta_checker
#####################################################
#Set the log level and log file name
#####################################################
a = logging.basicConfig(filename='auto_discoverlog.log',level=logging.DEBUG)
logging.debug('Auto-discovery started running')
#####################################################
# Log onto Zabbix #
#####################################################
zabbix_info = jmp_zabbix.jmp_info('jmp.properties')
print "##########Zabbix_info#########"
print zabbix_info
print zabbix_info['jtaHostName']
z = jmp_zabbix.z_logging()
if z.test_login():
#print 'Auth is working'
logging.debug('authorized and gained access to zabbix')
else:
#print 'Auth did not work'
logging.debug(' no authorization nor gain access to zabbix')
hostgroup='JasperServers'
jasper_groupid = jmp_zabbix.get_jasper_groupid(z,hostgroup)
jta_list_hosts = jmp_zabbix.get_jasperhosts(z,jasper_groupid)
#print '###################HostList########################'
#print jta_list_hosts
logging.debug('###################HostList########################')
logging.debug(jta_list_hosts)
deployed_jta_list = jta_checker.get_apps_diff()
#host_interface = jmp_zabbix.get_hostinterface(z,jasper_groupid)
#print '###################deployed_apps########################'
#print deployed_jta_list['deployed_apps']
logging.debug('###################deployed_apps########################')
logging.debug(deployed_jta_list['deployed_apps'])
#####################################################
# Get the list of JTA applicaitons under #
# JTA server host == JTA-jasperServer-a #
#####################################################
host_jta_server = z.host.get(
{
'filter': { 'host': zabbix_info['jtaHostName']},
'output': 'extend'
})
jta_server_hostID=host_jta_server[0]['hostid']
host_interface = jmp_zabbix.get_interface(z,jta_server_hostID)
log_interfaceID = jmp_zabbix.get_interface(z,jta_server_hostID)
print "list of interfaces \n"
print log_interfaceID
#####################################################
# Check for the JTA's and add the missing ones #
#####################################################
deployed_jta_applicaiton_list = jmp_zabbix.get_jta_applicaiton_list(z,jta_server_hostID,"jta")
print deployed_jta_applicaiton_list
if not deployed_jta_list['deployed_apps']:
print "list empty noting to update \n"
else:
#start adding JTA hosts
for item in deployed_jta_list['deployed_apps']:
if item in deployed_jta_applicaiton_list:
print item
print "\n Item is already added"
logging.debug(item)
logging.debug("\n Item is already added")
continue
else:
#####################################################
# Add log items and the screens to display
# get host id
#####################################################
information = jmp_zabbix.z_info(zabbix_info['jsb_z_agent_conf'])
print "##############Information####################"
print information
#####################################################
# Add log item for the JTA-Log applicaiton
#####################################################
jta_log_applicaitonID = jmp_zabbix.get_jta_log_applicaitonID(z,jta_server_hostID)
print "######LOG-ApplicaitonID##############"
print jta_log_applicaitonID
#####################################################
#Get interface ID
#####################################################
jta_interfaceID = jmp_zabbix.get_interface(z,jta_server_hostID)
print "######Interface ID##############"
print jta_interfaceID
print jta_interfaceID[0]['interfaceid']
#####################################################
#Add log item to JTA_log applicaiotn in jasperServer-a
#####################################################
item_name = item + "-log"
key_value = "log[{$JTA_SVR_PATH}/logs/" + item + ".log]"
print "######Key value##############"
print key_value
jasper_itemID = z.item.create({
'name':item_name,
'key_':key_value,
'type':'7',
'interfaceid':jta_interfaceID[0]['interfaceid'],
'applications':[jta_log_applicaitonID],
'hostid':jta_server_hostID,
'value_type':'2',
'delay':'10'
})
#####################################################
# Create screen for the new JTA log
####################################################
jta_screen_name = item + 'logs'
JTA_log_screenID = z.screen.get(
{
'selectScreenItems':'extend',
'filter': { 'name': jta_screen_name},
'output': 'extend'
})
print JTA_log_screenID
screen_name = item + " log"
jta_log_screen = z.screen.create({
'name':screen_name,
'hsize':'1',
'vsize':'1',
})
jta_log_screen['screenids'] = [s.encode('utf-8') for s in jta_log_screen['screenids']]
print "#############ScreenID################"
print jta_log_screen['screenids'][0]
#####################################################
# Add new application to JTA-jasperServer-a host
#####################################################
jta_jmx_application_name = item+"-JMX"
new_jta_application = z.application.create({
'name':jta_jmx_application_name,
'hostid':jta_server_hostID
})
print "###### NEW applicaiton id##############"
print new_jta_application
new_jta_application['applicationids'] = [s.encode('utf-8') for s in new_jta_application['applicationids']]
new_jta_applicationID = new_jta_application['applicationids'][0]
print new_jta_applicationID
print jta_interfaceID[1]['interfaceid']
jta_jmx_interfaceID = jta_interfaceID[1]['interfaceid']
#jmp_zabbix.get_interface(z,jta_server_hostID)
jmp_zabbix.add_jta_jmx_items(z,item,jta_jmx_interfaceID,new_jta_applicationID,jta_server_hostID)