| 
									
										
										
										
											2018-11-24 11:11:27 -08:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Adjusts the testnet monitor dashboard for the specified release channel | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import json | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if len(sys.argv) != 3: | 
					
						
							|  |  |  |     print('Error: Dashboard or Channel not specified') | 
					
						
							|  |  |  |     sys.exit(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | dashboard_json = sys.argv[1] | 
					
						
							|  |  |  | channel = sys.argv[2] | 
					
						
							|  |  |  | if channel not in ['edge', 'beta', 'stable']: | 
					
						
							|  |  |  |     print('Error: Unknown channel:', channel) | 
					
						
							|  |  |  |     sys.exit(2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with open(dashboard_json, 'r') as read_file: | 
					
						
							|  |  |  |     data = json.load(read_file) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if channel == 'stable': | 
					
						
							|  |  |  |     # Stable dashboard only allows the user to select between the stable | 
					
						
							|  |  |  |     # testnet databases | 
					
						
							|  |  |  |     data['title'] = 'Testnet Monitor' | 
					
						
							|  |  |  |     data['uid'] = 'testnet' | 
					
						
							| 
									
										
										
										
											2019-04-25 21:14:36 -07:00
										 |  |  |     data['templating']['list'] = [{'current': {'text': '$datasource', | 
					
						
							|  |  |  |                                                'value': '$datasource'}, | 
					
						
							|  |  |  |                                    'hide': 1, | 
					
						
							|  |  |  |                                    'label': 'Data Source', | 
					
						
							|  |  |  |                                    'name': 'datasource', | 
					
						
							|  |  |  |                                    'options': [], | 
					
						
							|  |  |  |                                    'query': 'influxdb', | 
					
						
							|  |  |  |                                    'refresh': 1, | 
					
						
							|  |  |  |                                    'regex': '', | 
					
						
							|  |  |  |                                    'type': 'datasource'}, | 
					
						
							|  |  |  |                                   {'allValue': None, | 
					
						
							| 
									
										
										
										
											2018-11-24 11:11:27 -08:00
										 |  |  |                                    'current': {'text': 'testnet', | 
					
						
							|  |  |  |                                                'value': 'testnet'}, | 
					
						
							|  |  |  |                                    'hide': 1, | 
					
						
							|  |  |  |                                    'includeAll': False, | 
					
						
							|  |  |  |                                    'label': 'Testnet', | 
					
						
							|  |  |  |                                    'multi': False, | 
					
						
							|  |  |  |                                    'name': 'testnet', | 
					
						
							|  |  |  |                                    'options': [{'selected': False, | 
					
						
							|  |  |  |                                                 'text': 'testnet', | 
					
						
							|  |  |  |                                                 'value': 'testnet'}, | 
					
						
							|  |  |  |                                                {'selected': True, | 
					
						
							|  |  |  |                                                 'text': 'testnet-perf', | 
					
						
							|  |  |  |                                                 'value': 'testnet-perf'}], | 
					
						
							|  |  |  |                                    'query': 'testnet,testnet-perf', | 
					
						
							|  |  |  |                                    'type': 'custom'}] | 
					
						
							|  |  |  | else: | 
					
						
							|  |  |  |     # Non-stable dashboard only allows the user to select between all testnet | 
					
						
							|  |  |  |     # databases | 
					
						
							|  |  |  |     data['title'] = 'Testnet Monitor ({})'.format(channel) | 
					
						
							|  |  |  |     data['uid'] = 'testnet-' + channel | 
					
						
							| 
									
										
										
										
											2019-04-25 21:14:36 -07:00
										 |  |  |     data['templating']['list'] = [{'current': {'text': '$datasource', | 
					
						
							|  |  |  |                                                'value': '$datasource'}, | 
					
						
							|  |  |  |                                    'hide': 1, | 
					
						
							|  |  |  |                                    'label': 'Data Source', | 
					
						
							|  |  |  |                                    'name': 'datasource', | 
					
						
							|  |  |  |                                    'options': [], | 
					
						
							|  |  |  |                                    'query': 'influxdb', | 
					
						
							|  |  |  |                                    'refresh': 1, | 
					
						
							|  |  |  |                                    'regex': '', | 
					
						
							|  |  |  |                                    'type': 'datasource'}, | 
					
						
							|  |  |  |                                    {'allValue': ".*", | 
					
						
							| 
									
										
										
										
											2018-11-24 11:11:27 -08:00
										 |  |  |                                    'current': {'text': 'testnet', | 
					
						
							|  |  |  |                                                'value': 'testnet'}, | 
					
						
							| 
									
										
										
										
											2019-04-25 21:14:36 -07:00
										 |  |  |                                    'datasource': '$datasource', | 
					
						
							| 
									
										
										
										
											2018-11-24 11:11:27 -08:00
										 |  |  |                                    'hide': 1, | 
					
						
							|  |  |  |                                    'includeAll': False, | 
					
						
							|  |  |  |                                    'label': 'Testnet', | 
					
						
							|  |  |  |                                    'multi': False, | 
					
						
							|  |  |  |                                    'name': 'testnet', | 
					
						
							|  |  |  |                                    'options': [], | 
					
						
							|  |  |  |                                    'query': 'show databases', | 
					
						
							|  |  |  |                                    'refresh': 1, | 
					
						
							|  |  |  |                                    'regex': 'testnet.*', | 
					
						
							|  |  |  |                                    'sort': 1, | 
					
						
							|  |  |  |                                    'tagValuesQuery': '', | 
					
						
							|  |  |  |                                    'tags': [], | 
					
						
							|  |  |  |                                    'tagsQuery': '', | 
					
						
							|  |  |  |                                    'type': 'query', | 
					
						
							| 
									
										
										
										
											2018-12-12 06:06:33 -08:00
										 |  |  |                                    'useTags': False}, | 
					
						
							| 
									
										
										
										
											2019-04-09 15:28:25 -07:00
										 |  |  |                                    {'allValue': ".*", | 
					
						
							| 
									
										
										
										
											2019-04-25 21:14:36 -07:00
										 |  |  |                                     'datasource': '$datasource', | 
					
						
							| 
									
										
										
										
											2018-12-12 06:06:33 -08:00
										 |  |  |                                     'hide': 0, | 
					
						
							| 
									
										
										
										
											2018-12-12 12:38:00 -08:00
										 |  |  |                                     'includeAll': True, | 
					
						
							| 
									
										
										
										
											2018-12-12 06:06:33 -08:00
										 |  |  |                                     'label': 'HostID', | 
					
						
							|  |  |  |                                     'multi': False, | 
					
						
							|  |  |  |                                     'name': 'hostid', | 
					
						
							|  |  |  |                                     'options': [], | 
					
						
							| 
									
										
										
										
											2018-12-12 12:38:00 -08:00
										 |  |  |                                     'query': 'SELECT DISTINCT(\"host_id\") FROM \"$testnet\".\"autogen\".\"counter-fullnode-new\" ', | 
					
						
							| 
									
										
										
										
											2018-12-12 06:06:33 -08:00
										 |  |  |                                     'refresh': 2, | 
					
						
							|  |  |  |                                     'regex': '', | 
					
						
							|  |  |  |                                     'sort': 1, | 
					
						
							|  |  |  |                                     'tagValuesQuery': '', | 
					
						
							|  |  |  |                                     'tags': [], | 
					
						
							|  |  |  |                                     'tagsQuery': '', | 
					
						
							|  |  |  |                                     'type': 'query', | 
					
						
							|  |  |  |                                     'useTags': False}] | 
					
						
							| 
									
										
										
										
											2018-11-24 11:11:27 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | with open(dashboard_json, 'w') as write_file: | 
					
						
							|  |  |  |     json.dump(data, write_file, indent=2) |