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.
29 ###############################################################################
30 # Functions to build up commandList contents
31 ###############################################################################
33 "return a provideThrottlingState command"
35 {'commandType': 'provideThrottlingState'}}
37 def command_interval(interval):
38 "return a measurementIntervalChange command"
40 {'commandType': 'measurementIntervalChange',
41 'measurementInterval': interval}}
43 def command_throttle(domain, fields, pairs):
44 "return a throttlingSpecification"
45 throttle_spec = {'eventDomain' : domain}
47 throttle_spec['suppressedFieldNames'] = fields
49 throttle_spec['suppressedNvPairsList'] = pairs
51 {'commandType': 'throttlingSpecification',
52 'eventDomainThrottleSpecification': throttle_spec}}
54 def command_nvpairs(field_name, pair_names):
55 "return a suppressedNvPairs"
56 return {'nvPairFieldName' : field_name,
57 'suppressedNvPairNames' : pair_names}
59 ###############################################################################
60 # Example functions to build up commandLists for various domains.
61 ###############################################################################
62 def command_list_empty():
63 return {'commandList' : []}
65 def command_list_provide():
66 return {'commandList' : [command_state()]}
68 def command_list_interval(interval):
69 return {'commandList' : [command_interval(interval)]}
71 def command_list_fault_suppress_fields():
72 "Throttling Specification - two suppressedFieldNames"
73 fields = ['alarmInterfaceA', 'alarmAdditionalInformation']
75 command_list = [command_throttle('fault', fields, pairs)]
76 return {'commandList' : command_list}
78 def command_list_fault_suppress_nothing():
79 "Throttling Specification - no suppression"
82 command_list = [command_throttle('fault', fields, pairs)]
83 return {'commandList' : command_list}
85 def command_list_fault_suppress_pairs():
86 "Throttling Specification - two suppressedNvPairNames"
88 pairs = [command_nvpairs('alarmAdditionalInformation',
90 command_list = [command_throttle('fault', fields, pairs)]
91 return {'commandList' : command_list}
93 def command_list_fault_suppress_fields_and_pairs():
94 "Throttling Specification - a mixture of fields and pairs"
95 fields = ['alarmInterfaceA']
96 pairs = [command_nvpairs('alarmAdditionalInformation',
98 command_list = [command_throttle('fault', fields, pairs)]
99 return {'commandList' : command_list}
101 def command_list_measurements_suppress_example():
102 "Throttling Specification - measurements"
103 fields = ['numberOfMediaPortsInUse', 'aggregateCpuUsage']
104 pairs = [command_nvpairs('cpuUsageArray',
106 command_list = [command_throttle('measurementsForVfScaling',
108 return {'commandList' : command_list}
110 def command_list_mobile_flow_suppress_example():
111 "Throttling Specification - mobile flow"
112 fields = ['radioAccessTechnology', 'samplingAlgorithm']
114 command_list = [command_throttle('mobileFlow', fields, pairs)]
115 return {'commandList' : command_list}
117 def command_list_state_change_suppress_example():
118 "Throttling Specification - state change"
119 fields = ['reportingEntityId', 'eventType', 'sourceId']
120 pairs = [command_nvpairs('additionalFields', ['Name1'])]
121 command_list = [command_throttle('stateChange', fields, pairs)]
122 return {'commandList' : command_list}
124 def command_list_syslog_suppress_example():
125 "Throttling Specification - syslog"
126 fields = ['syslogFacility', 'syslogProc', 'syslogProcId']
127 pairs = [command_nvpairs('additionalFields', ['Name1', 'Name4'])]
128 command_list = [command_throttle('syslog', fields, pairs)]
129 return {'commandList' : command_list}
131 def command_list_reset_all_domains():
132 "Throttling Specification - reset all domains"
133 command_list = [command_throttle('fault', [], []),
134 command_throttle('measurementsForVfScaling', [], []),
135 command_throttle('mobileFlow', [], []),
136 command_throttle('stateChange', [], []),
137 command_throttle('syslog', [], [])]
138 return {'commandList' : command_list}
141 fields = ['alarmInterfaceA']
142 pairs = [command_nvpairs('alarmAdditionalInformation',
144 command_list = [command_throttle('fault', fields, pairs),
145 command_interval(10),
147 return {'commandList' : command_list}
149 ###############################################################################
150 # Default command line values
151 ###############################################################################
152 DEFAULT_FQDN = "127.0.0.1"
155 ###############################################################################
156 # Command Line Parsing
157 ###############################################################################
158 parser = optparse.OptionParser()
159 parser.add_option('--fqdn',
162 default=DEFAULT_FQDN)
163 parser.add_option('--port',
166 default=DEFAULT_PORT,
168 options, remainder = parser.parse_args()
170 ###############################################################################
171 # Derive the Test Control URL
172 ###############################################################################
173 url = 'http://%s:%d/testControl/v1.1/commandList'%(options.fqdn, options.port)
175 ###############################################################################
176 # Create JSON and POST it to the Test Control URL.
177 ###############################################################################
178 command_list = command_list_fault_suppress_fields_and_pairs()
179 requests.post(url, json = command_list)