DataGenerator¶
PytestSplunkAddonDataParser¶
PytestSplunkAddonDataParser
¶
This class parses pytest-splunk-addon-data.conf file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addon_path |
str
|
Path to the Splunk App |
required |
config_path |
str
|
Path to the pytest-splunk-addon-data.conf |
required |
Source code in pytest_splunk_addon/sample_generation/pytest_splunk_addon_data_parser.py
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 |
|
get_sample_stanzas()
¶
Converts a stanza in pytest-splunk-addon-data.conf to an object of SampleStanza.
Returns:
Name | Type | Description |
---|---|---|
list |
List of SampleStanza objects. |
Source code in pytest_splunk_addon/sample_generation/pytest_splunk_addon_data_parser.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
test_unicode_char(filename)
¶
Function to check if the file contains unicode chars
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
name of the file to check |
required |
Raises:
Type | Description |
---|---|
ValueError
|
if file contains unicode chars |
Source code in pytest_splunk_addon/sample_generation/pytest_splunk_addon_data_parser.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
SampleStanza¶
SampleStanza
¶
Bases: object
This class represents a stanza of the pytest-splunk-addon-data.conf. It contains all the parameters for the stanza such as:
* Sample Name
* Tokens
* Sample file's raw data
* Tokenized events
* Sample ingestion type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_path |
str
|
Path to the sample file |
required |
psa_data_params |
dict
|
Dictionary representing pytest-splunk-addon-data.conf |
required |
Source code in pytest_splunk_addon/sample_generation/sample_stanza.py
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 |
|
break_events(sample_raw)
¶
Break sample file into list of raw events using breaker
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_raw |
str
|
Raw sample |
required |
Return
event_list (list): List of raw events
Source code in pytest_splunk_addon/sample_generation/sample_stanza.py
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 |
|
get_eventmetadata()
¶
Return the unique host metadata for event.
Source code in pytest_splunk_addon/sample_generation/sample_stanza.py
262 263 264 265 266 267 268 269 270 271 |
|
get_raw_events()
¶
Gets the raw events from the sample file.
Source code in pytest_splunk_addon/sample_generation/sample_stanza.py
58 59 60 61 62 63 |
|
get_tokenized_events()
¶
Yields the tokenized events
Source code in pytest_splunk_addon/sample_generation/sample_stanza.py
65 66 67 68 69 70 71 72 73 |
|
populate_requirement_test_data(event)
staticmethod
¶
Analyze event’s datamodels, cim_fields, missing_recommended_fields, exception
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event |
dict
|
event data from xml file |
required |
Return
requirement_test_data (dict): datamodels, cim_fields, missing_recommended_fields, exception
Source code in pytest_splunk_addon/sample_generation/sample_stanza.py
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 |
|
tokenize(conf_name)
¶
Tokenizes the raw events by replacing all the tokens in it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conf_name |
str
|
Name of the conf file, “psa-data-gen” |
required |
Source code in pytest_splunk_addon/sample_generation/sample_stanza.py
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 |
|
SampleEvent¶
SampleEvent
¶
Bases: object
This class represents an event which will be ingested in Splunk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event_string |
str
|
Event content |
required |
metadata |
dict
|
Contains metadata for the event |
required |
sample_name |
str
|
Name of the file containing this event |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
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 |
|
copy(event)
classmethod
¶
Copies the SampleEvent object into a new one. Args: event (SampleEvent): Event object which has to be copied
Returns:
Type | Description |
---|---|
Copy of the SampleEvent object |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
get_field_fqdn(rule)
¶
Returns unique fqdn value for the key fields src, dest, host, dvc
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
str
|
Type of rule either src, host, dest, dvc |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
get_field_host(rule)
¶
Returns unique host value for the key fields src, dest, host, dvc
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
str
|
Type of rule either src, host, dest, dvc |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
get_host()
¶
Returns a unique host value
Source code in pytest_splunk_addon/sample_generation/sample_event.py
83 84 85 86 87 88 89 90 91 92 93 94 |
|
get_ipv4(rule)
¶
Returns Ipv4 Address as per the rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
str
|
Type of rule either src, host, dest, dvc. |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
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 |
|
get_ipv6(rule)
¶
Returns Ipv6 Address as per the rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
str
|
Type of rule either src, host, dest, dvc. |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
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 |
|
get_key_fields()
¶
Returns the key field value from event
Source code in pytest_splunk_addon/sample_generation/sample_event.py
391 392 393 394 395 |
|
get_token_count(token)
¶
Returns the token count in event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
Token name |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
276 277 278 279 280 281 282 283 |
|
get_token_extractions_count(token)
¶
Returns minimum number of occurrence count if token not found in event but is in extracted fields
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
Token name |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
register_field_value(field, token_values)
¶
Registers the value for the key fields in its SampleEvent object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
Token field name |
required |
token_values |
list / str
|
Token value(s) which are replaced in the key fields |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
replace_token(token, token_values)
¶
Replaces the token value in event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
str
|
Token name |
required |
token_values |
list / str
|
Value(s) to be replaced in the token |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
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 |
|
update(new_event)
¶
This method updates the event content
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_event |
str
|
Event content |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
73 74 75 76 77 78 79 80 81 |
|
update_metadata(event, metadata, key_fields)
¶
Processes the syslog formated samples Format::
'***SPLUNK*** source=<source> sourcetype=<sourcetype> field_1 field2 field3 ##value1## ##value2## ##value3##'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
event |
str
|
event string containing raw syslog data |
required |
metadata |
dict
|
Contains metadata for the event |
required |
Returns:
Type | Description |
---|---|
Syslog event and the updated metadata |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
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 |
|
update_requirement_test_field(field, token, token_values)
¶
Function to update field value for requirement_test_data as per the token replacement
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field |
str
|
name of the field |
required |
token |
str
|
name of the token |
required |
token_values |
list / str
|
Token value(s) which are replaced in the key fields |
required |
Source code in pytest_splunk_addon/sample_generation/sample_event.py
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 |
|
Rule¶
Provides Rules for all possible replacements for tokens.
DestPortRule
¶
Bases: Rule
DestPortRule
Source code in pytest_splunk_addon/sample_generation/rule.py
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
|
replace(sample, token_count)
¶
Yields a random port value from [80, 443, 25, 22, 21]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 |
|
DestRule
¶
Bases: Rule
DestRule
Source code in pytest_splunk_addon/sample_generation/rule.py
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
|
replace(sample, token_count)
¶
Yields a random dest replacement value from the list of values mentioned in token. Possible values: [“host”, “ipv4”, “ipv6”, “fqdn”]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
|
DvcRule
¶
Bases: Rule
DvcRule
Source code in pytest_splunk_addon/sample_generation/rule.py
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
|
replace(sample, token_count)
¶
Yields a random dvc replacement value from the list of values mentioned in token. Possible values: [“host”, “ipv4”, “ipv6”, “fqdn”]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
|
EmailRule
¶
Bases: Rule
EmailRule
Source code in pytest_splunk_addon/sample_generation/rule.py
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 |
|
replace(sample, token_count)
¶
Yields a random email from lookups\user_email.csv file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 |
|
FileRule
¶
Bases: Rule
FileRule
Source code in pytest_splunk_addon/sample_generation/rule.py
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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
|
get_file_path()
¶
Returns the relative sample file path and index value
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
indexed_sample_file(sample, file_path, index, token_count)
¶
Yields the column value of token by reading files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
file_path |
str
|
path of the file mentioned in token. |
required |
index |
int
|
index value mentioned in file_path i.e. |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
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 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 |
|
lookupfile(sample, file_path, index, token_count)
¶
Yields the column value of token by reading files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
file_path |
str
|
path of the file mentioned in token. |
required |
index |
int
|
index value mentioned in file_path i.e. |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
|
replace(sample, token_count)
¶
Yields the values of token by reading files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
FloatRule
¶
Bases: Rule
FloatRule
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
replace(sample, token_count)
¶
Yields a random float no. between the range mentioned in token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
GuidRule
¶
Bases: Rule
GuidRule
Source code in pytest_splunk_addon/sample_generation/rule.py
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 |
|
replace(sample, token_count)
¶
Yields a random guid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
779 780 781 782 783 784 785 786 787 788 |
|
HexRule
¶
Bases: Rule
HexRule
Source code in pytest_splunk_addon/sample_generation/rule.py
1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
|
replace(sample, token_count)
¶
Yields a random hex value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
|
HostRule
¶
Bases: Rule
HostRule
Source code in pytest_splunk_addon/sample_generation/rule.py
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 |
|
replace(sample, token_count)
¶
Yields a random host replacement value from the list of values mentioned in token. Possible values: [“host”, “ipv4”, “ipv6”, “fqdn”]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 |
|
IntRule
¶
Bases: Rule
IntRule
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
replace(sample, token_count)
¶
Yields a random int between the range mentioned in token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
Ipv4Rule
¶
Bases: Rule
Ipv4Rule
Source code in pytest_splunk_addon/sample_generation/rule.py
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
|
replace(sample, token_count)
¶
Yields a random ipv4 address.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
728 729 730 731 732 733 734 735 736 737 |
|
Ipv6Rule
¶
Bases: Rule
Ipv6Rule
Source code in pytest_splunk_addon/sample_generation/rule.py
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 |
|
replace(sample, token_count)
¶
Yields a random ipv6 address
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
745 746 747 748 749 750 751 752 753 754 |
|
ListRule
¶
Bases: Rule
ListRule
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
replace(sample, token_count)
¶
Yields a random value from the list mentioned in token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
MacRule
¶
Bases: Rule
MacRule
Source code in pytest_splunk_addon/sample_generation/rule.py
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 |
|
replace(sample, token_count)
¶
Yields a random mac address
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
762 763 764 765 766 767 768 769 770 771 |
|
Rule
¶
Base class for all the rules.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
dict
|
Dictionary containing token and its data |
required |
psa_data_params |
dict
|
PSA data stanzas dictionary |
None
|
sample_path |
str
|
Path to the samples directory |
None
|
Source code in pytest_splunk_addon/sample_generation/rule.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 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 |
|
apply(events)
¶
Replaces the token with appropriate values as per rules mapped with the tokens in the event. For replacement_type = all it will generate an event for each replacement value. i.e. integer[1:50] => will generate 50 events
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events |
list
|
List of events(SampleEvent) |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
get_lookup_value(sample, key, headers, value_list)
¶
Common method to read csv and get a random row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
key |
str
|
fieldname i.e. host, src, user, dvc etc |
required |
headers |
list
|
Headers of csv file in list format |
required |
value_list |
list
|
list of replacement values mentioned in configuration file. |
required |
Returns:
Name | Type | Description |
---|---|---|
index_list |
list
|
list of mapped columns(int) as per value_list |
csv_row |
list
|
list of replacement values for the rule. |
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
get_rule_replacement_values(sample, value_list, rule)
¶
Common method for replacement values of SrcRule, Destrule, DvcRule, HostRule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
value_list |
list
|
list of replacement values mentioned in configuration file. |
required |
rule |
str
|
fieldname i.e. host, src, user, dvc etc |
required |
Returns:
Name | Type | Description |
---|---|---|
csv_row |
list
|
list of replacement values for the rule. |
Source code in pytest_splunk_addon/sample_generation/rule.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
parse_rule(token, psa_data_params, sample_path)
classmethod
¶
Returns appropriate Rule object as per replacement type of token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token |
dict
|
Dictionary containing token and its data |
required |
psa_data_params |
dict
|
PSA data stanzas dictionary |
required |
sample_path |
str
|
Path to the samples directory |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
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 |
|
SrcPortRule
¶
Bases: Rule
SrcPortRule
Source code in pytest_splunk_addon/sample_generation/rule.py
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
|
replace(sample, token_count)
¶
Yields a random port value from the range 4000-5000
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 |
|
SrcRule
¶
Bases: Rule
SrcRule
Source code in pytest_splunk_addon/sample_generation/rule.py
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
|
replace(sample, token_count)
¶
Yields a random src replacement value from the list of values mentioned in token. Possible values: [“host”, “ipv4”, “ipv6”, “fqdn”]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
|
StaticRule
¶
Bases: Rule
StaticRule
Source code in pytest_splunk_addon/sample_generation/rule.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
|
replace(sample, token_count)
¶
Yields the static value mentioned in token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
390 391 392 393 394 395 396 397 398 399 |
|
TimeRule
¶
Bases: Rule
Source code in pytest_splunk_addon/sample_generation/rule.py
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
|
replace(sample, token_count)
¶
Returns time according to the parameters specified in the input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 |
|
UrlRule
¶
Bases: Rule
UrlRule
Source code in pytest_splunk_addon/sample_generation/rule.py
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 |
|
generate_url_query_params()
¶
Generates random query params for url
Returns:
Type | Description |
---|---|
Return the query param string |
Source code in pytest_splunk_addon/sample_generation/rule.py
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 |
|
replace(sample, token_count)
¶
Yields a random url replacement value from the list of values mentioned in token.
Possible values: [“ip_host”, “fqdn_host”, “path”, “query”, “protocol”, “full”]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
|
UserRule
¶
Bases: Rule
UserRule
Source code in pytest_splunk_addon/sample_generation/rule.py
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
|
replace(sample, token_count)
¶
Yields a random user replacement value from the list of values mentioned in token. Possible values: [“name”, “email”, “domain_user”, “distinquised_name”]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample |
SampleEvent
|
Instance containing event info |
required |
token_count |
int
|
No. of token in sample event where rule is applicable |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
|
raise_warning(warning_string)
¶
To raise a pytest user warning along with a log.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
warning_string |
str
|
warning string |
required |
Source code in pytest_splunk_addon/sample_generation/rule.py
49 50 51 52 53 54 55 56 57 |
|