CimTests¶
TestTemplates¶
Includes the test scenarios to check the CIM compatibility of an Add-on.
CIMTestTemplates
¶
Bases: object
Test scenarios to check the CIM compatibility of an Add-on Supported Test scenarios:
- The eventtype should extract all required fields of data model
- One eventtype should not be mapped with more than one data model
- Field Cluster should be verified (should be included with required field test)
- Verify if CIM installed or not
- Not Allowed Fields should not be extracted
Source code in pytest_splunk_addon/cim_tests/test_templates.py
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
|
test_cim_fields_not_allowed_in_props(splunk_ingest_data, splunk_setup, splunk_searchtime_cim_fields_not_allowed_in_props, record_property)
¶
This testcase checks for cim field of type [“not_allowed_in_search_and_props”, “not_allowed_in_props”] if an extraction is defined in the configuration file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splunk_ingest_data |
fixture
|
Ensure data was ingested before running test |
required |
splunk_setup |
fixture
|
Ensure that test environment was set up before running test |
required |
splunk_searchtime_cim_fields_not_allowed_in_props |
fixture
|
Object which contain list of fields not allowed in props |
required |
record_property |
fixture
|
Document facts of test cases to provide more info in the test failure reports. |
required |
Source code in pytest_splunk_addon/cim_tests/test_templates.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
test_cim_fields_not_allowed_in_search(splunk_ingest_data, splunk_search_util, splunk_setup, splunk_searchtime_cim_fields_not_allowed_in_search, record_property)
¶
This test case checks the event_count for the cim fields of type [“not_allowed_in_search_and_props”, “not_allowed_in_search”]. - Expected event_count for these fields is zero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splunk_ingest_data |
fixture
|
Ensure data was ingested before running test |
required |
splunk_search_util |
SearchUtil
|
Object that helps to search on Splunk. |
required |
splunk_setup |
fixture
|
Ensure that test environment was set up before running test |
required |
splunk_searchtime_cim_fields_not_allowed_in_search |
fixture
|
Object which contain list of fields not_allowed_in_search |
required |
record_property |
fixture
|
Document facts of test cases to provide more info in the test failure reports. |
required |
Source code in pytest_splunk_addon/cim_tests/test_templates.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
test_cim_fields_recommended(splunk_dm_recommended_fields, splunk_searchtime_cim_fields_recommended)
¶
This test case check that all the recommended cim fields of datamodel mapped with event are extracted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splunk_dm_recommended_fields |
fixture
|
function which gets recommended fields for given datamodel |
required |
splunk_searchtime_cim_fields_recommended |
fixture
|
pytest parameters to test. |
required |
Source code in pytest_splunk_addon/cim_tests/test_templates.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
|
test_cim_required_fields(splunk_search_util, splunk_ingest_data, splunk_setup, splunk_searchtime_cim_fields, record_property)
¶
Test the the required fields in the data models are extracted with valid values. Supports 3 scenarios. The test order is maintained for better test report.
- Check that there is at least 1 event mapped with the data model
- Check that each required field is extracted in all of the events mapped with the data model.
- Check that if there are inter dependent fields, either all fields should be
extracted or none of them should be extracted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splunk_search_util |
SearchUtil
|
Object that helps to search on Splunk. |
required |
splunk_ingest_data |
fixture
|
Ensure data was ingested before running test |
required |
splunk_setup |
fixture
|
Ensure that test environment was set up before running test |
required |
splunk_searchtime_cim_fields |
fixture
|
Pytest parameter to test required cim field extraction |
required |
record_property |
fixture
|
Document facts of test cases to provide more info in the test failure reports. |
required |
Source code in pytest_splunk_addon/cim_tests/test_templates.py
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 |
|
test_eventtype_mapped_multiple_cim_datamodel(splunk_search_util, splunk_ingest_data, splunk_setup, splunk_searchtime_cim_mapped_datamodel, record_property, caplog)
¶
This test case check that event type is not be mapped with more than one data model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splunk_search_util |
SearchUtil
|
Object that helps to search on Splunk. |
required |
splunk_ingest_data |
fixture
|
Ensure data was ingested before running test |
required |
splunk_setup |
fixture
|
Ensure that test environment was set up before running test |
required |
splunk_searchtime_cim_mapped_datamodel |
fixture
|
Object which contain eventtype list |
required |
record_property |
fixture
|
Document facts of test cases to provide more info in the test failure reports. |
required |
caplog |
fixture
|
fixture to capture logs. |
required |
Source code in pytest_splunk_addon/cim_tests/test_templates.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|
TestGenerator¶
Generates test cases to verify the CIM compatibility .
CIMTestGenerator
¶
Bases: object
Generates test cases to verify the CIM compatibility.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addon_path |
str
|
Relative or absolute path to the add-on |
required |
data_model_path |
str
|
Relative or absolute path to the data model json files |
required |
test_field_type |
list
|
For which types of fields, the test cases should be generated |
['required', 'conditional']
|
common_fields_path |
str
|
Relative or absolute path of the json file with common fields |
None
|
Source code in pytest_splunk_addon/cim_tests/test_generator.py
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
generate_cim_fields_tests()
¶
Generates the test cases for required/conditional/cluster fields.
- List CIM mapped models
- Iterate through each field in CIM data model
- Generate & Yield pytest.param for each test case
- Include the cluster test case as well.
Source code in pytest_splunk_addon/cim_tests/test_generator.py
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 |
|
generate_field_extractions_test()
¶
Generate tests for the fields which the extractions are not allowed in props.conf
- Get a list of fields of type in [“not_allowed_in_search_and_props”, “not_allowed_in_props”] from common fields json.
- Get a list of fields whose extractions are defined in props.
- Compare and get the list of fields whose extractions are not allowed but defined.
- yield the field list
Source code in pytest_splunk_addon/cim_tests/test_generator.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
generate_fields_event_count_test()
¶
Generates the tests which should not be extracted in an add-on
- Get the list of type=[“not_allowed_in_search_and_props”, “not_allowed_in_search”] fields from common fields json.
- Get the list of type=[“not_allowed_in_search_and_props”, “not_allowed_in_search”] fields from mapped datasets.
- Combine list1 and list2
- yield the field list
- Expected event_count for the fields: 0
Source code in pytest_splunk_addon/cim_tests/test_generator.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
generate_mapped_datamodel_tests()
¶
Generates the tests to check event type is not be mapped with more than one data model
- Get a list of eventtype which defined in eventtype configuration.
- yield the eventtype list
Source code in pytest_splunk_addon/cim_tests/test_generator.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
generate_recommended_fields_tests()
¶
Generates the tests to check all the recommended cim fields of the mapped data model are extracted.
- Get a list of fields defined in cim_fields and missing_recommended_fields
- combine the fields list with the defined exceptions
- yield object with datamodel, dataset, cim_version and list of fields
Source code in pytest_splunk_addon/cim_tests/test_generator.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
generate_tests(fixture)
¶
Generate the test cases based on the fixture provided
supported fixtures:
* splunk_searchtime_cim_fields
* splunk_searchtime_cim_fields_not_allowed
* splunk_searchtime_cim_fields_not_extracted
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fixture |
str
|
fixture name |
required |
Source code in pytest_splunk_addon/cim_tests/test_generator.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
get_common_fields(test_type=[])
¶
To obtain list object of common fields mentioned in COMMON_FIELDS_PATH
Source code in pytest_splunk_addon/cim_tests/test_generator.py
233 234 235 236 237 238 239 240 241 242 243 244 |
|
get_mapped_datasets()
¶
Get all mapped data_sets for each tags stanza from an add-on
Yields:
Name | Type | Description |
---|---|---|
tuple |
Tag Stanza, mapped DataSet |
Source code in pytest_splunk_addon/cim_tests/test_generator.py
90 91 92 93 94 95 96 97 |
|
DataModelHandler¶
Provides Data Model handling functionalities. Such as
- Parse all the data model JSON files
- Get Mapped data model for an eventtype
DataModelHandler
¶
Bases: object
Provides Data Model handling functionalities. Such as
- Parse all the data model JSON files
- Get Mapped data model for an eventtype
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_model_path |
str
|
path to the data model JSON files |
required |
Source code in pytest_splunk_addon/cim_tests/data_model_handler.py
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 |
|
get_mapped_data_models(addon_parser)
¶
Get list of eventtypes mapped with Data-Sets. The reason addon_parser is an argument & not attribute of the class is that, the loaded handler should be used with multiple addons.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addon_parser |
AddonParser
|
Object of Addon_parser |
required |
Yields:
Type | Description |
---|---|
tag stanza mapped with list of data sets “eventtype=sample”, DataSet(performance) |
Source code in pytest_splunk_addon/cim_tests/data_model_handler.py
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 |
|
load_data_models(data_model_path)
¶
Parse all the data model JSON files one by one
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_model_path |
str
|
path to the datamodel schema json file |
required |
Yields:
Type | Description |
---|---|
DataModel
|
parsed data model object |
Source code in pytest_splunk_addon/cim_tests/data_model_handler.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
|
DataModel¶
Includes DataModel class which handles the DataSets within a data model.
DataModel
¶
Bases: object
Handles the DataSets within a data model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_model_json(dict) |
Dictionary of the data model Json file |
required |
Source code in pytest_splunk_addon/cim_tests/data_model.py
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 |
|
get_mapped_datasets(addon_tags)
¶
Get all mapped dataSets for an Add-on’s tags stanza
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addon_tags |
list
|
Contains tags mapped to a stanza |
required |
Yields:
Type | Description |
---|---|
data_set.DataSet: data set object mapped with the tags |
Source code in pytest_splunk_addon/cim_tests/data_model.py
60 61 62 63 64 65 66 67 68 69 70 |
|
DataSet¶
Includes DataSet class which handles a single data set
DataSet
¶
Bases: object
Handles a single data set
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_set_json |
dict
|
Json of a single DataSet |
required |
data_model |
str
|
Name of the data model |
required |
Source code in pytest_splunk_addon/cim_tests/data_set.py
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 |
|
load_dataset(dataset_list, data_model)
classmethod
¶
Parse all the fields from the data_model_json
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_list |
list
|
Contains list of datasets |
required |
data_model |
str
|
Name of the data model |
required |
Yields:
Type | Description |
---|---|
data_set.DataSet: Dataset object for the given list |
Source code in pytest_splunk_addon/cim_tests/data_set.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
match_tags(addon_tag_list)
¶
Check if the tags are mapped with this data set
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addon_tag_list |
list
|
list of tags defined in the addon |
required |
Source code in pytest_splunk_addon/cim_tests/data_set.py
94 95 96 97 98 99 100 101 102 103 |
|
FieldTestAdapter¶
FieldTestAdapter
¶
Bases: Field
Field adapter to include the testing related properties on top of Field
Properties:
- valid_field (str): New field generated which can only have the valid values
- invalid_field (str): New field generated which can only have the invalid values
- validity_query (str): The query which extracts the valid_field out of the field
Source code in pytest_splunk_addon/cim_tests/field_test_adapter.py
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 |
|
gen_validity_query()
¶
Generate validation search query::
| eval valid_field = <validity>
| eval valid_field = if(searchmatch(valid_field in <expected_values>), valid_field, null())
| eval valid_field = if(searchmatch(valid_field in <negative_values>), null(), valid_field)
| eval invalid_field=if(isnull(valid_field),field, null())
Source code in pytest_splunk_addon/cim_tests/field_test_adapter.py
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 |
|
get_query_from_values(values)
staticmethod
¶
List of values into SPL list
Example:: [“a”, “b”] to ‘“a”, “b”’
Parameters:
Name | Type | Description | Default |
---|---|---|---|
values |
list
|
List of str values |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
SPL query list |
Source code in pytest_splunk_addon/cim_tests/field_test_adapter.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
get_stats_query()
¶
Generate stats search query::
count(field) as field_count, count(valid_field) as valid_field_count,
values(invalid_field) as invalid_values
Source code in pytest_splunk_addon/cim_tests/field_test_adapter.py
99 100 101 102 103 104 105 106 107 108 109 110 |
|
FieldTestHelper¶
Provides the helper methods to test addon_parser.Field object
FieldTestHelper
¶
Bases: object
Provides the helper methods to test addon_parser.Field object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_util |
SearchUtil
|
the util class to search on the Splunk instance |
required |
fields |
list addon_parser.Field
|
The field to be tested |
required |
interval |
int
|
at what interval each retry should be made |
10
|
retries |
int
|
number of retries to make if no results found |
4
|
Source code in pytest_splunk_addon/cim_tests/field_test_helper.py
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 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
format_exc_message()
¶
Format the exception message to display
1) There’s no field in the result::
Source Sourcetype Event Count
-------------------------------------------
splunkd.log splunkd 10
scheduler.log scheduler 0
-------------------------------------------
Search = <search query>
2) There are multiple fields in the result::
Source Sourcetype Field Event Count Field Count Invalid Field Count Invalid Values
------------------------------------------------------------------------------------------------
splunkd.log splunkd One 10 10 5 'unknown'
scheduler.log scheduler Two 20 20 7 '-', 'invalid'
------------------------------------------------------------------------------------------------
Event count = 20
Search = <search_query>
Properties for the field :: One
. . .
Source code in pytest_splunk_addon/cim_tests/field_test_helper.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
test_field(base_search, record_property=None)
¶
Generate a query for the list of fields and return the result
Format of the query is::
<condition>
| eval <validity>
| eval <expected_values>
| eval <not negative_values>
| eval <invalid_fields>
| stats count as event_count, count(field) as field_count,
count(valid_field) as valid_field_count,
values(invalid_field) by sourcetype, source
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_search |
str
|
Base search. Must be a search command. |
required |
record_property |
fixture
|
Document facts of test cases. |
None
|
Yields:
Name | Type | Description |
---|---|---|
dict |
with source, sourcetype, field, event_count, field_count, valid_field_count, invalid_values keys |
Source code in pytest_splunk_addon/cim_tests/field_test_helper.py
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 |
|
JsonSchema¶
Includes JSON schema for data models
JSONSchema
¶
Bases: BaseSchema
JsonSchema + Parser of the Data model json files
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_path |
str
|
Relative or absolute path of the schema file |
None
|
Source code in pytest_splunk_addon/cim_tests/json_schema.py
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 |
|
parse_data_model(file_path)
classmethod
¶
Parse and validate the Json file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_path |
str
|
Relative or absolute path of the data model json file |
required |
Source code in pytest_splunk_addon/cim_tests/json_schema.py
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 |
|
BaseSchema¶
Includes base class for data model schema.
BaseSchema
¶
Bases: ABC
Abstract class to parse the Data model files. The possible format can be JSON, YML, CSV, Cim_json
Source code in pytest_splunk_addon/cim_tests/base_schema.py
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 |
|
parse_data_model(file_path)
¶
Parse the DataModel file Convert it to JSON
Expected Output::
{
"name":"Default_Authentication",
"tags": ["authentication","default"],
"fields_cluster":[],
"fields":[
{
"fieldname": "action",
"field_type": "required",
"condition": "action IN ('success','failure','error')",
"comment":"The action performed on the resource."
},
],
"child_dataset": [
{
"name":"SuccessFul_Default_Authentication",
"tags": ["authentication","default"],
"fields_cluster":[],
"fields":[]
"child_dataset":[],
"search_constraints": "action='success'"
}
],
"search_constraints":"action='failure'"
}
Source code in pytest_splunk_addon/cim_tests/base_schema.py
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 |
|