3 Example script to inject a throttling command list to the test_collector.
5 Only intended for test purposes.
10 * ===================================================================
11 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
12 * ===================================================================
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
17 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
30 ###############################################################################
31 # Functions to build up commandList contents
32 ###############################################################################
34 "return a provideThrottlingState command"
36 {'commandType': 'provideThrottlingState'}}
38 def command_interval(interval):
39 "return a measurementIntervalChange command"
41 {'commandType': 'measurementIntervalChange',
42 'measurementInterval': interval}}
44 def command_throttle(domain, fields, pairs):
45 "return a throttlingSpecification"
46 throttle_spec = {'eventDomain' : domain}
48 throttle_spec['suppressedFieldNames'] = fields
50 throttle_spec['suppressedNvPairsList'] = pairs
52 {'commandType': 'throttlingSpecification',
53 'eventDomainThrottleSpecification': throttle_spec}}
55 def command_nvpairs(field_name, pair_names):
56 "return a suppressedNvPairs"
57 return {'nvPairFieldName' : field_name,
58 'suppressedNvPairNames' : pair_names}
60 ###############################################################################
61 # Example functions to build up commandLists for various domains.
62 ###############################################################################
63 def command_list_empty():
64 return {'commandList' : []}
66 def command_list_provide():
67 return {'commandList' : [command_state()]}
69 def command_list_interval(interval):
70 return {'commandList' : [command_interval(interval)]}
72 def command_list_fault_suppress_fields():
73 "Throttling Specification - two suppressedFieldNames"
74 fields = ['alarmInterfaceA', 'alarmAdditionalInformation']
76 command_list = [command_throttle('fault', fields, pairs)]
77 return {'commandList' : command_list}
79 def command_list_fault_suppress_nothing():
80 "Throttling Specification - no suppression"
83 command_list = [command_throttle('fault', fields, pairs)]
84 return {'commandList' : command_list}
86 def command_list_fault_suppress_pairs():
87 "Throttling Specification - two suppressedNvPairNames"
89 pairs = [command_nvpairs('alarmAdditionalInformation',
91 command_list = [command_throttle('fault', fields, pairs)]
92 return {'commandList' : command_list}
94 def command_list_fault_suppress_fields_and_pairs():
95 "Throttling Specification - a mixture of fields and pairs"
96 fields = ['alarmInterfaceA']
97 pairs = [command_nvpairs('alarmAdditionalInformation',
99 command_list = [command_throttle('fault', fields, pairs)]
100 return {'commandList' : command_list}
102 def command_list_measurements_suppress_example():
103 "Throttling Specification - measurements"
104 fields = ['numberOfMediaPortsInUse', 'aggregateCpuUsage']
105 pairs = [command_nvpairs('cpuUsageArray',
107 command_list = [command_throttle('measurementsForVfScaling',
109 return {'commandList' : command_list}
111 def command_list_mobile_flow_suppress_example():
112 "Throttling Specification - mobile flow"
113 fields = ['radioAccessTechnology', 'samplingAlgorithm']
115 command_list = [command_throttle('mobileFlow', fields, pairs)]
116 return {'commandList' : command_list}
118 def command_list_state_change_suppress_example():
119 "Throttling Specification - state change"
120 fields = ['reportingEntityId', 'eventType', 'sourceId']
121 pairs = [command_nvpairs('additionalFields', ['Name1'])]
122 command_list = [command_throttle('stateChange', fields, pairs)]
123 return {'commandList' : command_list}
125 def command_list_syslog_suppress_example():
126 "Throttling Specification - syslog"
127 fields = ['syslogFacility', 'syslogProc', 'syslogProcId']
128 pairs = [command_nvpairs('additionalFields', ['Name1', 'Name4'])]
129 command_list = [command_throttle('syslog', fields, pairs)]
130 return {'commandList' : command_list}
132 def command_list_reset_all_domains():
133 "Throttling Specification - reset all domains"
134 command_list = [command_throttle('fault', [], []),
135 command_throttle('measurementsForVfScaling', [], []),
136 command_throttle('mobileFlow', [], []),
137 command_throttle('stateChange', [], []),
138 command_throttle('syslog', [], [])]
139 return {'commandList' : command_list}
142 fields = ['alarmInterfaceA']
143 pairs = [command_nvpairs('alarmAdditionalInformation',
145 command_list = [command_throttle('fault', fields, pairs),
146 command_interval(10),
148 return {'commandList' : command_list}
150 ###############################################################################
151 # Default command line values
152 ###############################################################################
153 DEFAULT_FQDN = "127.0.0.1"
156 ###############################################################################
157 # Command Line Parsing
158 ###############################################################################
159 parser = optparse.OptionParser()
160 parser.add_option('--fqdn',
163 default=DEFAULT_FQDN)
164 parser.add_option('--port',
167 default=DEFAULT_PORT,
169 options, remainder = parser.parse_args()
171 ###############################################################################
172 # Derive the Test Control URL
173 ###############################################################################
174 url = 'http://%s:%d/testControl/v1.1/commandList'%(options.fqdn, options.port)
176 ###############################################################################
177 # Create JSON and POST it to the Test Control URL.
178 ###############################################################################
179 command_list = command_list_fault_suppress_fields_and_pairs()
180 requests.post(url, json = command_list)