sequence
stringlengths 546
16.2k
| code
stringlengths 108
19.3k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:join; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ignore_errors; 7, False; 8, block; 8, 9; 8, 11; 8, 16; 8, 20; 8, 26; 8, 45; 8, 71; 8, 80; 8, 81; 8, 105; 8, 116; 8, 122; 8, 176; 9, expression_statement; 9, 10; 10, comment; 11, assert_statement; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_status_fn; 15, string:"Asked to join a task which hasn't had any commands executed on it"; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:check_interval; 19, float:0.2; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:status_fn; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_status_fn; 26, if_statement; 26, 27; 26, 37; 27, not_operator; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:wait_for_file; 32, argument_list; 32, 33; 32, 34; 33, identifier:status_fn; 34, keyword_argument; 34, 35; 34, 36; 35, identifier:max_wait_sec; 36, integer:30; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:log; 43, argument_list; 43, 44; 44, string:f"Retrying waiting for {status_fn}"; 45, while_statement; 45, 46; 45, 53; 46, not_operator; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:exists; 51, argument_list; 51, 52; 52, identifier:status_fn; 53, block; 53, 54; 53, 61; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:log; 59, argument_list; 59, 60; 60, string:f"Still waiting for {self._cmd}"; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:wait_for_file; 66, argument_list; 66, 67; 66, 68; 67, identifier:status_fn; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:max_wait_sec; 70, integer:30; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:contents; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:read; 78, argument_list; 78, 79; 79, identifier:status_fn; 80, comment; 81, if_statement; 81, 82; 81, 88; 82, comparison_operator:==; 82, 83; 82, 87; 83, call; 83, 84; 83, 85; 84, identifier:len; 85, argument_list; 85, 86; 86, identifier:contents; 87, integer:0; 88, block; 88, 89; 88, 96; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:time; 93, identifier:sleep; 94, argument_list; 94, 95; 95, identifier:check_interval; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:contents; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:read; 103, argument_list; 103, 104; 104, identifier:status_fn; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:status; 108, call; 108, 109; 108, 110; 109, identifier:int; 110, argument_list; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:contents; 114, identifier:strip; 115, argument_list; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:last_status; 121, identifier:status; 122, if_statement; 122, 123; 122, 126; 123, comparison_operator:!=; 123, 124; 123, 125; 124, identifier:status; 125, integer:0; 126, block; 126, 127; 126, 134; 126, 158; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:extra_msg; 130, conditional_expression:if; 130, 131; 130, 132; 130, 133; 131, string:'(ignoring error)'; 132, identifier:ignore_errors; 133, string:'(failing)'; 134, if_statement; 134, 135; 134, 143; 135, boolean_operator:or; 135, 136; 135, 142; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:util; 139, identifier:is_set; 140, argument_list; 140, 141; 141, string:'NCLUSTER_RUN_WITH_OUTPUT_ON_FAILURE'; 142, True; 143, block; 143, 144; 143, 151; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:log; 149, argument_list; 149, 150; 150, string:f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'"; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:log; 156, argument_list; 156, 157; 157, string:f"\n{'*'*80}\nEnd failing output"; 158, if_statement; 158, 159; 158, 161; 158, 167; 159, not_operator; 159, 160; 160, identifier:ignore_errors; 161, block; 161, 162; 162, raise_statement; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:RuntimeError; 165, argument_list; 165, 166; 166, string:f"Command {self._cmd} returned status {status}"; 167, else_clause; 167, 168; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:log; 174, argument_list; 174, 175; 175, string:f"Warning: command {self._cmd} returned status {status}"; 176, return_statement; 176, 177; 177, identifier:status | def join(self, ignore_errors=False):
"""Waits until last executed command completed."""
assert self._status_fn, "Asked to join a task which hasn't had any commands executed on it"
check_interval = 0.2
status_fn = self._status_fn
if not self.wait_for_file(status_fn, max_wait_sec=30):
self.log(f"Retrying waiting for {status_fn}")
while not self.exists(status_fn):
self.log(f"Still waiting for {self._cmd}")
self.wait_for_file(status_fn, max_wait_sec=30)
contents = self.read(status_fn)
# if empty wait a bit to allow for race condition
if len(contents) == 0:
time.sleep(check_interval)
contents = self.read(status_fn)
status = int(contents.strip())
self.last_status = status
if status != 0:
extra_msg = '(ignoring error)' if ignore_errors else '(failing)'
if util.is_set('NCLUSTER_RUN_WITH_OUTPUT_ON_FAILURE') or True:
self.log(
f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'")
self.log(f"\n{'*'*80}\nEnd failing output")
if not ignore_errors:
raise RuntimeError(f"Command {self._cmd} returned status {status}")
else:
self.log(f"Warning: command {self._cmd} returned status {status}")
return status |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 1, 24; 2, function_name:_run_with_output_on_failure; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 19; 4, identifier:self; 5, identifier:cmd; 6, default_parameter; 6, 7; 6, 8; 7, identifier:non_blocking; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:ignore_errors; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:max_wait_sec; 14, binary_operator:*; 14, 15; 14, 18; 15, binary_operator:*; 15, 16; 15, 17; 16, integer:365; 17, integer:24; 18, integer:3600; 19, default_parameter; 19, 20; 19, 21; 20, identifier:check_interval; 21, float:0.2; 22, type; 22, 23; 23, identifier:str; 24, block; 24, 25; 24, 27; 24, 36; 24, 44; 24, 52; 24, 63; 24, 69; 24, 77; 24, 83; 24, 89; 24, 95; 24, 101; 24, 110; 24, 115; 24, 116; 24, 128; 24, 129; 24, 130; 24, 131; 24, 135; 24, 144; 24, 152; 24, 167; 24, 171; 24, 181; 24, 186; 24, 207; 24, 217; 24, 261; 24, 272; 24, 273; 24, 299; 24, 310; 24, 316; 24, 360; 25, expression_statement; 25, 26; 26, comment; 27, if_statement; 27, 28; 27, 32; 28, not_operator; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_can_run; 32, block; 32, 33; 33, assert_statement; 33, 34; 33, 35; 34, False; 35, string:"Using .run before initialization finished"; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:in; 37, 38; 37, 39; 38, string:'\n'; 39, identifier:cmd; 40, block; 40, 41; 41, assert_statement; 41, 42; 41, 43; 42, False; 43, string:"Don't support multi-line for run2"; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:cmd; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:cmd; 50, identifier:strip; 51, argument_list; 52, if_statement; 52, 53; 52, 59; 52, 60; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:cmd; 56, identifier:startswith; 57, argument_list; 57, 58; 58, string:'#'; 59, comment; 60, block; 60, 61; 61, return_statement; 61, 62; 62, string:''; 63, expression_statement; 63, 64; 64, augmented_assignment:+=; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:run_counter; 68, integer:1; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:log; 74, argument_list; 74, 75; 74, 76; 75, string:"tmux> %s"; 76, identifier:cmd; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:_cmd; 82, identifier:cmd; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:_cmd_fn; 88, string:f'{self.remote_scratch}/{self.run_counter}.cmd'; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:_status_fn; 94, string:f'{self.remote_scratch}/{self.run_counter}.status'; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_out_fn; 100, string:f'{self.remote_scratch}/{self.run_counter}.out'; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:cmd; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:util; 107, identifier:shell_strip_comment; 108, argument_list; 108, 109; 109, identifier:cmd; 110, assert_statement; 110, 111; 110, 114; 111, comparison_operator:not; 111, 112; 111, 113; 112, string:'&'; 113, identifier:cmd; 114, string:f"cmd {cmd} contains &, that breaks things"; 115, comment; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:file_write; 121, argument_list; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_cmd_fn; 125, binary_operator:+; 125, 126; 125, 127; 126, identifier:cmd; 127, string:'\n'; 128, comment; 129, comment; 130, comment; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:modified_cmd; 134, string:f'{cmd} > >(tee -a {self._out_fn}) 2> >(tee -a {self._out_fn} >&2); echo $? > {self._status_fn}'; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:modified_cmd; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:shlex; 141, identifier:quote; 142, argument_list; 142, 143; 143, identifier:modified_cmd; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:start_time; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:time; 150, identifier:time; 151, argument_list; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:tmux_window; 155, binary_operator:+; 155, 156; 155, 161; 156, binary_operator:+; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:tmux_session; 160, string:':'; 161, call; 161, 162; 161, 163; 162, identifier:str; 163, argument_list; 163, 164; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:tmux_window_id; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:tmux_cmd; 170, string:f"tmux send-keys -t {tmux_window} {modified_cmd} Enter"; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:_run_raw; 176, argument_list; 176, 177; 176, 178; 177, identifier:tmux_cmd; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:ignore_errors; 180, identifier:ignore_errors; 181, if_statement; 181, 182; 181, 183; 182, identifier:non_blocking; 183, block; 183, 184; 184, return_statement; 184, 185; 185, integer:0; 186, if_statement; 186, 187; 186, 199; 187, not_operator; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:wait_for_file; 192, argument_list; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:_status_fn; 196, keyword_argument; 196, 197; 196, 198; 197, identifier:max_wait_sec; 198, integer:60; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:log; 205, argument_list; 205, 206; 206, string:f"Retrying waiting for {self._status_fn}"; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:elapsed_time; 210, binary_operator:-; 210, 211; 210, 216; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:time; 214, identifier:time; 215, argument_list; 216, identifier:start_time; 217, while_statement; 217, 218; 217, 231; 218, boolean_operator:and; 218, 219; 218, 228; 219, not_operator; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:exists; 224, argument_list; 224, 225; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:_status_fn; 228, comparison_operator:<; 228, 229; 228, 230; 229, identifier:elapsed_time; 230, identifier:max_wait_sec; 231, block; 231, 232; 231, 239; 231, 251; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 237; 234, attribute; 234, 235; 234, 236; 235, identifier:self; 236, identifier:log; 237, argument_list; 237, 238; 238, string:f"Still waiting for {cmd}"; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:wait_for_file; 244, argument_list; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:_status_fn; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:max_wait_sec; 250, integer:60; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:elapsed_time; 254, binary_operator:-; 254, 255; 254, 260; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:time; 258, identifier:time; 259, argument_list; 260, identifier:start_time; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:contents; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:read; 268, argument_list; 268, 269; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:_status_fn; 272, comment; 273, if_statement; 273, 274; 273, 280; 274, comparison_operator:==; 274, 275; 274, 279; 275, call; 275, 276; 275, 277; 276, identifier:len; 277, argument_list; 277, 278; 278, identifier:contents; 279, integer:0; 280, block; 280, 281; 280, 288; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:time; 285, identifier:sleep; 286, argument_list; 286, 287; 287, identifier:check_interval; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:contents; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:read; 295, argument_list; 295, 296; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:_status_fn; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:status; 302, call; 302, 303; 302, 304; 303, identifier:int; 304, argument_list; 304, 305; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:contents; 308, identifier:strip; 309, argument_list; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:last_status; 315, identifier:status; 316, if_statement; 316, 317; 316, 320; 317, comparison_operator:!=; 317, 318; 317, 319; 318, identifier:status; 319, integer:0; 320, block; 320, 321; 320, 328; 320, 335; 320, 342; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:extra_msg; 324, conditional_expression:if; 324, 325; 324, 326; 324, 327; 325, string:'(ignoring error)'; 326, identifier:ignore_errors; 327, string:'(failing)'; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:log; 333, argument_list; 333, 334; 334, string:f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'"; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:self; 339, identifier:log; 340, argument_list; 340, 341; 341, string:f"\n{'*'*80}\nEnd failing output"; 342, if_statement; 342, 343; 342, 345; 342, 351; 343, not_operator; 343, 344; 344, identifier:ignore_errors; 345, block; 345, 346; 346, raise_statement; 346, 347; 347, call; 347, 348; 347, 349; 348, identifier:RuntimeError; 349, argument_list; 349, 350; 350, string:f"Command {cmd} returned status {status}"; 351, else_clause; 351, 352; 352, block; 352, 353; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:self; 357, identifier:log; 358, argument_list; 358, 359; 359, string:f"Warning: command {cmd} returned status {status}"; 360, return_statement; 360, 361; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:self; 364, identifier:read; 365, argument_list; 365, 366; 366, attribute; 366, 367; 366, 368; 367, identifier:self; 368, identifier:_out_fn | def _run_with_output_on_failure(self, cmd, non_blocking=False,
ignore_errors=False,
max_wait_sec=365 * 24 * 3600,
check_interval=0.2) -> str:
"""Experimental version of run propagates error messages to client. This command will be default "run" eventually"""
if not self._can_run:
assert False, "Using .run before initialization finished"
if '\n' in cmd:
assert False, "Don't support multi-line for run2"
cmd = cmd.strip()
if cmd.startswith('#'): # ignore empty/commented out lines
return ''
self.run_counter += 1
self.log("tmux> %s", cmd)
self._cmd = cmd
self._cmd_fn = f'{self.remote_scratch}/{self.run_counter}.cmd'
self._status_fn = f'{self.remote_scratch}/{self.run_counter}.status'
self._out_fn = f'{self.remote_scratch}/{self.run_counter}.out'
cmd = util.shell_strip_comment(cmd)
assert '&' not in cmd, f"cmd {cmd} contains &, that breaks things"
# modify command to dump shell success status into file
self.file_write(self._cmd_fn, cmd + '\n')
# modified_cmd = f'{cmd} > {out_fn} 2>&1; echo $? > {status_fn}'
# https://stackoverflow.com/a/692407/419116
# $cmd > >(tee -a fn) 2> >(tee -a fn >&2)
modified_cmd = f'{cmd} > >(tee -a {self._out_fn}) 2> >(tee -a {self._out_fn} >&2); echo $? > {self._status_fn}'
modified_cmd = shlex.quote(modified_cmd)
start_time = time.time()
tmux_window = self.tmux_session + ':' + str(self.tmux_window_id)
tmux_cmd = f"tmux send-keys -t {tmux_window} {modified_cmd} Enter"
self._run_raw(tmux_cmd, ignore_errors=ignore_errors)
if non_blocking:
return 0
if not self.wait_for_file(self._status_fn, max_wait_sec=60):
self.log(f"Retrying waiting for {self._status_fn}")
elapsed_time = time.time() - start_time
while not self.exists(self._status_fn) and elapsed_time < max_wait_sec:
self.log(f"Still waiting for {cmd}")
self.wait_for_file(self._status_fn, max_wait_sec=60)
elapsed_time = time.time() - start_time
contents = self.read(self._status_fn)
# if empty wait a bit to allow for race condition
if len(contents) == 0:
time.sleep(check_interval)
contents = self.read(self._status_fn)
status = int(contents.strip())
self.last_status = status
if status != 0:
extra_msg = '(ignoring error)' if ignore_errors else '(failing)'
self.log(
f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'")
self.log(f"\n{'*'*80}\nEnd failing output")
if not ignore_errors:
raise RuntimeError(f"Command {cmd} returned status {status}")
else:
self.log(f"Warning: command {cmd} returned status {status}")
return self.read(self._out_fn) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 1, 21; 2, function_name:upload; 3, parameters; 3, 4; 3, 5; 3, 9; 3, 14; 4, identifier:self; 5, typed_parameter; 5, 6; 5, 7; 6, identifier:local_fn; 7, type; 7, 8; 8, identifier:str; 9, typed_default_parameter; 9, 10; 9, 11; 9, 13; 10, identifier:remote_fn; 11, type; 11, 12; 12, identifier:str; 13, string:''; 14, typed_default_parameter; 14, 15; 14, 16; 14, 18; 15, identifier:dont_overwrite; 16, type; 16, 17; 17, identifier:bool; 18, False; 19, type; 19, 20; 20, None; 21, block; 21, 22; 21, 24; 21, 25; 21, 47; 21, 61; 21, 83; 21, 132; 21, 133; 21, 134; 21, 279; 21, 294; 21, 307; 21, 319; 21, 343; 21, 364; 21, 374; 22, expression_statement; 22, 23; 23, comment; 24, comment; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:in; 26, 27; 26, 28; 27, string:'*'; 28, identifier:local_fn; 29, block; 29, 30; 29, 46; 30, for_statement; 30, 31; 30, 32; 30, 38; 31, identifier:local_subfn; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:glob; 35, identifier:glob; 36, argument_list; 36, 37; 37, identifier:local_fn; 38, block; 38, 39; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:upload; 44, argument_list; 44, 45; 45, identifier:local_subfn; 46, return_statement; 47, if_statement; 47, 48; 47, 51; 47, 52; 48, comparison_operator:in; 48, 49; 48, 50; 49, string:'#'; 50, identifier:local_fn; 51, comment; 52, block; 52, 53; 52, 60; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:log; 58, argument_list; 58, 59; 59, string:"skipping backup file {local_fn}"; 60, return_statement; 61, if_statement; 61, 62; 61, 66; 62, not_operator; 62, 63; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:sftp; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:sftp; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:u; 75, identifier:call_with_retries; 76, argument_list; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:ssh_client; 81, identifier:open_sftp; 82, string:'self.ssh_client.open_sftp'; 83, function_definition; 83, 84; 83, 85; 83, 88; 84, function_name:maybe_fix_mode; 85, parameters; 85, 86; 85, 87; 86, identifier:local_fn_; 87, identifier:remote_fn_; 88, block; 88, 89; 88, 91; 88, 112; 89, expression_statement; 89, 90; 90, comment; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:mode; 94, subscript; 94, 95; 94, 108; 95, call; 95, 96; 95, 97; 96, identifier:oct; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 105; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:os; 102, identifier:stat; 103, argument_list; 103, 104; 104, identifier:local_fn_; 105, attribute; 105, 106; 105, 107; 106, identifier:stat; 107, identifier:ST_MODE; 108, slice; 108, 109; 108, 111; 109, unary_operator:-; 109, 110; 110, integer:3; 111, colon; 112, if_statement; 112, 113; 112, 116; 113, comparison_operator:in; 113, 114; 113, 115; 114, string:'7'; 115, identifier:mode; 116, block; 116, 117; 116, 124; 116, 125; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:log; 122, argument_list; 122, 123; 123, string:f"Making {remote_fn_} executable with mode {mode}"; 124, comment; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:_run_raw; 130, argument_list; 130, 131; 131, string:f"chmod {mode} {remote_fn_}"; 132, comment; 133, comment; 134, function_definition; 134, 135; 134, 136; 134, 139; 135, function_name:_put_dir; 136, parameters; 136, 137; 136, 138; 137, identifier:source; 138, identifier:target; 139, block; 139, 140; 139, 142; 139, 177; 139, 186; 139, 191; 140, expression_statement; 140, 141; 141, comment; 142, function_definition; 142, 143; 142, 144; 142, 152; 143, function_name:_safe_mkdir; 144, parameters; 144, 145; 144, 146; 144, 149; 145, identifier:path; 146, default_parameter; 146, 147; 146, 148; 147, identifier:mode; 148, integer:511; 149, default_parameter; 149, 150; 149, 151; 150, identifier:ignore_existing; 151, True; 152, block; 152, 153; 152, 155; 153, expression_statement; 153, 154; 154, comment; 155, try_statement; 155, 156; 155, 167; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 164; 159, attribute; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:sftp; 163, identifier:mkdir; 164, argument_list; 164, 165; 164, 166; 165, identifier:path; 166, identifier:mode; 167, except_clause; 167, 168; 167, 169; 168, identifier:IOError; 169, block; 169, 170; 170, if_statement; 170, 171; 170, 172; 170, 174; 171, identifier:ignore_existing; 172, block; 172, 173; 173, pass_statement; 174, else_clause; 174, 175; 175, block; 175, 176; 176, raise_statement; 177, assert_statement; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:os; 182, identifier:path; 183, identifier:isdir; 184, argument_list; 184, 185; 185, identifier:source; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:_safe_mkdir; 189, argument_list; 189, 190; 190, identifier:target; 191, for_statement; 191, 192; 191, 193; 191, 199; 192, identifier:item; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:os; 196, identifier:listdir; 197, argument_list; 197, 198; 198, identifier:source; 199, block; 199, 200; 200, if_statement; 200, 201; 200, 217; 200, 266; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:os; 205, identifier:path; 206, identifier:isfile; 207, argument_list; 207, 208; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:os; 212, identifier:path; 213, identifier:join; 214, argument_list; 214, 215; 214, 216; 215, identifier:source; 216, identifier:item; 217, block; 217, 218; 217, 244; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 225; 220, attribute; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:sftp; 224, identifier:put; 225, argument_list; 225, 226; 225, 235; 226, call; 226, 227; 226, 232; 227, attribute; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:os; 230, identifier:path; 231, identifier:join; 232, argument_list; 232, 233; 232, 234; 233, identifier:source; 234, identifier:item; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:os; 239, identifier:path; 240, identifier:join; 241, argument_list; 241, 242; 241, 243; 242, identifier:target; 243, identifier:item; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 247; 246, identifier:maybe_fix_mode; 247, argument_list; 247, 248; 247, 257; 248, call; 248, 249; 248, 254; 249, attribute; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:os; 252, identifier:path; 253, identifier:join; 254, argument_list; 254, 255; 254, 256; 255, identifier:source; 256, identifier:item; 257, call; 257, 258; 257, 263; 258, attribute; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:os; 261, identifier:path; 262, identifier:join; 263, argument_list; 263, 264; 263, 265; 264, identifier:target; 265, identifier:item; 266, else_clause; 266, 267; 267, block; 267, 268; 267, 273; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 271; 270, identifier:_safe_mkdir; 271, argument_list; 271, 272; 272, string:f'{target}/{item}'; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 276; 275, identifier:_put_dir; 276, argument_list; 276, 277; 276, 278; 277, string:f'{source}/{item}'; 278, string:f'{target}/{item}'; 279, if_statement; 279, 280; 279, 282; 280, not_operator; 280, 281; 281, identifier:remote_fn; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:remote_fn; 286, call; 286, 287; 286, 292; 287, attribute; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:os; 290, identifier:path; 291, identifier:basename; 292, argument_list; 292, 293; 293, identifier:local_fn; 294, expression_statement; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:log; 299, argument_list; 299, 300; 300, binary_operator:+; 300, 301; 300, 306; 301, binary_operator:+; 301, 302; 301, 305; 302, binary_operator:+; 302, 303; 302, 304; 303, string:'uploading '; 304, identifier:local_fn; 305, string:' to '; 306, identifier:remote_fn; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:remote_fn; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:remote_fn; 313, identifier:replace; 314, argument_list; 314, 315; 314, 316; 315, string:'~'; 316, attribute; 316, 317; 316, 318; 317, identifier:self; 318, identifier:homedir; 319, if_statement; 319, 320; 319, 323; 320, comparison_operator:in; 320, 321; 320, 322; 321, string:'/'; 322, identifier:remote_fn; 323, block; 323, 324; 323, 335; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:remote_dir; 327, call; 327, 328; 327, 333; 328, attribute; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:os; 331, identifier:path; 332, identifier:dirname; 333, argument_list; 333, 334; 334, identifier:remote_fn; 335, assert_statement; 335, 336; 335, 342; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:self; 339, identifier:exists; 340, argument_list; 340, 341; 341, identifier:remote_dir; 342, string:f"Remote dir {remote_dir} doesn't exist"; 343, if_statement; 343, 344; 343, 352; 344, boolean_operator:and; 344, 345; 344, 346; 345, identifier:dont_overwrite; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:self; 349, identifier:exists; 350, argument_list; 350, 351; 351, identifier:remote_fn; 352, block; 352, 353; 352, 363; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:self; 357, identifier:log; 358, argument_list; 358, 359; 359, binary_operator:%; 359, 360; 359, 361; 360, string:"Remote file %s exists, skipping"; 361, tuple; 361, 362; 362, identifier:remote_fn; 363, return_statement; 364, assert_statement; 364, 365; 364, 373; 365, call; 365, 366; 365, 371; 366, attribute; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:os; 369, identifier:path; 370, identifier:exists; 371, argument_list; 371, 372; 372, identifier:local_fn; 373, string:f"{local_fn} not found"; 374, if_statement; 374, 375; 374, 383; 374, 390; 375, call; 375, 376; 375, 381; 376, attribute; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:os; 379, identifier:path; 380, identifier:isdir; 381, argument_list; 381, 382; 382, identifier:local_fn; 383, block; 383, 384; 384, expression_statement; 384, 385; 385, call; 385, 386; 385, 387; 386, identifier:_put_dir; 387, argument_list; 387, 388; 387, 389; 388, identifier:local_fn; 389, identifier:remote_fn; 390, else_clause; 390, 391; 391, block; 391, 392; 391, 405; 391, 406; 391, 436; 391, 450; 392, assert_statement; 392, 393; 392, 401; 393, call; 393, 394; 393, 399; 394, attribute; 394, 395; 394, 398; 395, attribute; 395, 396; 395, 397; 396, identifier:os; 397, identifier:path; 398, identifier:isfile; 399, argument_list; 399, 400; 400, identifier:local_fn; 401, binary_operator:%; 401, 402; 401, 403; 402, string:"%s is not a file"; 403, tuple; 403, 404; 404, identifier:local_fn; 405, comment; 406, if_statement; 406, 407; 406, 420; 407, boolean_operator:and; 407, 408; 407, 414; 408, call; 408, 409; 408, 412; 409, attribute; 409, 410; 409, 411; 410, identifier:self; 411, identifier:exists; 412, argument_list; 412, 413; 413, identifier:remote_fn; 414, call; 414, 415; 414, 418; 415, attribute; 415, 416; 415, 417; 416, identifier:self; 417, identifier:isdir; 418, argument_list; 418, 419; 419, identifier:remote_fn; 420, block; 420, 421; 421, expression_statement; 421, 422; 422, assignment; 422, 423; 422, 424; 423, identifier:remote_fn; 424, binary_operator:+; 424, 425; 424, 428; 425, binary_operator:+; 425, 426; 425, 427; 426, identifier:remote_fn; 427, string:'/'; 428, call; 428, 429; 428, 434; 429, attribute; 429, 430; 429, 433; 430, attribute; 430, 431; 430, 432; 431, identifier:os; 432, identifier:path; 433, identifier:basename; 434, argument_list; 434, 435; 435, identifier:local_fn; 436, expression_statement; 436, 437; 437, call; 437, 438; 437, 443; 438, attribute; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:self; 441, identifier:sftp; 442, identifier:put; 443, argument_list; 443, 444; 443, 447; 444, keyword_argument; 444, 445; 444, 446; 445, identifier:localpath; 446, identifier:local_fn; 447, keyword_argument; 447, 448; 447, 449; 448, identifier:remotepath; 449, identifier:remote_fn; 450, expression_statement; 450, 451; 451, call; 451, 452; 451, 453; 452, identifier:maybe_fix_mode; 453, argument_list; 453, 454; 453, 455; 454, identifier:local_fn; 455, identifier:remote_fn | def upload(self, local_fn: str, remote_fn: str = '',
dont_overwrite: bool = False) -> None:
"""Uploads file to remote instance. If location not specified, dumps it
into default directory. If remote location has files or directories with the
same name, behavior is undefined."""
# support wildcard through glob
if '*' in local_fn:
for local_subfn in glob.glob(local_fn):
self.upload(local_subfn)
return
if '#' in local_fn: # hashes also give problems from shell commands
self.log("skipping backup file {local_fn}")
return
if not self.sftp:
self.sftp = u.call_with_retries(self.ssh_client.open_sftp,
'self.ssh_client.open_sftp')
def maybe_fix_mode(local_fn_, remote_fn_):
"""Makes remote file execute for locally executable files"""
mode = oct(os.stat(local_fn_)[stat.ST_MODE])[-3:]
if '7' in mode:
self.log(f"Making {remote_fn_} executable with mode {mode}")
# use raw run, in case tmux is unavailable
self._run_raw(f"chmod {mode} {remote_fn_}")
# augmented SFTP client that can transfer directories, from
# https://stackoverflow.com/a/19974994/419116
def _put_dir(source, target):
""" Uploads the contents of the source directory to the target path."""
def _safe_mkdir(path, mode=511, ignore_existing=True):
""" Augments mkdir by adding an option to not fail if the folder exists asdf asdf asdf as"""
try:
self.sftp.mkdir(path, mode)
except IOError:
if ignore_existing:
pass
else:
raise
assert os.path.isdir(source)
_safe_mkdir(target)
for item in os.listdir(source):
if os.path.isfile(os.path.join(source, item)):
self.sftp.put(os.path.join(source, item), os.path.join(target, item))
maybe_fix_mode(os.path.join(source, item), os.path.join(target, item))
else:
_safe_mkdir(f'{target}/{item}')
_put_dir(f'{source}/{item}', f'{target}/{item}')
if not remote_fn:
remote_fn = os.path.basename(local_fn)
self.log('uploading ' + local_fn + ' to ' + remote_fn)
remote_fn = remote_fn.replace('~', self.homedir)
if '/' in remote_fn:
remote_dir = os.path.dirname(remote_fn)
assert self.exists(
remote_dir), f"Remote dir {remote_dir} doesn't exist"
if dont_overwrite and self.exists(remote_fn):
self.log("Remote file %s exists, skipping" % (remote_fn,))
return
assert os.path.exists(local_fn), f"{local_fn} not found"
if os.path.isdir(local_fn):
_put_dir(local_fn, remote_fn)
else:
assert os.path.isfile(local_fn), "%s is not a file" % (local_fn,)
# this crashes with IOError when upload failed
if self.exists(remote_fn) and self.isdir(remote_fn):
remote_fn = remote_fn + '/' + os.path.basename(local_fn)
self.sftp.put(localpath=local_fn, remotepath=remote_fn)
maybe_fix_mode(local_fn, remote_fn) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_child_fn; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:attrs; 5, identifier:names; 6, identifier:bases; 7, block; 7, 8; 7, 10; 7, 61; 7, 62; 7, 68; 7, 94; 7, 100; 7, 101; 7, 117; 7, 118; 8, expression_statement; 8, 9; 9, comment; 10, function_definition; 10, 11; 10, 12; 10, 15; 11, function_name:call_method; 12, parameters; 12, 13; 12, 14; 13, identifier:obj; 14, identifier:method; 15, block; 15, 16; 15, 18; 15, 19; 15, 20; 15, 21; 15, 22; 15, 23; 15, 24; 15, 51; 16, expression_statement; 16, 17; 17, comment; 18, comment; 19, comment; 20, comment; 21, comment; 22, comment; 23, comment; 24, if_statement; 24, 25; 24, 30; 24, 39; 25, call; 25, 26; 25, 27; 26, identifier:isinstance; 27, argument_list; 27, 28; 27, 29; 28, identifier:obj; 29, identifier:type; 30, block; 30, 31; 30, 35; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:instance; 34, None; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:owner; 38, identifier:obj; 39, else_clause; 39, 40; 40, block; 40, 41; 40, 45; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:instance; 44, identifier:obj; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:owner; 48, attribute; 48, 49; 48, 50; 49, identifier:obj; 50, identifier:__class__; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 60; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:method; 56, identifier:__get__; 57, argument_list; 57, 58; 57, 59; 58, identifier:instance; 59, identifier:owner; 60, argument_list; 61, comment; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:default_name; 65, subscript; 65, 66; 65, 67; 66, identifier:names; 67, integer:0; 68, function_definition; 68, 69; 68, 70; 68, 72; 69, function_name:default_fn; 70, parameters; 70, 71; 71, identifier:obj; 72, block; 72, 73; 73, for_statement; 73, 74; 73, 75; 73, 76; 74, identifier:cls; 75, identifier:bases; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 83; 78, call; 78, 79; 78, 80; 79, identifier:hasattr; 80, argument_list; 80, 81; 80, 82; 81, identifier:cls; 82, identifier:default_name; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 87; 86, identifier:call_method; 87, argument_list; 87, 88; 87, 89; 88, identifier:obj; 89, call; 89, 90; 89, 91; 90, identifier:getattr; 91, argument_list; 91, 92; 91, 93; 92, identifier:cls; 93, identifier:default_name; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:default_fn; 98, identifier:__name__; 99, identifier:default_name; 100, comment; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:fns; 104, list_comprehension; 104, 105; 104, 110; 104, 113; 105, tuple; 105, 106; 105, 107; 106, identifier:name; 107, subscript; 107, 108; 107, 109; 108, identifier:attrs; 109, identifier:name; 110, for_in_clause; 110, 111; 110, 112; 111, identifier:name; 112, identifier:names; 113, if_clause; 113, 114; 114, comparison_operator:in; 114, 115; 114, 116; 115, identifier:name; 116, identifier:attrs; 117, comment; 118, if_statement; 118, 119; 118, 125; 118, 131; 118, 132; 118, 167; 118, 168; 119, comparison_operator:>; 119, 120; 119, 124; 120, call; 120, 121; 120, 122; 121, identifier:len; 122, argument_list; 122, 123; 123, identifier:fns; 124, integer:1; 125, block; 125, 126; 126, raise_statement; 126, 127; 127, call; 127, 128; 127, 129; 128, identifier:RuntimeError; 129, argument_list; 129, 130; 130, string:"Cannot have more than one setup or teardown method per context (class or test)."; 131, comment; 132, elif_clause; 132, 133; 132, 139; 133, comparison_operator:==; 133, 134; 133, 138; 134, call; 134, 135; 134, 136; 135, identifier:len; 136, argument_list; 136, 137; 137, identifier:fns; 138, integer:1; 139, block; 139, 140; 139, 148; 139, 159; 139, 165; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, pattern_list; 142, 143; 142, 144; 143, identifier:name; 144, identifier:fn; 145, subscript; 145, 146; 145, 147; 146, identifier:fns; 147, integer:0; 148, function_definition; 148, 149; 148, 150; 148, 152; 149, function_name:child_fn; 150, parameters; 150, 151; 151, identifier:obj; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 156; 155, identifier:call_method; 156, argument_list; 156, 157; 156, 158; 157, identifier:obj; 158, identifier:fn; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:child_fn; 163, identifier:__name__; 164, identifier:name; 165, return_statement; 165, 166; 166, identifier:child_fn; 167, comment; 168, else_clause; 168, 169; 169, block; 169, 170; 170, return_statement; 170, 171; 171, identifier:default_fn | def get_child_fn(attrs, names, bases):
"""Returns a function from the child class that matches one of the names.
Searches the child class's set of methods (i.e., the attrs dict) for all
the functions matching the given list of names. If more than one is found,
an exception is raised, if one is found, it is returned, and if none are
found, a function that calls the default method on each parent class is
returned.
"""
def call_method(obj, method):
"""Calls a method as either a class method or an instance method.
"""
# The __get__ method takes an instance and an owner which changes
# depending on the calling object. If the calling object is a class,
# the instance is None and the owner will be the object itself. If the
# calling object is an instance, the instance will be the calling object
# and the owner will be its class. For more info on the __get__ method,
# see http://docs.python.org/2/reference/datamodel.html#object.__get__.
if isinstance(obj, type):
instance = None
owner = obj
else:
instance = obj
owner = obj.__class__
method.__get__(instance, owner)()
# Create a default function that calls the default method on each parent
default_name = names[0]
def default_fn(obj):
for cls in bases:
if hasattr(cls, default_name):
call_method(obj, getattr(cls, default_name))
default_fn.__name__ = default_name
# Get all of the functions in the child class that match the list of names
fns = [(name, attrs[name]) for name in names if name in attrs]
# Raise an error if more than one setup/teardown method is found
if len(fns) > 1:
raise RuntimeError("Cannot have more than one setup or teardown method per context (class or test).")
# If one setup/teardown function was found, return it
elif len(fns) == 1:
name, fn = fns[0]
def child_fn(obj):
call_method(obj, fn)
child_fn.__name__ = name
return child_fn
# Otherwise, return the default function
else:
return default_fn |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 1, 21; 2, function_name:authenticate; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:username; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:password; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:actions; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:response; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:authorization; 19, None; 20, comment; 21, block; 21, 22; 21, 24; 21, 63; 21, 70; 21, 71; 21, 96; 21, 107; 21, 120; 21, 173; 21, 370; 21, 376; 22, expression_statement; 22, 23; 23, comment; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:response; 27, None; 28, block; 28, 29; 29, with_statement; 29, 30; 29, 37; 30, with_clause; 30, 31; 31, with_item; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:warnings; 35, identifier:catch_warnings; 36, argument_list; 37, block; 37, 38; 37, 43; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:_ignore_warnings; 41, argument_list; 41, 42; 42, identifier:self; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:response; 46, call; 46, 47; 46, 54; 47, attribute; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_sessions; 52, integer:0; 53, identifier:get; 54, argument_list; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_base_url; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:verify; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_tlsverify; 63, if_statement; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:response; 66, identifier:ok; 67, block; 67, 68; 68, return_statement; 68, 69; 69, None; 70, comment; 71, if_statement; 71, 72; 71, 81; 72, comparison_operator:!=; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:response; 75, identifier:status_code; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:requests; 79, identifier:codes; 80, identifier:unauthorized; 81, block; 81, 82; 82, raise_statement; 82, 83; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:exceptions; 86, identifier:DXFUnexpectedStatusCodeError; 87, argument_list; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:response; 90, identifier:status_code; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:requests; 94, identifier:codes; 95, identifier:unauthorized; 96, if_statement; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:_insecure; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:exceptions; 105, identifier:DXFAuthInsecureError; 106, argument_list; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:parsed; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:www_authenticate; 113, identifier:parse; 114, argument_list; 114, 115; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:response; 118, identifier:headers; 119, string:'www-authenticate'; 120, if_statement; 120, 121; 120, 128; 120, 155; 120, 167; 121, boolean_operator:and; 121, 122; 121, 125; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:username; 124, None; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:password; 127, None; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:headers; 132, dictionary; 132, 133; 133, pair; 133, 134; 133, 135; 134, string:'Authorization'; 135, binary_operator:+; 135, 136; 135, 137; 136, string:'Basic '; 137, call; 137, 138; 137, 153; 138, attribute; 138, 139; 138, 152; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:base64; 142, identifier:b64encode; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 146; 145, identifier:_to_bytes_2and3; 146, argument_list; 146, 147; 147, binary_operator:+; 147, 148; 147, 151; 148, binary_operator:+; 148, 149; 148, 150; 149, identifier:username; 150, string:':'; 151, identifier:password; 152, identifier:decode; 153, argument_list; 153, 154; 154, string:'utf-8'; 155, elif_clause; 155, 156; 155, 159; 156, comparison_operator:is; 156, 157; 156, 158; 157, identifier:authorization; 158, None; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:headers; 163, dictionary; 163, 164; 164, pair; 164, 165; 164, 166; 165, string:'Authorization'; 166, identifier:authorization; 167, else_clause; 167, 168; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:headers; 172, dictionary; 173, if_statement; 173, 174; 173, 177; 174, comparison_operator:in; 174, 175; 174, 176; 175, string:'bearer'; 176, identifier:parsed; 177, block; 177, 178; 177, 184; 177, 225; 177, 239; 177, 250; 177, 265; 177, 275; 177, 281; 177, 294; 177, 303; 177, 338; 177, 343; 177, 351; 177, 366; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:info; 181, subscript; 181, 182; 181, 183; 182, identifier:parsed; 183, string:'bearer'; 184, if_statement; 184, 185; 184, 190; 184, 208; 184, 219; 185, boolean_operator:and; 185, 186; 185, 187; 186, identifier:actions; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:_repo; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:scope; 194, binary_operator:+; 194, 195; 194, 202; 195, binary_operator:+; 195, 196; 195, 201; 196, binary_operator:+; 196, 197; 196, 198; 197, string:'repository:'; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:_repo; 201, string:':'; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, string:','; 205, identifier:join; 206, argument_list; 206, 207; 207, identifier:actions; 208, elif_clause; 208, 209; 208, 212; 209, comparison_operator:in; 209, 210; 209, 211; 210, string:'scope'; 211, identifier:info; 212, block; 212, 213; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:scope; 216, subscript; 216, 217; 216, 218; 217, identifier:info; 218, string:'scope'; 219, else_clause; 219, 220; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:scope; 224, string:''; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:url_parts; 228, call; 228, 229; 228, 230; 229, identifier:list; 230, argument_list; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:urlparse; 234, identifier:urlparse; 235, argument_list; 235, 236; 236, subscript; 236, 237; 236, 238; 237, identifier:info; 238, string:'realm'; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:query; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:urlparse; 245, identifier:parse_qs; 246, argument_list; 246, 247; 247, subscript; 247, 248; 247, 249; 248, identifier:url_parts; 249, integer:4; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:query; 254, identifier:update; 255, argument_list; 255, 256; 256, dictionary; 256, 257; 256, 262; 257, pair; 257, 258; 257, 259; 258, string:'service'; 259, subscript; 259, 260; 259, 261; 260, identifier:info; 261, string:'service'; 262, pair; 262, 263; 262, 264; 263, string:'scope'; 264, identifier:scope; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 270; 267, subscript; 267, 268; 267, 269; 268, identifier:url_parts; 269, integer:4; 270, call; 270, 271; 270, 272; 271, identifier:urlencode; 272, argument_list; 272, 273; 272, 274; 273, identifier:query; 274, True; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:url_parts; 279, integer:0; 280, string:'https'; 281, if_statement; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:_auth_host; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 291; 288, subscript; 288, 289; 288, 290; 289, identifier:url_parts; 290, integer:1; 291, attribute; 291, 292; 291, 293; 292, identifier:self; 293, identifier:_auth_host; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:auth_url; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:urlparse; 300, identifier:urlunparse; 301, argument_list; 301, 302; 302, identifier:url_parts; 303, with_statement; 303, 304; 303, 311; 304, with_clause; 304, 305; 305, with_item; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:warnings; 309, identifier:catch_warnings; 310, argument_list; 311, block; 311, 312; 311, 317; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 315; 314, identifier:_ignore_warnings; 315, argument_list; 315, 316; 316, identifier:self; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:r; 320, call; 320, 321; 320, 328; 321, attribute; 321, 322; 321, 327; 322, subscript; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:_sessions; 326, integer:0; 327, identifier:get; 328, argument_list; 328, 329; 328, 330; 328, 333; 329, identifier:auth_url; 330, keyword_argument; 330, 331; 330, 332; 331, identifier:headers; 332, identifier:headers; 333, keyword_argument; 333, 334; 333, 335; 334, identifier:verify; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:_tlsverify; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 341; 340, identifier:_raise_for_status; 341, argument_list; 341, 342; 342, identifier:r; 343, expression_statement; 343, 344; 344, assignment; 344, 345; 344, 346; 345, identifier:rjson; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:r; 349, identifier:json; 350, argument_list; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:token; 356, conditional_expression:if; 356, 357; 356, 360; 356, 363; 357, subscript; 357, 358; 357, 359; 358, identifier:rjson; 359, string:'access_token'; 360, comparison_operator:in; 360, 361; 360, 362; 361, string:'access_token'; 362, identifier:rjson; 363, subscript; 363, 364; 363, 365; 364, identifier:rjson; 365, string:'token'; 366, return_statement; 366, 367; 367, attribute; 367, 368; 367, 369; 368, identifier:self; 369, identifier:_token; 370, expression_statement; 370, 371; 371, assignment; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:self; 374, identifier:_headers; 375, identifier:headers; 376, return_statement; 376, 377; 377, None | def authenticate(self,
username=None, password=None,
actions=None, response=None,
authorization=None):
# pylint: disable=too-many-arguments,too-many-locals
"""
Authenticate to the registry using a username and password,
an authorization header or otherwise as the anonymous user.
:param username: User name to authenticate as.
:type username: str
:param password: User's password.
:type password: str
:param actions: If you know which types of operation you need to make on the registry, specify them here. Valid actions are ``pull``, ``push`` and ``*``.
:type actions: list
:param response: When the ``auth`` function you passed to :class:`DXFBase`'s constructor is called, it is passed a HTTP response object. Pass it back to :meth:`authenticate` to have it automatically detect which actions are required.
:type response: requests.Response
:param authorization: ``Authorization`` header value.
:type authorization: str
:rtype: str
:returns: Authentication token, if the registry supports bearer tokens. Otherwise ``None``, and HTTP Basic auth is used (if the registry requires authentication).
"""
if response is None:
with warnings.catch_warnings():
_ignore_warnings(self)
response = self._sessions[0].get(self._base_url, verify=self._tlsverify)
if response.ok:
return None
# pylint: disable=no-member
if response.status_code != requests.codes.unauthorized:
raise exceptions.DXFUnexpectedStatusCodeError(response.status_code,
requests.codes.unauthorized)
if self._insecure:
raise exceptions.DXFAuthInsecureError()
parsed = www_authenticate.parse(response.headers['www-authenticate'])
if username is not None and password is not None:
headers = {
'Authorization': 'Basic ' + base64.b64encode(_to_bytes_2and3(username + ':' + password)).decode('utf-8')
}
elif authorization is not None:
headers = {
'Authorization': authorization
}
else:
headers = {}
if 'bearer' in parsed:
info = parsed['bearer']
if actions and self._repo:
scope = 'repository:' + self._repo + ':' + ','.join(actions)
elif 'scope' in info:
scope = info['scope']
else:
scope = ''
url_parts = list(urlparse.urlparse(info['realm']))
query = urlparse.parse_qs(url_parts[4])
query.update({
'service': info['service'],
'scope': scope
})
url_parts[4] = urlencode(query, True)
url_parts[0] = 'https'
if self._auth_host:
url_parts[1] = self._auth_host
auth_url = urlparse.urlunparse(url_parts)
with warnings.catch_warnings():
_ignore_warnings(self)
r = self._sessions[0].get(auth_url, headers=headers, verify=self._tlsverify)
_raise_for_status(r)
rjson = r.json()
self.token = rjson['access_token'] if 'access_token' in rjson else rjson['token']
return self._token
self._headers = headers
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:parse; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ddl; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:source_database; 10, None; 11, block; 11, 12; 11, 14; 11, 25; 11, 36; 11, 48; 11, 61; 11, 62; 11, 77; 11, 87; 11, 100; 11, 234; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:is; 15, 16; 15, 17; 16, identifier:ddl; 17, None; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_ddl; 24, identifier:ddl; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:source_database; 28, None; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:source_database; 35, identifier:source_database; 36, if_statement; 36, 37; 36, 42; 37, comparison_operator:is; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:_ddl; 41, None; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:ValueError; 46, argument_list; 46, 47; 47, string:"DDL is not specified"; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:ret; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_DDL_PARSE_EXPR; 56, identifier:parseString; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_ddl; 61, comment; 62, if_statement; 62, 63; 62, 66; 63, comparison_operator:in; 63, 64; 63, 65; 64, string:"schema"; 65, identifier:ret; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:_table; 73, identifier:schema; 74, subscript; 74, 75; 74, 76; 75, identifier:ret; 76, string:"schema"; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_table; 83, identifier:name; 84, subscript; 84, 85; 84, 86; 85, identifier:ret; 86, string:"table"; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:_table; 93, identifier:is_temp; 94, conditional_expression:if; 94, 95; 94, 96; 94, 99; 95, True; 96, comparison_operator:in; 96, 97; 96, 98; 97, string:"temp"; 98, identifier:ret; 99, False; 100, for_statement; 100, 101; 100, 102; 100, 105; 101, identifier:ret_col; 102, subscript; 102, 103; 102, 104; 103, identifier:ret; 104, string:"columns"; 105, block; 105, 106; 106, if_statement; 106, 107; 106, 114; 106, 115; 106, 161; 107, comparison_operator:==; 107, 108; 107, 113; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:ret_col; 111, identifier:getName; 112, argument_list; 113, string:"column"; 114, comment; 115, block; 115, 116; 115, 148; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:col; 119, call; 119, 120; 119, 127; 120, attribute; 120, 121; 120, 126; 121, attribute; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_table; 125, identifier:columns; 126, identifier:append; 127, argument_list; 127, 128; 127, 133; 127, 138; 128, keyword_argument; 128, 129; 128, 130; 129, identifier:column_name; 130, subscript; 130, 131; 130, 132; 131, identifier:ret_col; 132, string:"name"; 133, keyword_argument; 133, 134; 133, 135; 134, identifier:data_type_array; 135, subscript; 135, 136; 135, 137; 136, identifier:ret_col; 137, string:"type"; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:array_brackets; 140, conditional_expression:if; 140, 141; 140, 144; 140, 147; 141, subscript; 141, 142; 141, 143; 142, identifier:ret_col; 143, string:'array_brackets'; 144, comparison_operator:in; 144, 145; 144, 146; 145, string:"array_brackets"; 146, identifier:ret_col; 147, None; 148, if_statement; 148, 149; 148, 152; 149, comparison_operator:in; 149, 150; 149, 151; 150, string:"constraint"; 151, identifier:ret_col; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:col; 157, identifier:constraint; 158, subscript; 158, 159; 158, 160; 159, identifier:ret_col; 160, string:"constraint"; 161, elif_clause; 161, 162; 161, 169; 161, 170; 162, comparison_operator:==; 162, 163; 162, 168; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:ret_col; 166, identifier:getName; 167, argument_list; 168, string:"constraint"; 169, comment; 170, block; 170, 171; 171, for_statement; 171, 172; 171, 173; 171, 176; 172, identifier:col_name; 173, subscript; 173, 174; 173, 175; 174, identifier:ret_col; 175, string:"constraint_columns"; 176, block; 176, 177; 176, 187; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:col; 180, subscript; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:_table; 185, identifier:columns; 186, identifier:col_name; 187, if_statement; 187, 188; 187, 193; 187, 206; 187, 221; 188, comparison_operator:==; 188, 189; 188, 192; 189, subscript; 189, 190; 189, 191; 190, identifier:ret_col; 191, string:"type"; 192, string:"PRIMARY KEY"; 193, block; 193, 194; 193, 200; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:col; 198, identifier:not_null; 199, True; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:col; 204, identifier:primary_key; 205, True; 206, elif_clause; 206, 207; 206, 214; 207, comparison_operator:in; 207, 208; 207, 211; 208, subscript; 208, 209; 208, 210; 209, identifier:ret_col; 210, string:"type"; 211, list:["UNIQUE", "UNIQUE KEY"]; 211, 212; 211, 213; 212, string:"UNIQUE"; 213, string:"UNIQUE KEY"; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:col; 219, identifier:unique; 220, True; 221, elif_clause; 221, 222; 221, 227; 222, comparison_operator:==; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:ret_col; 225, string:"type"; 226, string:"NOT NULL"; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:col; 232, identifier:not_null; 233, True; 234, return_statement; 234, 235; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:_table | def parse(self, ddl=None, source_database=None):
"""
Parse DDL script.
:param ddl: DDL script
:return: DdlParseTable, Parsed table define info.
"""
if ddl is not None:
self._ddl = ddl
if source_database is not None:
self.source_database = source_database
if self._ddl is None:
raise ValueError("DDL is not specified")
ret = self._DDL_PARSE_EXPR.parseString(self._ddl)
# print(ret.dump())
if "schema" in ret:
self._table.schema = ret["schema"]
self._table.name = ret["table"]
self._table.is_temp = True if "temp" in ret else False
for ret_col in ret["columns"]:
if ret_col.getName() == "column":
# add column
col = self._table.columns.append(
column_name=ret_col["name"],
data_type_array=ret_col["type"],
array_brackets=ret_col['array_brackets'] if "array_brackets" in ret_col else None)
if "constraint" in ret_col:
col.constraint = ret_col["constraint"]
elif ret_col.getName() == "constraint":
# set column constraint
for col_name in ret_col["constraint_columns"]:
col = self._table.columns[col_name]
if ret_col["type"] == "PRIMARY KEY":
col.not_null = True
col.primary_key = True
elif ret_col["type"] in ["UNIQUE", "UNIQUE KEY"]:
col.unique = True
elif ret_col["type"] == "NOT NULL":
col.not_null = True
return self._table |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_next_valid_time_from_t; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:timestamp; 6, block; 6, 7; 6, 9; 6, 19; 6, 20; 6, 29; 6, 36; 6, 37; 6, 38; 6, 64; 6, 82; 6, 83; 6, 84; 6, 93; 6, 102; 6, 111; 6, 124; 6, 125; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 16; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:is_time_valid; 14, argument_list; 14, 15; 15, identifier:timestamp; 16, block; 16, 17; 17, return_statement; 17, 18; 18, identifier:timestamp; 19, comment; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:t_day; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:get_next_valid_day; 27, argument_list; 27, 28; 28, identifier:timestamp; 29, if_statement; 29, 30; 29, 33; 30, comparison_operator:is; 30, 31; 30, 32; 31, identifier:t_day; 32, None; 33, block; 33, 34; 34, return_statement; 34, 35; 35, identifier:t_day; 36, comment; 37, comment; 38, if_statement; 38, 39; 38, 42; 38, 52; 39, comparison_operator:<; 39, 40; 39, 41; 40, identifier:timestamp; 41, identifier:t_day; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:sec_from_morning; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:get_next_future_timerange_valid; 50, argument_list; 50, 51; 51, identifier:t_day; 52, else_clause; 52, 53; 52, 54; 53, comment; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:sec_from_morning; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:get_next_future_timerange_valid; 62, argument_list; 62, 63; 63, identifier:timestamp; 64, if_statement; 64, 65; 64, 68; 65, comparison_operator:is; 65, 66; 65, 67; 66, identifier:sec_from_morning; 67, None; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 77; 70, boolean_operator:and; 70, 71; 70, 74; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:t_day; 73, None; 74, comparison_operator:is; 74, 75; 74, 76; 75, identifier:sec_from_morning; 76, None; 77, block; 77, 78; 78, return_statement; 78, 79; 79, binary_operator:+; 79, 80; 79, 81; 80, identifier:t_day; 81, identifier:sec_from_morning; 82, comment; 83, comment; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:timestamp; 87, binary_operator:+; 87, 88; 87, 92; 88, call; 88, 89; 88, 90; 89, identifier:get_day; 90, argument_list; 90, 91; 91, identifier:timestamp; 92, integer:86400; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:t_day2; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:get_next_valid_day; 100, argument_list; 100, 101; 101, identifier:timestamp; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:sec_from_morning; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:get_next_future_timerange_valid; 109, argument_list; 109, 110; 110, identifier:t_day2; 111, if_statement; 111, 112; 111, 119; 112, boolean_operator:and; 112, 113; 112, 116; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:t_day2; 115, None; 116, comparison_operator:is; 116, 117; 116, 118; 117, identifier:sec_from_morning; 118, None; 119, block; 119, 120; 120, return_statement; 120, 121; 121, binary_operator:+; 121, 122; 121, 123; 122, identifier:t_day2; 123, identifier:sec_from_morning; 124, comment; 125, return_statement; 125, 126; 126, None | def get_next_valid_time_from_t(self, timestamp):
"""Get next valid time for time range
:param timestamp: time we compute from
:type timestamp: int
:return: timestamp of the next valid time (LOCAL TIME)
:rtype: int | None
"""
if self.is_time_valid(timestamp):
return timestamp
# First we search for the day of t
t_day = self.get_next_valid_day(timestamp)
if t_day is None:
return t_day
# We search for the min of all tr.start > sec_from_morning
# if it's the next day, use a start of the day search for timerange
if timestamp < t_day:
sec_from_morning = self.get_next_future_timerange_valid(t_day)
else: # it is in this day, so look from t (can be in the evening or so)
sec_from_morning = self.get_next_future_timerange_valid(timestamp)
if sec_from_morning is not None:
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning
# Then we search for the next day of t
# The sec will be the min of the day
timestamp = get_day(timestamp) + 86400
t_day2 = self.get_next_valid_day(timestamp)
sec_from_morning = self.get_next_future_timerange_valid(t_day2)
if t_day2 is not None and sec_from_morning is not None:
return t_day2 + sec_from_morning
# I did not found any valid time
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_next_invalid_time_from_t; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:timestamp; 6, block; 6, 7; 6, 9; 6, 20; 6, 21; 6, 30; 6, 31; 6, 32; 6, 58; 6, 59; 6, 60; 6, 61; 6, 62; 6, 77; 6, 78; 6, 79; 6, 90; 6, 91; 6, 92; 6, 101; 6, 110; 6, 119; 6, 134; 6, 145; 6, 146; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 17; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:is_time_valid; 15, argument_list; 15, 16; 16, identifier:timestamp; 17, block; 17, 18; 18, return_statement; 18, 19; 19, identifier:timestamp; 20, comment; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:t_day; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:get_next_invalid_day; 28, argument_list; 28, 29; 29, identifier:timestamp; 30, comment; 31, comment; 32, if_statement; 32, 33; 32, 36; 32, 46; 33, comparison_operator:<; 33, 34; 33, 35; 34, identifier:timestamp; 35, identifier:t_day; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:sec_from_morning; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:get_next_future_timerange_invalid; 44, argument_list; 44, 45; 45, identifier:t_day; 46, else_clause; 46, 47; 46, 48; 47, comment; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:sec_from_morning; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:get_next_future_timerange_invalid; 56, argument_list; 56, 57; 57, identifier:timestamp; 58, comment; 59, comment; 60, comment; 61, comment; 62, if_statement; 62, 63; 62, 70; 63, boolean_operator:and; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:t_day; 66, None; 67, comparison_operator:is; 67, 68; 67, 69; 68, identifier:sec_from_morning; 69, None; 70, block; 70, 71; 71, return_statement; 71, 72; 72, binary_operator:+; 72, 73; 72, 76; 73, binary_operator:+; 73, 74; 73, 75; 74, identifier:t_day; 75, identifier:sec_from_morning; 76, integer:1; 77, comment; 78, comment; 79, if_statement; 79, 80; 79, 87; 80, boolean_operator:and; 80, 81; 80, 84; 81, comparison_operator:is; 81, 82; 81, 83; 82, identifier:t_day; 83, None; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:sec_from_morning; 86, None; 87, block; 87, 88; 88, return_statement; 88, 89; 89, identifier:t_day; 90, comment; 91, comment; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:timestamp; 95, binary_operator:+; 95, 96; 95, 100; 96, call; 96, 97; 96, 98; 97, identifier:get_day; 98, argument_list; 98, 99; 99, identifier:timestamp; 100, integer:86400; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:t_day2; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:get_next_invalid_day; 108, argument_list; 108, 109; 109, identifier:timestamp; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:sec_from_morning; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:get_next_future_timerange_invalid; 117, argument_list; 117, 118; 118, identifier:t_day2; 119, if_statement; 119, 120; 119, 127; 120, boolean_operator:and; 120, 121; 120, 124; 121, comparison_operator:is; 121, 122; 121, 123; 122, identifier:t_day2; 123, None; 124, comparison_operator:is; 124, 125; 124, 126; 125, identifier:sec_from_morning; 126, None; 127, block; 127, 128; 128, return_statement; 128, 129; 129, binary_operator:+; 129, 130; 129, 133; 130, binary_operator:+; 130, 131; 130, 132; 131, identifier:t_day2; 132, identifier:sec_from_morning; 133, integer:1; 134, if_statement; 134, 135; 134, 142; 135, boolean_operator:and; 135, 136; 135, 139; 136, comparison_operator:is; 136, 137; 136, 138; 137, identifier:t_day2; 138, None; 139, comparison_operator:is; 139, 140; 139, 141; 140, identifier:sec_from_morning; 141, None; 142, block; 142, 143; 143, return_statement; 143, 144; 144, identifier:t_day2; 145, comment; 146, return_statement; 146, 147; 147, None | def get_next_invalid_time_from_t(self, timestamp):
"""Get next invalid time for time range
:param timestamp: time we compute from
:type timestamp: int
:return: timestamp of the next invalid time (LOCAL TIME)
:rtype: int
"""
if not self.is_time_valid(timestamp):
return timestamp
# First we search for the day of time range
t_day = self.get_next_invalid_day(timestamp)
# We search for the min of all tr.start > sec_from_morning
# if it's the next day, use a start of the day search for timerange
if timestamp < t_day:
sec_from_morning = self.get_next_future_timerange_invalid(t_day)
else: # it is in this day, so look from t (can be in the evening or so)
sec_from_morning = self.get_next_future_timerange_invalid(timestamp)
# tr can't be valid, or it will be return at the beginning
# sec_from_morning = self.get_next_future_timerange_invalid(t)
# Ok we've got a next invalid day and a invalid possibility in
# timerange, so the next invalid is this day+sec_from_morning
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning + 1
# We've got a day but no sec_from_morning: the timerange is full (0->24h)
# so the next invalid is this day at the day_start
if t_day is not None and sec_from_morning is None:
return t_day
# Then we search for the next day of t
# The sec will be the min of the day
timestamp = get_day(timestamp) + 86400
t_day2 = self.get_next_invalid_day(timestamp)
sec_from_morning = self.get_next_future_timerange_invalid(t_day2)
if t_day2 is not None and sec_from_morning is not None:
return t_day2 + sec_from_morning + 1
if t_day2 is not None and sec_from_morning is None:
return t_day2
# I did not found any valid time
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_start_and_end_time; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ref; 7, None; 8, block; 8, 9; 8, 11; 8, 20; 8, 35; 8, 53; 8, 66; 8, 81; 8, 99; 8, 112; 8, 121; 8, 284; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:now; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:time; 17, identifier:localtime; 18, argument_list; 18, 19; 19, identifier:ref; 20, if_statement; 20, 21; 20, 26; 21, comparison_operator:==; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:syear; 25, integer:0; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:syear; 32, attribute; 32, 33; 32, 34; 33, identifier:now; 34, identifier:tm_year; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:day_start; 38, call; 38, 39; 38, 40; 39, identifier:find_day_by_weekday_offset; 40, argument_list; 40, 41; 40, 44; 40, 47; 40, 50; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:syear; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:smon; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:swday; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:swday_offset; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:start_time; 56, call; 56, 57; 56, 58; 57, identifier:get_start_of_day; 58, argument_list; 58, 59; 58, 62; 58, 65; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:syear; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:smon; 65, identifier:day_start; 66, if_statement; 66, 67; 66, 72; 67, comparison_operator:==; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:eyear; 71, integer:0; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:eyear; 78, attribute; 78, 79; 78, 80; 79, identifier:now; 80, identifier:tm_year; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:day_end; 84, call; 84, 85; 84, 86; 85, identifier:find_day_by_weekday_offset; 86, argument_list; 86, 87; 86, 90; 86, 93; 86, 96; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:eyear; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:emon; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:ewday; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:ewday_offset; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:end_time; 102, call; 102, 103; 102, 104; 103, identifier:get_end_of_day; 104, argument_list; 104, 105; 104, 108; 104, 111; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:eyear; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:emon; 111, identifier:day_end; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:now_epoch; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:time; 118, identifier:mktime; 119, argument_list; 119, 120; 120, identifier:now; 121, if_statement; 121, 122; 121, 125; 121, 126; 121, 206; 122, comparison_operator:>; 122, 123; 122, 124; 123, identifier:start_time; 124, identifier:end_time; 125, comment; 126, block; 126, 127; 127, if_statement; 127, 128; 127, 131; 127, 132; 127, 168; 128, comparison_operator:>; 128, 129; 128, 130; 129, identifier:now_epoch; 130, identifier:end_time; 131, comment; 132, block; 132, 133; 132, 153; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:day_end; 136, call; 136, 137; 136, 138; 137, identifier:find_day_by_weekday_offset; 138, argument_list; 138, 139; 138, 144; 138, 147; 138, 150; 139, binary_operator:+; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:eyear; 143, integer:1; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:emon; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:ewday; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:ewday_offset; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:end_time; 156, call; 156, 157; 156, 158; 157, identifier:get_end_of_day; 158, argument_list; 158, 159; 158, 164; 158, 167; 159, binary_operator:+; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:eyear; 163, integer:1; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:emon; 167, identifier:day_end; 168, else_clause; 168, 169; 168, 170; 169, comment; 170, block; 170, 171; 170, 191; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:day_start; 174, call; 174, 175; 174, 176; 175, identifier:find_day_by_weekday_offset; 176, argument_list; 176, 177; 176, 182; 176, 185; 176, 188; 177, binary_operator:-; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:syear; 181, integer:1; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:smon; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:swday; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:swday_offset; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:start_time; 194, call; 194, 195; 194, 196; 195, identifier:get_start_of_day; 196, argument_list; 196, 197; 196, 202; 196, 205; 197, binary_operator:-; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:syear; 201, integer:1; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:smon; 205, identifier:day_start; 206, else_clause; 206, 207; 207, block; 207, 208; 208, if_statement; 208, 209; 208, 212; 208, 213; 209, comparison_operator:>; 209, 210; 209, 211; 210, identifier:now_epoch; 211, identifier:end_time; 212, comment; 213, block; 213, 214; 213, 234; 213, 249; 213, 269; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:day_start; 217, call; 217, 218; 217, 219; 218, identifier:find_day_by_weekday_offset; 219, argument_list; 219, 220; 219, 225; 219, 228; 219, 231; 220, binary_operator:+; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:syear; 224, integer:1; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:smon; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:swday; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:swday_offset; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:start_time; 237, call; 237, 238; 237, 239; 238, identifier:get_start_of_day; 239, argument_list; 239, 240; 239, 245; 239, 248; 240, binary_operator:+; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:syear; 244, integer:1; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:smon; 248, identifier:day_start; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:day_end; 252, call; 252, 253; 252, 254; 253, identifier:find_day_by_weekday_offset; 254, argument_list; 254, 255; 254, 260; 254, 263; 254, 266; 255, binary_operator:+; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:eyear; 259, integer:1; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:emon; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:ewday; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:ewday_offset; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:end_time; 272, call; 272, 273; 272, 274; 273, identifier:get_end_of_day; 274, argument_list; 274, 275; 274, 280; 274, 283; 275, binary_operator:+; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:eyear; 279, integer:1; 280, attribute; 280, 281; 280, 282; 281, identifier:self; 282, identifier:emon; 283, identifier:day_end; 284, return_statement; 284, 285; 285, tuple; 285, 286; 285, 287; 286, identifier:start_time; 287, identifier:end_time | def get_start_and_end_time(self, ref=None):
"""Specific function to get start time and end time for MonthWeekDayDaterange
:param ref: time in seconds
:type ref: int | None
:return: tuple with start and end time
:rtype: tuple
"""
now = time.localtime(ref)
if self.syear == 0:
self.syear = now.tm_year
day_start = find_day_by_weekday_offset(self.syear, self.smon, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear, self.smon, day_start)
if self.eyear == 0:
self.eyear = now.tm_year
day_end = find_day_by_weekday_offset(self.eyear, self.emon, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear, self.emon, day_end)
now_epoch = time.mktime(now)
if start_time > end_time: # the period is between years
if now_epoch > end_time: # check for next year
day_end = find_day_by_weekday_offset(self.eyear + 1,
self.emon, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
else:
# it s just that the start was the last year
day_start = find_day_by_weekday_offset(self.syear - 1,
self.smon, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear - 1, self.smon, day_start)
else:
if now_epoch > end_time:
# just have to check for next year if necessary
day_start = find_day_by_weekday_offset(self.syear + 1,
self.smon, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear + 1, self.smon, day_start)
day_end = find_day_by_weekday_offset(self.eyear + 1,
self.emon, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
return (start_time, end_time) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_start_and_end_time; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ref; 7, None; 8, block; 8, 9; 8, 11; 8, 20; 8, 35; 8, 50; 8, 63; 8, 78; 8, 93; 8, 106; 8, 115; 8, 266; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:now; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:time; 17, identifier:localtime; 18, argument_list; 18, 19; 19, identifier:ref; 20, if_statement; 20, 21; 20, 26; 21, comparison_operator:==; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:syear; 25, integer:0; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:syear; 32, attribute; 32, 33; 32, 34; 33, identifier:now; 34, identifier:tm_year; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:day_start; 38, call; 38, 39; 38, 40; 39, identifier:find_day_by_offset; 40, argument_list; 40, 41; 40, 44; 40, 47; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:syear; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:smon; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:smday; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:start_time; 53, call; 53, 54; 53, 55; 54, identifier:get_start_of_day; 55, argument_list; 55, 56; 55, 59; 55, 62; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:syear; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:smon; 62, identifier:day_start; 63, if_statement; 63, 64; 63, 69; 64, comparison_operator:==; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:eyear; 68, integer:0; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:eyear; 75, attribute; 75, 76; 75, 77; 76, identifier:now; 77, identifier:tm_year; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:day_end; 81, call; 81, 82; 81, 83; 82, identifier:find_day_by_offset; 83, argument_list; 83, 84; 83, 87; 83, 90; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:eyear; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:emon; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:emday; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:end_time; 96, call; 96, 97; 96, 98; 97, identifier:get_end_of_day; 98, argument_list; 98, 99; 98, 102; 98, 105; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:eyear; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:emon; 105, identifier:day_end; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:now_epoch; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:time; 112, identifier:mktime; 113, argument_list; 113, 114; 114, identifier:now; 115, if_statement; 115, 116; 115, 119; 115, 120; 115, 194; 116, comparison_operator:>; 116, 117; 116, 118; 117, identifier:start_time; 118, identifier:end_time; 119, comment; 120, block; 120, 121; 121, if_statement; 121, 122; 121, 125; 121, 126; 121, 159; 122, comparison_operator:>; 122, 123; 122, 124; 123, identifier:now_epoch; 124, identifier:end_time; 125, comment; 126, block; 126, 127; 126, 144; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:day_end; 130, call; 130, 131; 130, 132; 131, identifier:find_day_by_offset; 132, argument_list; 132, 133; 132, 138; 132, 141; 133, binary_operator:+; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:eyear; 137, integer:1; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:emon; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:emday; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:end_time; 147, call; 147, 148; 147, 149; 148, identifier:get_end_of_day; 149, argument_list; 149, 150; 149, 155; 149, 158; 150, binary_operator:+; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:eyear; 154, integer:1; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:emon; 158, identifier:day_end; 159, else_clause; 159, 160; 159, 161; 160, comment; 161, block; 161, 162; 161, 179; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:day_start; 165, call; 165, 166; 165, 167; 166, identifier:find_day_by_offset; 167, argument_list; 167, 168; 167, 173; 167, 176; 168, binary_operator:-; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:syear; 172, integer:1; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:smon; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:emday; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:start_time; 182, call; 182, 183; 182, 184; 183, identifier:get_start_of_day; 184, argument_list; 184, 185; 184, 190; 184, 193; 185, binary_operator:-; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:syear; 189, integer:1; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:smon; 193, identifier:day_start; 194, else_clause; 194, 195; 195, block; 195, 196; 196, if_statement; 196, 197; 196, 200; 196, 201; 197, comparison_operator:>; 197, 198; 197, 199; 198, identifier:now_epoch; 199, identifier:end_time; 200, comment; 201, block; 201, 202; 201, 219; 201, 234; 201, 251; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:day_start; 205, call; 205, 206; 205, 207; 206, identifier:find_day_by_offset; 207, argument_list; 207, 208; 207, 213; 207, 216; 208, binary_operator:+; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:syear; 212, integer:1; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:smon; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:smday; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:start_time; 222, call; 222, 223; 222, 224; 223, identifier:get_start_of_day; 224, argument_list; 224, 225; 224, 230; 224, 233; 225, binary_operator:+; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:syear; 229, integer:1; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:smon; 233, identifier:day_start; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:day_end; 237, call; 237, 238; 237, 239; 238, identifier:find_day_by_offset; 239, argument_list; 239, 240; 239, 245; 239, 248; 240, binary_operator:+; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:eyear; 244, integer:1; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:emon; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:emday; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:end_time; 254, call; 254, 255; 254, 256; 255, identifier:get_end_of_day; 256, argument_list; 256, 257; 256, 262; 256, 265; 257, binary_operator:+; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:eyear; 261, integer:1; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:emon; 265, identifier:day_end; 266, return_statement; 266, 267; 267, tuple; 267, 268; 267, 269; 268, identifier:start_time; 269, identifier:end_time | def get_start_and_end_time(self, ref=None):
"""Specific function to get start time and end time for MonthDateDaterange
:param ref: time in seconds
:type ref: int
:return: tuple with start and end time
:rtype: tuple (int, int)
"""
now = time.localtime(ref)
if self.syear == 0:
self.syear = now.tm_year
day_start = find_day_by_offset(self.syear, self.smon, self.smday)
start_time = get_start_of_day(self.syear, self.smon, day_start)
if self.eyear == 0:
self.eyear = now.tm_year
day_end = find_day_by_offset(self.eyear, self.emon, self.emday)
end_time = get_end_of_day(self.eyear, self.emon, day_end)
now_epoch = time.mktime(now)
if start_time > end_time: # the period is between years
if now_epoch > end_time:
# check for next year
day_end = find_day_by_offset(self.eyear + 1, self.emon, self.emday)
end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
else:
# it s just that start was the last year
day_start = find_day_by_offset(self.syear - 1, self.smon, self.emday)
start_time = get_start_of_day(self.syear - 1, self.smon, day_start)
else:
if now_epoch > end_time:
# just have to check for next year if necessary
day_start = find_day_by_offset(self.syear + 1, self.smon, self.smday)
start_time = get_start_of_day(self.syear + 1, self.smon, day_start)
day_end = find_day_by_offset(self.eyear + 1, self.emon, self.emday)
end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
return (start_time, end_time) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_start_and_end_time; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ref; 7, None; 8, block; 8, 9; 8, 11; 8, 20; 8, 21; 8, 36; 8, 42; 8, 58; 8, 69; 8, 70; 8, 85; 8, 91; 8, 107; 8, 118; 8, 119; 8, 120; 8, 171; 8, 180; 8, 181; 8, 280; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:now; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:time; 17, identifier:localtime; 18, argument_list; 18, 19; 19, identifier:ref; 20, comment; 21, if_statement; 21, 22; 21, 27; 22, comparison_operator:==; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:syear; 26, integer:0; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:syear; 33, attribute; 33, 34; 33, 35; 34, identifier:now; 35, identifier:tm_year; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:month_start_id; 39, attribute; 39, 40; 39, 41; 40, identifier:now; 41, identifier:tm_mon; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:day_start; 45, call; 45, 46; 45, 47; 46, identifier:find_day_by_weekday_offset; 47, argument_list; 47, 48; 47, 51; 47, 52; 47, 55; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:syear; 51, identifier:month_start_id; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:swday; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:swday_offset; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:start_time; 61, call; 61, 62; 61, 63; 62, identifier:get_start_of_day; 63, argument_list; 63, 64; 63, 67; 63, 68; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:syear; 67, identifier:month_start_id; 68, identifier:day_start; 69, comment; 70, if_statement; 70, 71; 70, 76; 71, comparison_operator:==; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:eyear; 75, integer:0; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:eyear; 82, attribute; 82, 83; 82, 84; 83, identifier:now; 84, identifier:tm_year; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:month_end_id; 88, attribute; 88, 89; 88, 90; 89, identifier:now; 90, identifier:tm_mon; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:day_end; 94, call; 94, 95; 94, 96; 95, identifier:find_day_by_weekday_offset; 96, argument_list; 96, 97; 96, 100; 96, 101; 96, 104; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:eyear; 100, identifier:month_end_id; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:ewday; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:ewday_offset; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:end_time; 110, call; 110, 111; 110, 112; 111, identifier:get_end_of_day; 112, argument_list; 112, 113; 112, 116; 112, 117; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:eyear; 116, identifier:month_end_id; 117, identifier:day_end; 118, comment; 119, comment; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:>; 121, 122; 121, 123; 122, identifier:start_time; 123, identifier:end_time; 124, block; 124, 125; 124, 129; 124, 144; 124, 160; 125, expression_statement; 125, 126; 126, augmented_assignment:+=; 126, 127; 126, 128; 127, identifier:month_end_id; 128, integer:1; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:>; 130, 131; 130, 132; 131, identifier:month_end_id; 132, integer:12; 133, block; 133, 134; 133, 138; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:month_end_id; 137, integer:1; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:eyear; 143, integer:1; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:day_end; 147, call; 147, 148; 147, 149; 148, identifier:find_day_by_weekday_offset; 149, argument_list; 149, 150; 149, 153; 149, 154; 149, 157; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:eyear; 153, identifier:month_end_id; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:ewday; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:ewday_offset; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:end_time; 163, call; 163, 164; 163, 165; 164, identifier:get_end_of_day; 165, argument_list; 165, 166; 165, 169; 165, 170; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:eyear; 169, identifier:month_end_id; 170, identifier:day_end; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:now_epoch; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:time; 177, identifier:mktime; 178, argument_list; 178, 179; 179, identifier:now; 180, comment; 181, if_statement; 181, 182; 181, 185; 182, comparison_operator:<; 182, 183; 182, 184; 183, identifier:end_time; 184, identifier:now_epoch; 185, block; 185, 186; 185, 190; 185, 194; 185, 209; 185, 224; 185, 225; 185, 241; 185, 252; 185, 253; 185, 269; 186, expression_statement; 186, 187; 187, augmented_assignment:+=; 187, 188; 187, 189; 188, identifier:month_end_id; 189, integer:1; 190, expression_statement; 190, 191; 191, augmented_assignment:+=; 191, 192; 191, 193; 192, identifier:month_start_id; 193, integer:1; 194, if_statement; 194, 195; 194, 198; 195, comparison_operator:>; 195, 196; 195, 197; 196, identifier:month_end_id; 197, integer:12; 198, block; 198, 199; 198, 203; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:month_end_id; 202, integer:1; 203, expression_statement; 203, 204; 204, augmented_assignment:+=; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:eyear; 208, integer:1; 209, if_statement; 209, 210; 209, 213; 210, comparison_operator:>; 210, 211; 210, 212; 211, identifier:month_start_id; 212, integer:12; 213, block; 213, 214; 213, 218; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:month_start_id; 217, integer:1; 218, expression_statement; 218, 219; 219, augmented_assignment:+=; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:syear; 223, integer:1; 224, comment; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 228; 227, identifier:day_start; 228, call; 228, 229; 228, 230; 229, identifier:find_day_by_weekday_offset; 230, argument_list; 230, 231; 230, 234; 230, 235; 230, 238; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:syear; 234, identifier:month_start_id; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:swday; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:swday_offset; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:start_time; 244, call; 244, 245; 244, 246; 245, identifier:get_start_of_day; 246, argument_list; 246, 247; 246, 250; 246, 251; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:syear; 250, identifier:month_start_id; 251, identifier:day_start; 252, comment; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:day_end; 256, call; 256, 257; 256, 258; 257, identifier:find_day_by_weekday_offset; 258, argument_list; 258, 259; 258, 262; 258, 263; 258, 266; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:eyear; 262, identifier:month_end_id; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:ewday; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:ewday_offset; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:end_time; 272, call; 272, 273; 272, 274; 273, identifier:get_end_of_day; 274, argument_list; 274, 275; 274, 278; 274, 279; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:eyear; 278, identifier:month_end_id; 279, identifier:day_end; 280, return_statement; 280, 281; 281, tuple; 281, 282; 281, 283; 282, identifier:start_time; 283, identifier:end_time | def get_start_and_end_time(self, ref=None):
"""Specific function to get start time and end time for WeekDayDaterange
:param ref: time in seconds
:type ref: int
:return: tuple with start and end time
:rtype: tuple (int, int)
"""
now = time.localtime(ref)
# If no year, it's our year
if self.syear == 0:
self.syear = now.tm_year
month_start_id = now.tm_mon
day_start = find_day_by_weekday_offset(self.syear,
month_start_id, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear, month_start_id, day_start)
# Same for end year
if self.eyear == 0:
self.eyear = now.tm_year
month_end_id = now.tm_mon
day_end = find_day_by_weekday_offset(self.eyear, month_end_id, self.ewday,
self.ewday_offset)
end_time = get_end_of_day(self.eyear, month_end_id, day_end)
# Maybe end_time is before start. So look for the
# next month
if start_time > end_time:
month_end_id += 1
if month_end_id > 12:
month_end_id = 1
self.eyear += 1
day_end = find_day_by_weekday_offset(self.eyear,
month_end_id, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear, month_end_id, day_end)
now_epoch = time.mktime(now)
# But maybe we look not enought far. We should add a month
if end_time < now_epoch:
month_end_id += 1
month_start_id += 1
if month_end_id > 12:
month_end_id = 1
self.eyear += 1
if month_start_id > 12:
month_start_id = 1
self.syear += 1
# First start
day_start = find_day_by_weekday_offset(self.syear,
month_start_id, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear, month_start_id, day_start)
# Then end
day_end = find_day_by_weekday_offset(self.eyear,
month_end_id, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear, month_end_id, day_end)
return (start_time, end_time) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:flush; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:log; 7, False; 8, block; 8, 9; 8, 11; 8, 26; 8, 37; 8, 100; 8, 267; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 16; 12, not_operator; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:my_metrics; 16, block; 16, 17; 16, 24; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:logger; 21, identifier:debug; 22, argument_list; 22, 23; 23, string:"Flushing - no metrics to send"; 24, return_statement; 24, 25; 25, True; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:now; 29, call; 29, 30; 29, 31; 30, identifier:int; 31, argument_list; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:time; 35, identifier:time; 36, argument_list; 37, if_statement; 37, 38; 37, 51; 38, boolean_operator:and; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:last_failure; 42, comparison_operator:>; 42, 43; 42, 50; 43, binary_operator:+; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:last_failure; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:metrics_flush_pause; 50, identifier:now; 51, block; 51, 52; 51, 98; 52, if_statement; 52, 53; 52, 57; 53, not_operator; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:log_metrics_flush_pause; 57, block; 57, 58; 57, 78; 57, 92; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:date; 61, call; 61, 62; 61, 74; 62, attribute; 62, 63; 62, 73; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:datetime; 67, identifier:datetime; 68, identifier:fromtimestamp; 69, argument_list; 69, 70; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:last_failure; 73, identifier:strftime; 74, argument_list; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:date_fmt; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:logger; 82, identifier:warning; 83, argument_list; 83, 84; 83, 88; 83, 89; 84, concatenated_string; 84, 85; 84, 86; 84, 87; 85, string:"Metrics flush paused on connection error "; 86, string:"(last failed: %s). "; 87, string:"Inner stored metric: %d. Trying to send..."; 88, identifier:date; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:metrics_count; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:log_metrics_flush_pause; 97, True; 98, return_statement; 98, 99; 99, True; 100, try_statement; 100, 101; 100, 187; 101, block; 101, 102; 101, 112; 101, 158; 101, 175; 101, 181; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:logger; 106, identifier:debug; 107, argument_list; 107, 108; 107, 109; 108, string:"Flushing %d metrics to Graphite/carbon"; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:metrics_count; 112, if_statement; 112, 113; 112, 120; 112, 127; 113, call; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:carbon; 118, identifier:send_data; 119, argument_list; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:my_metrics; 126, list:[]; 127, else_clause; 127, 128; 128, block; 128, 129; 128, 141; 128, 156; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:logger; 133, identifier:warning; 134, argument_list; 134, 135; 134, 138; 135, concatenated_string; 135, 136; 135, 137; 136, string:"Failed sending metrics to Graphite/carbon. "; 137, string:"Inner stored metric: %d"; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:metrics_count; 141, if_statement; 141, 142; 141, 143; 142, identifier:log; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:logger; 148, identifier:warning; 149, argument_list; 149, 150; 149, 153; 150, concatenated_string; 150, 151; 150, 152; 151, string:"Failed sending metrics to Graphite/carbon. "; 152, string:"Inner stored metric: %d"; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:metrics_count; 156, return_statement; 156, 157; 157, False; 158, if_statement; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:log_metrics_flush_pause; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:logger; 167, identifier:warning; 168, argument_list; 168, 169; 168, 172; 169, concatenated_string; 169, 170; 169, 171; 170, string:"Metrics flush restored. "; 171, string:"Remaining stored metric: %d"; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:metrics_count; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:last_failure; 180, integer:0; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:log_metrics_flush_pause; 186, False; 187, except_clause; 187, 188; 187, 192; 187, 193; 188, as_pattern; 188, 189; 188, 190; 189, identifier:Exception; 190, as_pattern_target; 190, 191; 191, identifier:exp; 192, comment; 193, block; 193, 194; 193, 248; 193, 259; 193, 265; 194, if_statement; 194, 195; 194, 199; 194, 212; 195, not_operator; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:log_metrics_flush_pause; 199, block; 199, 200; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:logger; 204, identifier:warning; 205, argument_list; 205, 206; 205, 209; 206, concatenated_string; 206, 207; 206, 208; 207, string:"Failed sending metrics to Graphite/carbon. "; 208, string:"Inner stored metric: %d"; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:metrics_count; 212, else_clause; 212, 213; 213, block; 213, 214; 213, 234; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:date; 217, call; 217, 218; 217, 230; 218, attribute; 218, 219; 218, 229; 219, call; 219, 220; 219, 225; 220, attribute; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:datetime; 223, identifier:datetime; 224, identifier:fromtimestamp; 225, argument_list; 225, 226; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:last_failure; 229, identifier:strftime; 230, argument_list; 230, 231; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:date_fmt; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:logger; 238, identifier:warning; 239, argument_list; 239, 240; 239, 244; 239, 245; 240, concatenated_string; 240, 241; 240, 242; 240, 243; 241, string:"Metrics flush paused on connection error "; 242, string:"(last failed: %s). "; 243, string:"Inner stored metric: %d. Trying to send..."; 244, identifier:date; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:metrics_count; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:logger; 252, identifier:warning; 253, argument_list; 253, 254; 253, 255; 254, string:"Exception: %s"; 255, call; 255, 256; 255, 257; 256, identifier:str; 257, argument_list; 257, 258; 258, identifier:exp; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:self; 263, identifier:last_failure; 264, identifier:now; 265, return_statement; 265, 266; 266, False; 267, return_statement; 267, 268; 268, True | def flush(self, log=False):
"""Send inner stored metrics to the defined Graphite
Returns False if the sending failed with a warning log if log parameter is set
:return: bool
"""
if not self.my_metrics:
logger.debug("Flushing - no metrics to send")
return True
now = int(time.time())
if self.last_failure and self.last_failure + self.metrics_flush_pause > now:
if not self.log_metrics_flush_pause:
date = datetime.datetime.fromtimestamp(
self.last_failure).strftime(self.date_fmt)
logger.warning("Metrics flush paused on connection error "
"(last failed: %s). "
"Inner stored metric: %d. Trying to send...",
date, self.metrics_count)
self.log_metrics_flush_pause = True
return True
try:
logger.debug("Flushing %d metrics to Graphite/carbon", self.metrics_count)
if self.carbon.send_data():
self.my_metrics = []
else:
logger.warning("Failed sending metrics to Graphite/carbon. "
"Inner stored metric: %d", self.metrics_count)
if log:
logger.warning("Failed sending metrics to Graphite/carbon. "
"Inner stored metric: %d", self.metrics_count)
return False
if self.log_metrics_flush_pause:
logger.warning("Metrics flush restored. "
"Remaining stored metric: %d", self.metrics_count)
self.last_failure = 0
self.log_metrics_flush_pause = False
except Exception as exp: # pylint: disable=broad-except
if not self.log_metrics_flush_pause:
logger.warning("Failed sending metrics to Graphite/carbon. "
"Inner stored metric: %d", self.metrics_count)
else:
date = datetime.datetime.fromtimestamp(
self.last_failure).strftime(self.date_fmt)
logger.warning("Metrics flush paused on connection error "
"(last failed: %s). "
"Inner stored metric: %d. Trying to send...",
date, self.metrics_count)
logger.warning("Exception: %s", str(exp))
self.last_failure = now
return False
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:counter; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:key; 6, identifier:value; 7, default_parameter; 7, 8; 7, 9; 8, identifier:timestamp; 9, None; 10, block; 10, 11; 10, 13; 10, 33; 10, 37; 10, 41; 10, 54; 10, 67; 10, 79; 10, 80; 10, 139; 10, 140; 10, 160; 10, 161; 10, 297; 10, 362; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 20; 15, pattern_list; 15, 16; 15, 17; 15, 18; 15, 19; 16, identifier:_min; 17, identifier:_max; 18, identifier:count; 19, identifier:_sum; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:stats; 25, identifier:get; 26, argument_list; 26, 27; 26, 28; 27, identifier:key; 28, tuple; 28, 29; 28, 30; 28, 31; 28, 32; 29, None; 30, None; 31, integer:0; 32, integer:0; 33, expression_statement; 33, 34; 34, augmented_assignment:+=; 34, 35; 34, 36; 35, identifier:count; 36, integer:1; 37, expression_statement; 37, 38; 38, augmented_assignment:+=; 38, 39; 38, 40; 39, identifier:_sum; 40, identifier:value; 41, if_statement; 41, 42; 41, 49; 42, boolean_operator:or; 42, 43; 42, 46; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:_min; 45, None; 46, comparison_operator:<; 46, 47; 46, 48; 47, identifier:value; 48, identifier:_min; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:_min; 53, identifier:value; 54, if_statement; 54, 55; 54, 62; 55, boolean_operator:or; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:_max; 58, None; 59, comparison_operator:>; 59, 60; 59, 61; 60, identifier:value; 61, identifier:_max; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:_max; 66, identifier:value; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 74; 69, subscript; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:stats; 73, identifier:key; 74, tuple; 74, 75; 74, 76; 74, 77; 74, 78; 75, identifier:_min; 76, identifier:_max; 77, identifier:count; 78, identifier:_sum; 79, comment; 80, if_statement; 80, 81; 80, 88; 80, 89; 81, boolean_operator:and; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:statsd_enabled; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:statsd_sock; 88, comment; 89, block; 89, 90; 89, 104; 89, 113; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:packet; 93, binary_operator:%; 93, 94; 93, 95; 94, string:'%s.%s.%s:%d|c'; 95, tuple; 95, 96; 95, 99; 95, 102; 95, 103; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:statsd_prefix; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:name; 102, identifier:key; 103, identifier:value; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:packet; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:packet; 110, identifier:encode; 111, argument_list; 111, 112; 112, string:'utf-8'; 113, try_statement; 113, 114; 113, 127; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:statsd_sock; 121, identifier:sendto; 122, argument_list; 122, 123; 122, 124; 123, identifier:packet; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:statsd_addr; 127, except_clause; 127, 128; 127, 135; 128, tuple; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:socket; 131, identifier:error; 132, attribute; 132, 133; 132, 134; 133, identifier:socket; 134, identifier:gaierror; 135, block; 135, 136; 135, 137; 135, 138; 136, pass_statement; 137, comment; 138, comment; 139, comment; 140, if_statement; 140, 141; 140, 148; 141, boolean_operator:and; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:statsd_enabled; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:carbon; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:send_to_graphite; 154, argument_list; 154, 155; 154, 156; 154, 157; 155, identifier:key; 156, identifier:value; 157, keyword_argument; 157, 158; 157, 159; 158, identifier:timestamp; 159, identifier:timestamp; 160, comment; 161, if_statement; 161, 162; 161, 169; 162, boolean_operator:and; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:statsd_enabled; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:file_d; 169, block; 169, 170; 169, 186; 169, 192; 169, 224; 169, 234; 169, 253; 169, 265; 169, 275; 170, if_statement; 170, 171; 170, 174; 171, comparison_operator:is; 171, 172; 171, 173; 172, identifier:timestamp; 173, None; 174, block; 174, 175; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:timestamp; 178, call; 178, 179; 178, 180; 179, identifier:int; 180, argument_list; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:time; 184, identifier:time; 185, argument_list; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:packet; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:line_fmt; 192, if_statement; 192, 193; 192, 197; 192, 204; 193, not_operator; 193, 194; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:date_fmt; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:date; 201, binary_operator:%; 201, 202; 201, 203; 202, string:"%s"; 203, identifier:timestamp; 204, else_clause; 204, 205; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 209; 208, identifier:date; 209, call; 209, 210; 209, 220; 210, attribute; 210, 211; 210, 219; 211, call; 211, 212; 211, 217; 212, attribute; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:datetime; 215, identifier:datetime; 216, identifier:fromtimestamp; 217, argument_list; 217, 218; 218, identifier:timestamp; 219, identifier:strftime; 220, argument_list; 220, 221; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:date_fmt; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:packet; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:packet; 230, identifier:replace; 231, argument_list; 231, 232; 231, 233; 232, string:"#date#"; 233, identifier:date; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:packet; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:packet; 240, identifier:replace; 241, argument_list; 241, 242; 241, 243; 242, string:"#counter#"; 243, binary_operator:%; 243, 244; 243, 245; 244, string:'%s.%s.%s'; 245, tuple; 245, 246; 245, 249; 245, 252; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:statsd_prefix; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:name; 252, identifier:key; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:packet; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:packet; 259, identifier:replace; 260, argument_list; 260, 261; 260, 262; 261, string:"#value#"; 262, binary_operator:%; 262, 263; 262, 264; 263, string:'%d'; 264, identifier:value; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:packet; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:packet; 271, identifier:replace; 272, argument_list; 272, 273; 272, 274; 273, string:"#uom#"; 274, string:'c'; 275, try_statement; 275, 276; 275, 286; 276, block; 276, 277; 277, expression_statement; 277, 278; 278, call; 278, 279; 278, 284; 279, attribute; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:self; 282, identifier:file_d; 283, identifier:write; 284, argument_list; 284, 285; 285, identifier:packet; 286, except_clause; 286, 287; 286, 288; 287, identifier:IOError; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:logger; 293, identifier:warning; 294, argument_list; 294, 295; 294, 296; 295, string:"Could not write to the file: %s"; 296, identifier:packet; 297, if_statement; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:self; 300, identifier:broks_enabled; 301, block; 301, 302; 301, 311; 301, 327; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:logger; 306, identifier:debug; 307, argument_list; 307, 308; 307, 309; 307, 310; 308, string:"alignak stat brok: %s = %s"; 309, identifier:key; 310, identifier:value; 311, if_statement; 311, 312; 311, 315; 312, comparison_operator:is; 312, 313; 312, 314; 313, identifier:timestamp; 314, None; 315, block; 315, 316; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:timestamp; 319, call; 319, 320; 319, 321; 320, identifier:int; 321, argument_list; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:time; 325, identifier:time; 326, argument_list; 327, return_statement; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:Brok; 330, argument_list; 330, 331; 331, dictionary; 331, 332; 331, 335; 332, pair; 332, 333; 332, 334; 333, string:'type'; 334, string:'alignak_stat'; 335, pair; 335, 336; 335, 337; 336, string:'data'; 337, dictionary; 337, 338; 337, 341; 337, 344; 337, 356; 337, 359; 338, pair; 338, 339; 338, 340; 339, string:'ts'; 340, identifier:timestamp; 341, pair; 341, 342; 341, 343; 342, string:'type'; 343, string:'counter'; 344, pair; 344, 345; 344, 346; 345, string:'metric'; 346, binary_operator:%; 346, 347; 346, 348; 347, string:'%s.%s.%s'; 348, tuple; 348, 349; 348, 352; 348, 355; 349, attribute; 349, 350; 349, 351; 350, identifier:self; 351, identifier:statsd_prefix; 352, attribute; 352, 353; 352, 354; 353, identifier:self; 354, identifier:name; 355, identifier:key; 356, pair; 356, 357; 356, 358; 357, string:'value'; 358, identifier:value; 359, pair; 359, 360; 359, 361; 360, string:'uom'; 361, string:'c'; 362, return_statement; 362, 363; 363, None | def counter(self, key, value, timestamp=None):
"""Set a counter value
If the inner key does not exist is is created
:param key: counter to update
:type key: str
:param value: counter value
:type value: float
:return: An alignak_stat brok if broks are enabled else None
"""
_min, _max, count, _sum = self.stats.get(key, (None, None, 0, 0))
count += 1
_sum += value
if _min is None or value < _min:
_min = value
if _max is None or value > _max:
_max = value
self.stats[key] = (_min, _max, count, _sum)
# Manage local statsd part
if self.statsd_enabled and self.statsd_sock:
# beware, we are sending ms here, timer is in seconds
packet = '%s.%s.%s:%d|c' % (self.statsd_prefix, self.name, key, value)
packet = packet.encode('utf-8')
try:
self.statsd_sock.sendto(packet, self.statsd_addr)
except (socket.error, socket.gaierror):
pass
# cannot send? ok not a huge problem here and we cannot
# log because it will be far too verbose :p
# Manage Graphite part
if self.statsd_enabled and self.carbon:
self.send_to_graphite(key, value, timestamp=timestamp)
# Manage file part
if self.statsd_enabled and self.file_d:
if timestamp is None:
timestamp = int(time.time())
packet = self.line_fmt
if not self.date_fmt:
date = "%s" % timestamp
else:
date = datetime.datetime.fromtimestamp(timestamp).strftime(self.date_fmt)
packet = packet.replace("#date#", date)
packet = packet.replace("#counter#", '%s.%s.%s' % (self.statsd_prefix, self.name, key))
packet = packet.replace("#value#", '%d' % value)
packet = packet.replace("#uom#", 'c')
try:
self.file_d.write(packet)
except IOError:
logger.warning("Could not write to the file: %s", packet)
if self.broks_enabled:
logger.debug("alignak stat brok: %s = %s", key, value)
if timestamp is None:
timestamp = int(time.time())
return Brok({'type': 'alignak_stat',
'data': {
'ts': timestamp,
'type': 'counter',
'metric': '%s.%s.%s' % (self.statsd_prefix, self.name, key),
'value': value,
'uom': 'c'
}})
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:create_and_launch_worker; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:module_name; 7, string:'fork'; 8, block; 8, 9; 8, 11; 8, 19; 8, 20; 8, 24; 8, 28; 8, 104; 8, 105; 8, 106; 8, 112; 8, 139; 8, 140; 8, 141; 8, 153; 8, 154; 8, 155; 8, 169; 8, 170; 8, 176; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logger; 15, identifier:info; 16, argument_list; 16, 17; 16, 18; 17, string:"Allocating new '%s' worker..."; 18, identifier:module_name; 19, comment; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:target; 23, None; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:__warned; 27, list:[]; 28, if_statement; 28, 29; 28, 32; 28, 37; 29, comparison_operator:==; 29, 30; 29, 31; 30, identifier:module_name; 31, string:'fork'; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:target; 36, None; 37, else_clause; 37, 38; 38, block; 38, 39; 38, 78; 39, for_statement; 39, 40; 39, 41; 39, 46; 39, 47; 40, identifier:module; 41, attribute; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:modules_manager; 45, identifier:instances; 46, comment; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 56; 48, 57; 49, comparison_operator:==; 49, 50; 49, 55; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:module; 53, identifier:get_name; 54, argument_list; 55, identifier:module_name; 56, comment; 57, block; 57, 58; 57, 72; 58, if_statement; 58, 59; 58, 69; 59, not_operator; 59, 60; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:module; 64, identifier:properties; 65, identifier:get; 66, argument_list; 66, 67; 66, 68; 67, string:'worker_capable'; 68, False; 69, block; 69, 70; 70, raise_statement; 70, 71; 71, identifier:NotWorkerMod; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:target; 75, attribute; 75, 76; 75, 77; 76, identifier:module; 77, identifier:work; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:is; 79, 80; 79, 81; 80, identifier:target; 81, None; 82, block; 82, 83; 82, 103; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:not; 84, 85; 84, 86; 85, identifier:module_name; 86, identifier:__warned; 87, block; 87, 88; 87, 96; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:logger; 92, identifier:warning; 93, argument_list; 93, 94; 93, 95; 94, string:"No target found for %s, NOT creating a worker for it..."; 95, identifier:module_name; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:__warned; 100, identifier:append; 101, argument_list; 101, 102; 102, identifier:module_name; 103, return_statement; 104, comment; 105, comment; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:queue; 109, call; 109, 110; 109, 111; 110, identifier:Queue; 111, argument_list; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:worker; 115, call; 115, 116; 115, 117; 116, identifier:Worker; 117, argument_list; 117, 118; 117, 119; 117, 120; 117, 123; 117, 126; 117, 131; 117, 134; 118, identifier:module_name; 119, identifier:queue; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:returns_queue; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:processes_by_worker; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:max_plugins_output_length; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:max_plugins_output_length; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:target; 133, identifier:target; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:loaded_into; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:name; 139, comment; 140, comment; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 152; 143, subscript; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:workers; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:worker; 150, identifier:get_id; 151, argument_list; 152, identifier:worker; 153, comment; 154, comment; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 168; 157, subscript; 157, 158; 157, 163; 158, subscript; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:q_by_mod; 162, identifier:module_name; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:worker; 166, identifier:get_id; 167, argument_list; 168, identifier:queue; 169, comment; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:worker; 174, identifier:start; 175, argument_list; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:logger; 180, identifier:info; 181, argument_list; 181, 182; 181, 183; 181, 184; 181, 189; 182, string:"Started '%s' worker: %s (pid=%d)"; 183, identifier:module_name; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:worker; 187, identifier:get_id; 188, argument_list; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:worker; 192, identifier:get_pid; 193, argument_list | def create_and_launch_worker(self, module_name='fork'):
"""Create and launch a new worker, and put it into self.workers
It can be mortal or not
:param module_name: the module name related to the worker
default is "fork" for no module
Indeed, it is actually the module 'python_name'
:type module_name: str
:return: None
"""
logger.info("Allocating new '%s' worker...", module_name)
# If we are in the fork module, we do not specify a target
target = None
__warned = []
if module_name == 'fork':
target = None
else:
for module in self.modules_manager.instances:
# First, see if the module name matches...
if module.get_name() == module_name:
# ... and then if is a 'worker' module one or not
if not module.properties.get('worker_capable', False):
raise NotWorkerMod
target = module.work
if target is None:
if module_name not in __warned:
logger.warning("No target found for %s, NOT creating a worker for it...",
module_name)
__warned.append(module_name)
return
# We give to the Worker the instance name of the daemon (eg. poller-master)
# and not the daemon type (poller)
queue = Queue()
worker = Worker(module_name, queue, self.returns_queue, self.processes_by_worker,
max_plugins_output_length=self.max_plugins_output_length,
target=target, loaded_into=self.name)
# worker.module_name = module_name
# save this worker
self.workers[worker.get_id()] = worker
# And save the Queue of this worker, with key = worker id
# self.q_by_mod[module_name][worker.uuid] = queue
self.q_by_mod[module_name][worker.get_id()] = queue
# Ok, all is good. Start it!
worker.start()
logger.info("Started '%s' worker: %s (pid=%d)",
module_name, worker.get_id(), worker.get_pid()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 1, 7; 2, function_name:check_and_del_zombie_workers; 3, parameters; 3, 4; 4, identifier:self; 5, comment; 6, comment; 7, block; 7, 8; 7, 10; 7, 11; 7, 12; 7, 26; 7, 30; 7, 120; 7, 121; 7, 122; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, comment; 12, for_statement; 12, 13; 12, 14; 12, 17; 13, identifier:p; 14, call; 14, 15; 14, 16; 15, identifier:active_children; 16, argument_list; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:logger; 22, identifier:debug; 23, argument_list; 23, 24; 23, 25; 24, string:"got child: %s"; 25, identifier:p; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:w_to_del; 29, list:[]; 30, for_statement; 30, 31; 30, 32; 30, 42; 30, 43; 30, 44; 30, 45; 31, identifier:worker; 32, call; 32, 33; 32, 34; 33, identifier:list; 34, argument_list; 34, 35; 35, call; 35, 36; 35, 41; 36, attribute; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:workers; 40, identifier:values; 41, argument_list; 42, comment; 43, comment; 44, comment; 45, block; 45, 46; 45, 63; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:logger; 50, identifier:debug; 51, argument_list; 51, 52; 51, 53; 51, 58; 52, string:"checking if worker %s (pid=%d) is alive"; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:worker; 56, identifier:get_id; 57, argument_list; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:worker; 61, identifier:get_pid; 62, argument_list; 63, if_statement; 63, 64; 63, 75; 64, boolean_operator:and; 64, 65; 64, 69; 65, not_operator; 65, 66; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:interrupted; 69, not_operator; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:worker; 73, identifier:is_alive; 74, argument_list; 75, block; 75, 76; 75, 93; 75, 94; 75, 100; 75, 109; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:logger; 80, identifier:warning; 81, argument_list; 81, 82; 81, 83; 81, 88; 82, string:"The worker %s (pid=%d) went down unexpectedly!"; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:worker; 86, identifier:get_id; 87, argument_list; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:worker; 91, identifier:get_pid; 92, argument_list; 93, comment; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:worker; 98, identifier:terminate; 99, argument_list; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:worker; 104, identifier:join; 105, argument_list; 105, 106; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:timeout; 108, integer:1; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:w_to_del; 113, identifier:append; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:worker; 118, identifier:get_id; 119, argument_list; 120, comment; 121, comment; 122, for_statement; 122, 123; 122, 124; 122, 125; 123, identifier:worker_id; 124, identifier:w_to_del; 125, block; 125, 126; 125, 134; 125, 135; 125, 149; 125, 197; 125, 198; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:worker; 129, subscript; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:workers; 133, identifier:worker_id; 134, comment; 135, delete_statement; 135, 136; 136, subscript; 136, 137; 136, 144; 137, subscript; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:q_by_mod; 141, attribute; 141, 142; 141, 143; 142, identifier:worker; 143, identifier:module_name; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:worker; 147, identifier:get_id; 148, argument_list; 149, for_statement; 149, 150; 149, 151; 149, 154; 150, identifier:scheduler_uuid; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:schedulers; 154, block; 154, 155; 154, 163; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:sched; 158, subscript; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:schedulers; 162, identifier:scheduler_uuid; 163, for_statement; 163, 164; 163, 165; 163, 175; 164, identifier:act; 165, call; 165, 166; 165, 167; 166, identifier:list; 167, argument_list; 167, 168; 168, call; 168, 169; 168, 174; 169, attribute; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:sched; 172, identifier:actions; 173, identifier:values; 174, argument_list; 175, block; 175, 176; 176, if_statement; 176, 177; 176, 188; 176, 189; 177, boolean_operator:and; 177, 178; 177, 183; 178, comparison_operator:==; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:act; 181, identifier:status; 182, identifier:ACT_STATUS_QUEUED; 183, comparison_operator:==; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:act; 186, identifier:my_worker; 187, identifier:worker_id; 188, comment; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:assign_to_a_queue; 195, argument_list; 195, 196; 196, identifier:act; 197, comment; 198, delete_statement; 198, 199; 199, subscript; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:self; 202, identifier:workers; 203, identifier:worker_id | def check_and_del_zombie_workers(self): # pragma: no cover, not with unit tests...
# pylint: disable= not-callable
"""Check if worker are fine and kill them if not.
Dispatch the actions in the worker to another one
TODO: see if unit tests would allow to check this code?
:return: None
"""
# Active children make a join with everyone, useful :)
# active_children()
for p in active_children():
logger.debug("got child: %s", p)
w_to_del = []
for worker in list(self.workers.values()):
# If a worker goes down and we did not ask him, it's not
# good: we can think that we have a worker and it's not True
# So we del it
logger.debug("checking if worker %s (pid=%d) is alive",
worker.get_id(), worker.get_pid())
if not self.interrupted and not worker.is_alive():
logger.warning("The worker %s (pid=%d) went down unexpectedly!",
worker.get_id(), worker.get_pid())
# Terminate immediately
worker.terminate()
worker.join(timeout=1)
w_to_del.append(worker.get_id())
# OK, now really del workers from queues
# And requeue the actions it was managed
for worker_id in w_to_del:
worker = self.workers[worker_id]
# Del the queue of the module queue
del self.q_by_mod[worker.module_name][worker.get_id()]
for scheduler_uuid in self.schedulers:
sched = self.schedulers[scheduler_uuid]
for act in list(sched.actions.values()):
if act.status == ACT_STATUS_QUEUED and act.my_worker == worker_id:
# Got a check that will NEVER return if we do not restart it
self.assign_to_a_queue(act)
# So now we can really forgot it
del self.workers[worker_id] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:add_actions; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:actions_list; 6, identifier:scheduler_instance_id; 7, block; 7, 8; 7, 10; 7, 11; 7, 15; 7, 64; 7, 80; 7, 88; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:scheduler_link; 14, None; 15, for_statement; 15, 16; 15, 17; 15, 20; 15, 53; 16, identifier:scheduler_id; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:schedulers; 20, block; 20, 21; 20, 33; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:logger; 25, identifier:debug; 26, argument_list; 26, 27; 26, 28; 27, string:"Trying to add an action, scheduler: %s"; 28, subscript; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:schedulers; 32, identifier:scheduler_id; 33, if_statement; 33, 34; 33, 43; 34, comparison_operator:==; 34, 35; 34, 36; 35, identifier:scheduler_instance_id; 36, attribute; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:schedulers; 41, identifier:scheduler_id; 42, identifier:instance_id; 43, block; 43, 44; 43, 52; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:scheduler_link; 47, subscript; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:schedulers; 51, identifier:scheduler_id; 52, break_statement; 53, else_clause; 53, 54; 54, block; 54, 55; 54, 63; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:logger; 59, identifier:error; 60, argument_list; 60, 61; 60, 62; 61, string:"Trying to add actions from an unknwown scheduler: %s"; 62, identifier:scheduler_instance_id; 63, return_statement; 64, if_statement; 64, 65; 64, 67; 65, not_operator; 65, 66; 66, identifier:scheduler_link; 67, block; 67, 68; 67, 79; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:logger; 72, identifier:error; 73, argument_list; 73, 74; 73, 77; 73, 78; 74, concatenated_string; 74, 75; 74, 76; 75, string:"Trying to add actions, but scheduler link is not found for: %s, "; 76, string:"actions: %s"; 77, identifier:scheduler_instance_id; 78, identifier:actions_list; 79, return_statement; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:logger; 84, identifier:debug; 85, argument_list; 85, 86; 85, 87; 86, string:"Found scheduler link: %s"; 87, identifier:scheduler_link; 88, for_statement; 88, 89; 88, 90; 88, 91; 88, 92; 89, identifier:action; 90, identifier:actions_list; 91, comment; 92, block; 92, 93; 92, 102; 92, 137; 92, 138; 92, 146; 92, 147; 92, 155; 92, 165; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:uuid; 96, call; 96, 97; 96, 98; 97, identifier:getattr; 98, argument_list; 98, 99; 98, 100; 98, 101; 99, identifier:action; 100, string:'uuid'; 101, None; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:uuid; 105, None; 106, block; 106, 107; 107, try_statement; 107, 108; 107, 125; 108, block; 108, 109; 108, 119; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:action; 112, call; 112, 113; 112, 114; 113, identifier:unserialize; 114, argument_list; 114, 115; 114, 116; 115, identifier:action; 116, keyword_argument; 116, 117; 116, 118; 117, identifier:no_load; 118, True; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:uuid; 122, attribute; 122, 123; 122, 124; 123, identifier:action; 124, identifier:uuid; 125, except_clause; 125, 126; 125, 127; 126, identifier:AlignakClassLookupException; 127, block; 127, 128; 127, 136; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:logger; 132, identifier:error; 133, argument_list; 133, 134; 133, 135; 134, string:'Cannot un-serialize action: %s'; 135, identifier:action; 136, continue_statement; 137, comment; 138, if_statement; 138, 139; 138, 144; 139, comparison_operator:in; 139, 140; 139, 141; 140, identifier:uuid; 141, attribute; 141, 142; 141, 143; 142, identifier:scheduler_link; 143, identifier:actions; 144, block; 144, 145; 145, continue_statement; 146, comment; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:action; 151, identifier:my_scheduler; 152, attribute; 152, 153; 152, 154; 153, identifier:scheduler_link; 154, identifier:uuid; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 164; 157, subscript; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:scheduler_link; 160, identifier:actions; 161, attribute; 161, 162; 161, 163; 162, identifier:action; 163, identifier:uuid; 164, identifier:action; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:assign_to_a_queue; 170, argument_list; 170, 171; 171, identifier:action | def add_actions(self, actions_list, scheduler_instance_id):
"""Add a list of actions to the satellite queues
:param actions_list: Actions list to add
:type actions_list: list
:param scheduler_instance_id: sheduler link to assign the actions to
:type scheduler_instance_id: SchedulerLink
:return: None
"""
# We check for new check in each schedulers and put the result in new_checks
scheduler_link = None
for scheduler_id in self.schedulers:
logger.debug("Trying to add an action, scheduler: %s", self.schedulers[scheduler_id])
if scheduler_instance_id == self.schedulers[scheduler_id].instance_id:
scheduler_link = self.schedulers[scheduler_id]
break
else:
logger.error("Trying to add actions from an unknwown scheduler: %s",
scheduler_instance_id)
return
if not scheduler_link:
logger.error("Trying to add actions, but scheduler link is not found for: %s, "
"actions: %s", scheduler_instance_id, actions_list)
return
logger.debug("Found scheduler link: %s", scheduler_link)
for action in actions_list:
# First we look if the action is identified
uuid = getattr(action, 'uuid', None)
if uuid is None:
try:
action = unserialize(action, no_load=True)
uuid = action.uuid
except AlignakClassLookupException:
logger.error('Cannot un-serialize action: %s', action)
continue
# If we already have this action, we are already working for it!
if uuid in scheduler_link.actions:
continue
# Action is attached to a scheduler
action.my_scheduler = scheduler_link.uuid
scheduler_link.actions[action.uuid] = action
self.assign_to_a_queue(action) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:split_semicolon; 3, parameters; 3, 4; 3, 5; 4, identifier:line; 5, default_parameter; 5, 6; 5, 7; 6, identifier:maxsplit; 7, None; 8, block; 8, 9; 8, 11; 8, 12; 8, 21; 8, 28; 8, 29; 8, 42; 8, 43; 8, 44; 8, 48; 8, 138; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:split_line; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:line; 18, identifier:split; 19, argument_list; 19, 20; 20, string:';'; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:split_line_size; 24, call; 24, 25; 24, 26; 25, identifier:len; 26, argument_list; 26, 27; 27, identifier:split_line; 28, comment; 29, if_statement; 29, 30; 29, 37; 30, boolean_operator:or; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:maxsplit; 33, None; 34, comparison_operator:<; 34, 35; 34, 36; 35, identifier:maxsplit; 36, integer:0; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:maxsplit; 41, identifier:split_line_size; 42, comment; 43, comment; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:i; 47, integer:0; 48, while_statement; 48, 49; 48, 54; 48, 55; 49, comparison_operator:<; 49, 50; 49, 51; 50, identifier:i; 51, binary_operator:-; 51, 52; 51, 53; 52, identifier:split_line_size; 53, integer:1; 54, comment; 55, block; 55, 56; 55, 67; 55, 84; 55, 85; 55, 86; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:ends; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:split_line; 63, identifier:i; 64, identifier:endswith; 65, argument_list; 65, 66; 66, string:'\\'; 67, if_statement; 67, 68; 67, 69; 67, 70; 68, identifier:ends; 69, comment; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:split_line; 75, identifier:i; 76, subscript; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:split_line; 79, identifier:i; 80, slice; 80, 81; 80, 82; 81, colon; 82, unary_operator:-; 82, 83; 83, integer:1; 84, comment; 85, comment; 86, if_statement; 86, 87; 86, 99; 86, 130; 86, 131; 86, 132; 87, boolean_operator:and; 87, 88; 87, 94; 88, parenthesized_expression; 88, 89; 89, boolean_operator:or; 89, 90; 89, 91; 90, identifier:ends; 91, comparison_operator:>=; 91, 92; 91, 93; 92, identifier:i; 93, identifier:maxsplit; 94, comparison_operator:<; 94, 95; 94, 96; 95, identifier:i; 96, binary_operator:-; 96, 97; 96, 98; 97, identifier:split_line_size; 98, integer:1; 99, block; 99, 100; 99, 119; 99, 120; 99, 126; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:split_line; 104, identifier:i; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:";"; 108, identifier:join; 109, argument_list; 109, 110; 110, list:[split_line[i], split_line[i + 1]]; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:split_line; 113, identifier:i; 114, subscript; 114, 115; 114, 116; 115, identifier:split_line; 116, binary_operator:+; 116, 117; 116, 118; 117, identifier:i; 118, integer:1; 119, comment; 120, delete_statement; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:split_line; 123, binary_operator:+; 123, 124; 123, 125; 124, identifier:i; 125, integer:1; 126, expression_statement; 126, 127; 127, augmented_assignment:-=; 127, 128; 127, 129; 128, identifier:split_line_size; 129, integer:1; 130, comment; 131, comment; 132, else_clause; 132, 133; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, augmented_assignment:+=; 135, 136; 135, 137; 136, identifier:i; 137, integer:1; 138, return_statement; 138, 139; 139, identifier:split_line | def split_semicolon(line, maxsplit=None):
r"""Split a line on semicolons characters but not on the escaped semicolons
:param line: line to split
:type line: str
:param maxsplit: maximal number of split (if None, no limit)
:type maxsplit: None | int
:return: split line
:rtype: list
>>> split_semicolon('a,b;c;;g')
['a,b', 'c', '', 'g']
>>> split_semicolon('a,b;c;;g', 2)
['a,b', 'c', ';g']
>>> split_semicolon(r'a,b;c\;;g', 2)
['a,b', 'c;', 'g']
"""
# Split on ';' character
split_line = line.split(';')
split_line_size = len(split_line)
# if maxsplit is not specified, we set it to the number of part
if maxsplit is None or maxsplit < 0:
maxsplit = split_line_size
# Join parts to the next one, if ends with a '\'
# because we mustn't split if the semicolon is escaped
i = 0
while i < split_line_size - 1:
# for each part, check if its ends with a '\'
ends = split_line[i].endswith('\\')
if ends:
# remove the last character '\'
split_line[i] = split_line[i][:-1]
# append the next part to the current if it is not the last and the current
# ends with '\' or if there is more than maxsplit parts
if (ends or i >= maxsplit) and i < split_line_size - 1:
split_line[i] = ";".join([split_line[i], split_line[i + 1]])
# delete the next part
del split_line[i + 1]
split_line_size -= 1
# increase i only if we don't have append because after append the new
# string can end with '\'
else:
i += 1
return split_line |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:sort_by_number_values; 3, parameters; 3, 4; 3, 5; 4, identifier:x00; 5, identifier:y00; 6, comment; 7, block; 7, 8; 7, 10; 7, 23; 7, 37; 7, 38; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 20; 11, comparison_operator:<; 11, 12; 11, 16; 12, call; 12, 13; 12, 14; 13, identifier:len; 14, argument_list; 14, 15; 15, identifier:x00; 16, call; 16, 17; 16, 18; 17, identifier:len; 18, argument_list; 18, 19; 19, identifier:y00; 20, block; 20, 21; 21, return_statement; 21, 22; 22, integer:1; 23, if_statement; 23, 24; 23, 33; 24, comparison_operator:>; 24, 25; 24, 29; 25, call; 25, 26; 25, 27; 26, identifier:len; 27, argument_list; 27, 28; 28, identifier:x00; 29, call; 29, 30; 29, 31; 30, identifier:len; 31, argument_list; 31, 32; 32, identifier:y00; 33, block; 33, 34; 34, return_statement; 34, 35; 35, unary_operator:-; 35, 36; 36, integer:1; 37, comment; 38, return_statement; 38, 39; 39, integer:0 | def sort_by_number_values(x00, y00): # pragma: no cover, looks like not used!
"""Compare x00, y00 base on number of values
:param x00: first elem to compare
:type x00: list
:param y00: second elem to compare
:type y00: list
:return: x00 > y00 (-1) if len(x00) > len(y00), x00 == y00 (0) if id equals, x00 < y00 (1) else
:rtype: int
"""
if len(x00) < len(y00):
return 1
if len(x00) > len(y00):
return -1
# So is equal
return 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 10; 2, function_name:add_item; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:item; 6, default_parameter; 6, 7; 6, 8; 7, identifier:index; 8, True; 9, comment; 10, block; 10, 11; 10, 13; 10, 24; 10, 25; 10, 29; 10, 304; 10, 379; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:name_property; 16, call; 16, 17; 16, 18; 17, identifier:getattr; 18, argument_list; 18, 19; 18, 22; 18, 23; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:__class__; 22, string:"name_property"; 23, None; 24, comment; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:generated_hosts; 28, list:[]; 29, if_statement; 29, 30; 29, 31; 30, identifier:name_property; 31, block; 31, 32; 31, 41; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:name; 35, call; 35, 36; 35, 37; 36, identifier:getattr; 37, argument_list; 37, 38; 37, 39; 37, 40; 38, identifier:item; 39, identifier:name_property; 40, None; 41, if_statement; 41, 42; 41, 51; 41, 52; 42, boolean_operator:and; 42, 43; 42, 48; 43, boolean_operator:and; 43, 44; 43, 45; 44, identifier:name; 45, comparison_operator:in; 45, 46; 45, 47; 46, string:'['; 47, identifier:name; 48, comparison_operator:in; 48, 49; 48, 50; 49, string:']'; 50, identifier:name; 51, comment; 52, block; 52, 53; 52, 74; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:pattern; 56, subscript; 56, 57; 56, 58; 57, identifier:name; 58, slice; 58, 59; 58, 67; 58, 68; 59, binary_operator:+; 59, 60; 59, 66; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:name; 63, identifier:find; 64, argument_list; 64, 65; 65, string:"["; 66, integer:1; 67, colon; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:name; 71, identifier:find; 72, argument_list; 72, 73; 73, string:"]"; 74, if_statement; 74, 75; 74, 78; 75, comparison_operator:in; 75, 76; 75, 77; 76, string:'-'; 77, identifier:pattern; 78, block; 78, 79; 78, 87; 78, 88; 78, 89; 78, 98; 78, 102; 78, 106; 78, 110; 78, 163; 78, 178; 78, 193; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:logger; 83, identifier:debug; 84, argument_list; 84, 85; 84, 86; 85, string:"Found an host with a patterned name: %s"; 86, identifier:pattern; 87, comment; 88, comment; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:limits; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:pattern; 95, identifier:split; 96, argument_list; 96, 97; 97, string:'-'; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:fmt; 101, string:"%d"; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:min_v; 105, integer:1; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:max_v; 109, integer:1; 110, if_statement; 110, 111; 110, 117; 110, 143; 111, comparison_operator:==; 111, 112; 111, 116; 112, call; 112, 113; 112, 114; 113, identifier:len; 114, argument_list; 114, 115; 115, identifier:limits; 116, integer:3; 117, block; 117, 118; 117, 124; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:fmt; 121, subscript; 121, 122; 121, 123; 122, identifier:limits; 123, integer:2; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:new_name; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:name; 130, identifier:replace; 131, argument_list; 131, 132; 131, 142; 132, binary_operator:%; 132, 133; 132, 134; 133, string:'[%s-%s-%s]'; 134, tuple; 134, 135; 134, 138; 134, 141; 135, subscript; 135, 136; 135, 137; 136, identifier:limits; 137, integer:0; 138, subscript; 138, 139; 138, 140; 139, identifier:limits; 140, integer:1; 141, identifier:fmt; 142, string:'***'; 143, else_clause; 143, 144; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:new_name; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:name; 151, identifier:replace; 152, argument_list; 152, 153; 152, 162; 153, binary_operator:%; 153, 154; 153, 155; 154, string:'[%s-%s]'; 155, tuple; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:limits; 158, integer:0; 159, subscript; 159, 160; 159, 161; 160, identifier:limits; 161, integer:1; 162, string:'***'; 163, try_statement; 163, 164; 163, 174; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:min_v; 168, call; 168, 169; 168, 170; 169, identifier:int; 170, argument_list; 170, 171; 171, subscript; 171, 172; 171, 173; 172, identifier:limits; 173, integer:0; 174, except_clause; 174, 175; 174, 176; 175, identifier:ValueError; 176, block; 176, 177; 177, pass_statement; 178, try_statement; 178, 179; 178, 189; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:max_v; 183, call; 183, 184; 183, 185; 184, identifier:int; 185, argument_list; 185, 186; 186, subscript; 186, 187; 186, 188; 187, identifier:limits; 188, integer:1; 189, except_clause; 189, 190; 189, 191; 190, identifier:ValueError; 191, block; 191, 192; 192, pass_statement; 193, for_statement; 193, 194; 193, 195; 193, 202; 194, identifier:idx; 195, call; 195, 196; 195, 197; 196, identifier:range; 197, argument_list; 197, 198; 197, 199; 198, identifier:min_v; 199, binary_operator:+; 199, 200; 199, 201; 200, identifier:max_v; 201, integer:1; 202, block; 202, 203; 202, 219; 202, 226; 202, 234; 202, 248; 202, 249; 202, 297; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:logger; 207, identifier:debug; 208, argument_list; 208, 209; 208, 210; 209, string:"- cloning host: %s"; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:new_name; 213, identifier:replace; 214, argument_list; 214, 215; 214, 216; 215, string:'***'; 216, binary_operator:%; 216, 217; 216, 218; 217, identifier:fmt; 218, identifier:idx; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:new_host; 222, call; 222, 223; 222, 224; 223, identifier:deepcopy; 224, argument_list; 224, 225; 225, identifier:item; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:new_host; 230, identifier:uuid; 231, call; 231, 232; 231, 233; 232, identifier:get_a_new_object_id; 233, argument_list; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:new_host; 238, identifier:host_name; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:new_name; 242, identifier:replace; 243, argument_list; 243, 244; 243, 245; 244, string:'***'; 245, binary_operator:%; 245, 246; 245, 247; 246, identifier:fmt; 247, identifier:idx; 248, comment; 249, for_statement; 249, 250; 249, 251; 249, 257; 250, identifier:prop; 251, list:['display_name', 'alias', 'notes', 'notes_url', 'action_url']; 251, 252; 251, 253; 251, 254; 251, 255; 251, 256; 252, string:'display_name'; 253, string:'alias'; 254, string:'notes'; 255, string:'notes_url'; 256, string:'action_url'; 257, block; 257, 258; 257, 269; 257, 277; 258, if_statement; 258, 259; 258, 267; 259, comparison_operator:is; 259, 260; 259, 266; 260, call; 260, 261; 260, 262; 261, identifier:getattr; 262, argument_list; 262, 263; 262, 264; 262, 265; 263, identifier:new_host; 264, identifier:prop; 265, None; 266, None; 267, block; 267, 268; 268, continue_statement; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:value; 272, call; 272, 273; 272, 274; 273, identifier:getattr; 274, argument_list; 274, 275; 274, 276; 275, identifier:new_host; 276, identifier:prop; 277, if_statement; 277, 278; 277, 281; 278, comparison_operator:in; 278, 279; 278, 280; 279, string:'$HOSTNAME$'; 280, identifier:value; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:setattr; 285, argument_list; 285, 286; 285, 287; 285, 288; 286, identifier:new_host; 287, identifier:prop; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:value; 291, identifier:replace; 292, argument_list; 292, 293; 292, 294; 293, string:'$HOSTNAME$'; 294, attribute; 294, 295; 294, 296; 295, identifier:new_host; 296, identifier:host_name; 297, expression_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:generated_hosts; 301, identifier:append; 302, argument_list; 302, 303; 303, identifier:new_host; 304, if_statement; 304, 305; 304, 306; 304, 351; 305, identifier:generated_hosts; 306, block; 306, 307; 306, 335; 307, for_statement; 307, 308; 307, 309; 307, 310; 308, identifier:new_host; 309, identifier:generated_hosts; 310, block; 310, 311; 310, 325; 311, if_statement; 311, 312; 311, 315; 312, comparison_operator:is; 312, 313; 312, 314; 313, identifier:index; 314, True; 315, block; 315, 316; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:new_host; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:index_item; 323, argument_list; 323, 324; 324, identifier:new_host; 325, expression_statement; 325, 326; 326, assignment; 326, 327; 326, 334; 327, subscript; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:self; 330, identifier:items; 331, attribute; 331, 332; 331, 333; 332, identifier:new_host; 333, identifier:uuid; 334, identifier:new_host; 335, expression_statement; 335, 336; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:logger; 339, identifier:info; 340, argument_list; 340, 341; 340, 342; 340, 346; 341, string:" cloned %d hosts from %s"; 342, call; 342, 343; 342, 344; 343, identifier:len; 344, argument_list; 344, 345; 345, identifier:generated_hosts; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:item; 349, identifier:get_name; 350, argument_list; 351, else_clause; 351, 352; 352, block; 352, 353; 352, 369; 353, if_statement; 353, 354; 353, 359; 354, boolean_operator:and; 354, 355; 354, 358; 355, comparison_operator:is; 355, 356; 355, 357; 356, identifier:index; 357, True; 358, identifier:name_property; 359, block; 359, 360; 360, expression_statement; 360, 361; 361, assignment; 361, 362; 361, 363; 362, identifier:item; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:index_item; 367, argument_list; 367, 368; 368, identifier:item; 369, expression_statement; 369, 370; 370, assignment; 370, 371; 370, 378; 371, subscript; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:self; 374, identifier:items; 375, attribute; 375, 376; 375, 377; 376, identifier:item; 377, identifier:uuid; 378, identifier:item; 379, return_statement; 379, 380; 380, identifier:generated_hosts | def add_item(self, item, index=True):
# pylint: disable=too-many-branches, too-many-locals, too-many-nested-blocks
"""
Add an item into our containers, and index it depending on the `index` flag.
:param item: object to add
:type item: alignak.objects.item.Item
:param index: Flag indicating if the item should be indexed
:type index: bool
:return: the new items created
:rtype list
"""
name_property = getattr(self.__class__, "name_property", None)
# Check if some hosts are to be self-generated...
generated_hosts = []
if name_property:
name = getattr(item, name_property, None)
if name and '[' in name and ']' in name:
# We can create several objects from the same configuration!
pattern = name[name.find("[")+1:name.find("]")]
if '-' in pattern:
logger.debug("Found an host with a patterned name: %s", pattern)
# pattern is format-min-max
# format is optional
limits = pattern.split('-')
fmt = "%d"
min_v = 1
max_v = 1
if len(limits) == 3:
fmt = limits[2]
new_name = name.replace('[%s-%s-%s]' % (limits[0], limits[1], fmt), '***')
else:
new_name = name.replace('[%s-%s]' % (limits[0], limits[1]), '***')
try:
min_v = int(limits[0])
except ValueError:
pass
try:
max_v = int(limits[1])
except ValueError:
pass
for idx in range(min_v, max_v + 1):
logger.debug("- cloning host: %s", new_name.replace('***', fmt % idx))
new_host = deepcopy(item)
new_host.uuid = get_a_new_object_id()
new_host.host_name = new_name.replace('***', fmt % idx)
# Update some fields with the newly generated host name
for prop in ['display_name', 'alias', 'notes', 'notes_url', 'action_url']:
if getattr(new_host, prop, None) is None:
continue
value = getattr(new_host, prop)
if '$HOSTNAME$' in value:
setattr(new_host, prop, value.replace('$HOSTNAME$',
new_host.host_name))
generated_hosts.append(new_host)
if generated_hosts:
for new_host in generated_hosts:
if index is True:
new_host = self.index_item(new_host)
self.items[new_host.uuid] = new_host
logger.info(" cloned %d hosts from %s", len(generated_hosts), item.get_name())
else:
if index is True and name_property:
item = self.index_item(item)
self.items[item.uuid] = item
return generated_hosts |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:explode_contact_groups_into_contacts; 3, parameters; 3, 4; 3, 5; 4, identifier:item; 5, identifier:contactgroups; 6, block; 6, 7; 6, 9; 6, 18; 6, 19; 6, 23; 6, 56; 6, 63; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 16; 10, not_operator; 10, 11; 11, call; 11, 12; 11, 13; 12, identifier:hasattr; 13, argument_list; 13, 14; 13, 15; 14, identifier:item; 15, string:'contact_groups'; 16, block; 16, 17; 17, return_statement; 18, comment; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:cgnames; 22, string:''; 23, if_statement; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:item; 26, identifier:contact_groups; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 36; 28, 43; 29, call; 29, 30; 29, 31; 30, identifier:isinstance; 31, argument_list; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:item; 34, identifier:contact_groups; 35, identifier:list; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:cgnames; 40, attribute; 40, 41; 40, 42; 41, identifier:item; 42, identifier:contact_groups; 43, else_clause; 43, 44; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:cgnames; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:item; 52, identifier:contact_groups; 53, identifier:split; 54, argument_list; 54, 55; 55, string:','; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:cgnames; 59, call; 59, 60; 59, 61; 60, identifier:strip_and_uniq; 61, argument_list; 61, 62; 62, identifier:cgnames; 63, for_statement; 63, 64; 63, 65; 63, 66; 64, identifier:cgname; 65, identifier:cgnames; 66, block; 66, 67; 66, 76; 66, 101; 66, 110; 66, 111; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:contactgroup; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:contactgroups; 73, identifier:find_by_name; 74, argument_list; 74, 75; 75, identifier:cgname; 76, if_statement; 76, 77; 76, 79; 77, not_operator; 77, 78; 78, identifier:contactgroup; 79, block; 79, 80; 79, 100; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:item; 84, identifier:add_error; 85, argument_list; 85, 86; 86, binary_operator:%; 86, 87; 86, 88; 87, string:"The contact group '%s' defined on the %s '%s' do not exist"; 88, tuple; 88, 89; 88, 90; 88, 95; 89, identifier:cgname; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:item; 93, identifier:__class__; 94, identifier:my_type; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:item; 98, identifier:get_name; 99, argument_list; 100, continue_statement; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:cnames; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:contactgroups; 107, identifier:get_members_of_group; 108, argument_list; 108, 109; 109, identifier:cgname; 110, comment; 111, if_statement; 111, 112; 111, 113; 112, identifier:cnames; 113, block; 113, 114; 114, if_statement; 114, 115; 114, 120; 114, 121; 114, 122; 114, 133; 115, call; 115, 116; 115, 117; 116, identifier:hasattr; 117, argument_list; 117, 118; 117, 119; 118, identifier:item; 119, string:'contacts'; 120, comment; 121, comment; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:item; 127, identifier:contacts; 128, binary_operator:+; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:item; 131, identifier:contacts; 132, identifier:cnames; 133, else_clause; 133, 134; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:item; 139, identifier:contacts; 140, identifier:cnames | def explode_contact_groups_into_contacts(item, contactgroups):
"""
Get all contacts of contact_groups and put them in contacts container
:param item: item where have contact_groups property
:type item: object
:param contactgroups: all contactgroups object
:type contactgroups: alignak.objects.contactgroup.Contactgroups
:return: None
"""
if not hasattr(item, 'contact_groups'):
return
# TODO : See if we can remove this if
cgnames = ''
if item.contact_groups:
if isinstance(item.contact_groups, list):
cgnames = item.contact_groups
else:
cgnames = item.contact_groups.split(',')
cgnames = strip_and_uniq(cgnames)
for cgname in cgnames:
contactgroup = contactgroups.find_by_name(cgname)
if not contactgroup:
item.add_error("The contact group '%s' defined on the %s '%s' do not exist"
% (cgname, item.__class__.my_type, item.get_name()))
continue
cnames = contactgroups.get_members_of_group(cgname)
# We add contacts into our contacts
if cnames:
if hasattr(item, 'contacts'):
# Fix #1054 - bad contact explosion
# item.contacts.extend(cnames)
item.contacts = item.contacts + cnames
else:
item.contacts = cnames |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:dfs_loop_search; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:root; 6, block; 6, 7; 6, 9; 6, 10; 6, 20; 6, 21; 6, 132; 6, 133; 6, 134; 6, 135; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 19; 12, subscript; 12, 13; 12, 18; 13, subscript; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:nodes; 17, identifier:root; 18, string:'dfs_loop_status'; 19, string:'DFS_TEMPORARY_CHECKED'; 20, comment; 21, for_statement; 21, 22; 21, 23; 21, 30; 22, identifier:child; 23, subscript; 23, 24; 23, 29; 24, subscript; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:nodes; 28, identifier:root; 29, string:"sons"; 30, block; 30, 31; 30, 41; 30, 42; 30, 64; 30, 65; 30, 66; 30, 91; 30, 92; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:child_status; 34, subscript; 34, 35; 34, 40; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:nodes; 39, identifier:child; 40, string:'dfs_loop_status'; 41, comment; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:==; 43, 44; 43, 45; 44, identifier:child_status; 45, string:'DFS_UNCHECKED'; 46, block; 46, 47; 46, 54; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:dfs_loop_search; 52, argument_list; 52, 53; 53, identifier:child; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:child_status; 57, subscript; 57, 58; 57, 63; 58, subscript; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:nodes; 62, identifier:child; 63, string:'dfs_loop_status'; 64, comment; 65, comment; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:==; 67, 68; 67, 69; 68, identifier:child_status; 69, string:'DFS_TEMPORARY_CHECKED'; 70, block; 70, 71; 70, 81; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 80; 73, subscript; 73, 74; 73, 79; 74, subscript; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:nodes; 78, identifier:child; 79, string:'dfs_loop_status'; 80, string:'DFS_LOOP_INSIDE'; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 90; 83, subscript; 83, 84; 83, 89; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:nodes; 88, identifier:root; 89, string:'dfs_loop_status'; 90, string:'DFS_LOOP_INSIDE'; 91, comment; 92, if_statement; 92, 93; 92, 98; 92, 99; 93, comparison_operator:in; 93, 94; 93, 95; 94, identifier:child_status; 95, tuple; 95, 96; 95, 97; 96, string:'DFS_NEAR_LOOP'; 97, string:'DFS_LOOP_INSIDE'; 98, comment; 99, block; 99, 100; 99, 121; 99, 122; 100, if_statement; 100, 101; 100, 110; 101, comparison_operator:!=; 101, 102; 101, 109; 102, subscript; 102, 103; 102, 108; 103, subscript; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:nodes; 107, identifier:root; 108, string:'dfs_loop_status'; 109, string:'DFS_LOOP_INSIDE'; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 120; 113, subscript; 113, 114; 113, 119; 114, subscript; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:nodes; 118, identifier:root; 119, string:'dfs_loop_status'; 120, string:'DFS_NEAR_LOOP'; 121, comment; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 131; 124, subscript; 124, 125; 124, 130; 125, subscript; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:nodes; 129, identifier:child; 130, string:'dfs_loop_status'; 131, string:'DFS_LOOP_INSIDE'; 132, comment; 133, comment; 134, comment; 135, if_statement; 135, 136; 135, 145; 136, comparison_operator:==; 136, 137; 136, 144; 137, subscript; 137, 138; 137, 143; 138, subscript; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:nodes; 142, identifier:root; 143, string:'dfs_loop_status'; 144, string:'DFS_TEMPORARY_CHECKED'; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 155; 148, subscript; 148, 149; 148, 154; 149, subscript; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:nodes; 153, identifier:root; 154, string:'dfs_loop_status'; 155, string:'DFS_OK' | def dfs_loop_search(self, root):
"""Main algorithm to look for loop.
It tags nodes and find ones stuck in loop.
* Init all nodes with DFS_UNCHECKED value
* DFS_TEMPORARY_CHECKED means we found it once
* DFS_OK : this node (and all sons) are fine
* DFS_NEAR_LOOP : One problem was found in of of the son
* DFS_LOOP_INSIDE : This node is part of a loop
:param root: Root of the dependency tree
:type root:
:return: None
"""
# Make the root temporary checked
self.nodes[root]['dfs_loop_status'] = 'DFS_TEMPORARY_CHECKED'
# We are scanning the sons
for child in self.nodes[root]["sons"]:
child_status = self.nodes[child]['dfs_loop_status']
# If a child is not checked, check it
if child_status == 'DFS_UNCHECKED':
self.dfs_loop_search(child)
child_status = self.nodes[child]['dfs_loop_status']
# If a child has already been temporary checked, it's a problem,
# loop inside, and its a checked status
if child_status == 'DFS_TEMPORARY_CHECKED':
self.nodes[child]['dfs_loop_status'] = 'DFS_LOOP_INSIDE'
self.nodes[root]['dfs_loop_status'] = 'DFS_LOOP_INSIDE'
# If a child has already been temporary checked, it's a problem, loop inside
if child_status in ('DFS_NEAR_LOOP', 'DFS_LOOP_INSIDE'):
# if a node is known to be part of a loop, do not let it be less
if self.nodes[root]['dfs_loop_status'] != 'DFS_LOOP_INSIDE':
self.nodes[root]['dfs_loop_status'] = 'DFS_NEAR_LOOP'
# We've already seen this child, it's a problem
self.nodes[child]['dfs_loop_status'] = 'DFS_LOOP_INSIDE'
# If root have been modified, do not set it OK
# A node is OK if and only if all of its children are OK
# if it does not have a child, goes ok
if self.nodes[root]['dfs_loop_status'] == 'DFS_TEMPORARY_CHECKED':
self.nodes[root]['dfs_loop_status'] = 'DFS_OK' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 1, 14; 2, function_name:eval_complex_cor_pattern; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 4, identifier:self; 5, identifier:pattern; 6, identifier:hosts; 7, identifier:services; 8, identifier:hostgroups; 9, identifier:servicegroups; 10, default_parameter; 10, 11; 10, 12; 11, identifier:running; 12, False; 13, comment; 14, block; 14, 15; 14, 17; 14, 23; 14, 33; 14, 37; 14, 41; 14, 45; 14, 46; 14, 50; 14, 346; 14, 347; 14, 355; 14, 397; 14, 398; 14, 399; 14, 405; 15, expression_statement; 15, 16; 16, comment; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:node; 20, call; 20, 21; 20, 22; 21, identifier:DependencyNode; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:pattern; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:eval_xof_pattern; 30, argument_list; 30, 31; 30, 32; 31, identifier:node; 32, identifier:pattern; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:in_par; 36, False; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:tmp; 40, string:''; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:son_is_not; 44, False; 45, comment; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:stacked_parenthesis; 49, integer:0; 50, for_statement; 50, 51; 50, 52; 50, 53; 51, identifier:char; 52, identifier:pattern; 53, block; 53, 54; 54, if_statement; 54, 55; 54, 58; 54, 105; 54, 193; 54, 194; 54, 195; 54, 202; 54, 203; 54, 204; 54, 205; 54, 241; 54, 339; 54, 340; 55, comparison_operator:==; 55, 56; 55, 57; 56, identifier:char; 57, string:'('; 58, block; 58, 59; 58, 63; 58, 67; 58, 75; 58, 76; 58, 77; 58, 94; 58, 95; 58, 96; 59, expression_statement; 59, 60; 60, augmented_assignment:+=; 60, 61; 60, 62; 61, identifier:stacked_parenthesis; 62, integer:1; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:in_par; 66, True; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:tmp; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:tmp; 73, identifier:strip; 74, argument_list; 75, comment; 76, comment; 77, if_statement; 77, 78; 77, 85; 77, 86; 78, boolean_operator:and; 78, 79; 78, 82; 79, comparison_operator:==; 79, 80; 79, 81; 80, identifier:stacked_parenthesis; 81, integer:1; 82, comparison_operator:!=; 82, 83; 82, 84; 83, identifier:tmp; 84, string:''; 85, comment; 86, block; 86, 87; 86, 93; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:print; 90, argument_list; 90, 91; 90, 92; 91, string:"ERROR : bad expression near"; 92, identifier:tmp; 93, continue_statement; 94, comment; 95, comment; 96, if_statement; 96, 97; 96, 100; 97, comparison_operator:>; 97, 98; 97, 99; 98, identifier:stacked_parenthesis; 99, integer:1; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, augmented_assignment:+=; 102, 103; 102, 104; 103, identifier:tmp; 104, identifier:char; 105, elif_clause; 105, 106; 105, 109; 106, comparison_operator:==; 106, 107; 106, 108; 107, identifier:char; 108, string:')'; 109, block; 109, 110; 109, 114; 109, 128; 109, 188; 109, 189; 110, expression_statement; 110, 111; 111, augmented_assignment:-=; 111, 112; 111, 113; 112, identifier:stacked_parenthesis; 113, integer:1; 114, if_statement; 114, 115; 114, 118; 114, 119; 115, comparison_operator:<; 115, 116; 115, 117; 116, identifier:stacked_parenthesis; 117, integer:0; 118, comment; 119, block; 119, 120; 119, 127; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:print; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, string:"Error : bad expression near"; 125, identifier:tmp; 126, string:"too much ')'"; 127, continue_statement; 128, if_statement; 128, 129; 128, 132; 129, comparison_operator:==; 129, 130; 129, 131; 130, identifier:stacked_parenthesis; 131, integer:0; 132, block; 132, 133; 132, 141; 132, 155; 132, 156; 132, 169; 132, 178; 132, 182; 132, 183; 132, 187; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:tmp; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:tmp; 139, identifier:strip; 140, argument_list; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:son; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:eval_cor_pattern; 148, argument_list; 148, 149; 148, 150; 148, 151; 148, 152; 148, 153; 148, 154; 149, identifier:tmp; 150, identifier:hosts; 151, identifier:services; 152, identifier:hostgroups; 153, identifier:servicegroups; 154, identifier:running; 155, comment; 156, if_statement; 156, 157; 156, 158; 157, identifier:son_is_not; 158, block; 158, 159; 158, 165; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:son; 163, identifier:not_value; 164, True; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:son_is_not; 168, False; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:node; 174, identifier:sons; 175, identifier:append; 176, argument_list; 176, 177; 177, identifier:son; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:in_par; 181, False; 182, comment; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:tmp; 186, string:''; 187, continue_statement; 188, comment; 189, expression_statement; 189, 190; 190, augmented_assignment:+=; 190, 191; 190, 192; 191, identifier:tmp; 192, identifier:char; 193, comment; 194, comment; 195, elif_clause; 195, 196; 195, 197; 196, identifier:in_par; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, augmented_assignment:+=; 199, 200; 199, 201; 200, identifier:tmp; 201, identifier:char; 202, comment; 203, comment; 204, comment; 205, elif_clause; 205, 206; 205, 209; 206, comparison_operator:==; 206, 207; 206, 208; 207, identifier:char; 208, string:'!'; 209, block; 209, 210; 209, 218; 209, 235; 209, 236; 209, 240; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:tmp; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:tmp; 216, identifier:strip; 217, argument_list; 218, if_statement; 218, 219; 218, 226; 219, boolean_operator:and; 219, 220; 219, 221; 220, identifier:tmp; 221, comparison_operator:!=; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:tmp; 224, integer:0; 225, string:'!'; 226, block; 226, 227; 226, 234; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 230; 229, identifier:print; 230, argument_list; 230, 231; 230, 232; 230, 233; 231, string:"Error : bad expression near"; 232, identifier:tmp; 233, string:"wrong position for '!'"; 234, continue_statement; 235, comment; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:son_is_not; 239, True; 240, comment; 241, elif_clause; 241, 242; 241, 247; 241, 248; 242, comparison_operator:in; 242, 243; 242, 244; 243, identifier:char; 244, list:['&', '|']; 244, 245; 244, 246; 245, string:'&'; 246, string:'|'; 247, comment; 248, block; 248, 249; 248, 257; 248, 258; 248, 280; 248, 293; 248, 335; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:tmp; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:tmp; 255, identifier:strip; 256, argument_list; 257, comment; 258, if_statement; 258, 259; 258, 276; 258, 277; 259, boolean_operator:and; 259, 260; 259, 271; 260, boolean_operator:and; 260, 261; 260, 266; 261, comparison_operator:is; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:node; 264, identifier:operand; 265, None; 266, comparison_operator:!=; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:node; 269, identifier:operand; 270, string:'of:'; 271, comparison_operator:!=; 271, 272; 271, 273; 272, identifier:char; 273, attribute; 273, 274; 273, 275; 274, identifier:node; 275, identifier:operand; 276, comment; 277, block; 277, 278; 278, return_statement; 278, 279; 279, None; 280, if_statement; 280, 281; 280, 286; 281, comparison_operator:!=; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:node; 284, identifier:operand; 285, string:'of:'; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:node; 291, identifier:operand; 292, identifier:char; 293, if_statement; 293, 294; 293, 297; 294, comparison_operator:!=; 294, 295; 294, 296; 295, identifier:tmp; 296, string:''; 297, block; 297, 298; 297, 312; 297, 313; 297, 326; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:son; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:self; 304, identifier:eval_cor_pattern; 305, argument_list; 305, 306; 305, 307; 305, 308; 305, 309; 305, 310; 305, 311; 306, identifier:tmp; 307, identifier:hosts; 308, identifier:services; 309, identifier:hostgroups; 310, identifier:servicegroups; 311, identifier:running; 312, comment; 313, if_statement; 313, 314; 313, 315; 314, identifier:son_is_not; 315, block; 315, 316; 315, 322; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:son; 320, identifier:not_value; 321, True; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:son_is_not; 325, False; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 333; 328, attribute; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:node; 331, identifier:sons; 332, identifier:append; 333, argument_list; 333, 334; 334, identifier:son; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:tmp; 338, string:''; 339, comment; 340, else_clause; 340, 341; 341, block; 341, 342; 342, expression_statement; 342, 343; 343, augmented_assignment:+=; 343, 344; 343, 345; 344, identifier:tmp; 345, identifier:char; 346, comment; 347, expression_statement; 347, 348; 348, assignment; 348, 349; 348, 350; 349, identifier:tmp; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:tmp; 353, identifier:strip; 354, argument_list; 355, if_statement; 355, 356; 355, 359; 356, comparison_operator:!=; 356, 357; 356, 358; 357, identifier:tmp; 358, string:''; 359, block; 359, 360; 359, 374; 359, 375; 359, 388; 360, expression_statement; 360, 361; 361, assignment; 361, 362; 361, 363; 362, identifier:son; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:eval_cor_pattern; 367, argument_list; 367, 368; 367, 369; 367, 370; 367, 371; 367, 372; 367, 373; 368, identifier:tmp; 369, identifier:hosts; 370, identifier:services; 371, identifier:hostgroups; 372, identifier:servicegroups; 373, identifier:running; 374, comment; 375, if_statement; 375, 376; 375, 377; 376, identifier:son_is_not; 377, block; 377, 378; 377, 384; 378, expression_statement; 378, 379; 379, assignment; 379, 380; 379, 383; 380, attribute; 380, 381; 380, 382; 381, identifier:son; 382, identifier:not_value; 383, True; 384, expression_statement; 384, 385; 385, assignment; 385, 386; 385, 387; 386, identifier:son_is_not; 387, False; 388, expression_statement; 388, 389; 389, call; 389, 390; 389, 395; 390, attribute; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:node; 393, identifier:sons; 394, identifier:append; 395, argument_list; 395, 396; 396, identifier:son; 397, comment; 398, comment; 399, expression_statement; 399, 400; 400, call; 400, 401; 400, 404; 401, attribute; 401, 402; 401, 403; 402, identifier:node; 403, identifier:switch_zeros_of_values; 404, argument_list; 405, return_statement; 405, 406; 406, identifier:node | def eval_complex_cor_pattern(self, pattern, hosts, services,
hostgroups, servicegroups, running=False):
# pylint: disable=too-many-branches
"""Parse and build recursively a tree of DependencyNode from a complex pattern
:param pattern: pattern to parse
:type pattern: str
:param hosts: hosts list, used to find a specific host
:type hosts: alignak.objects.host.Host
:param services: services list, used to find a specific service
:type services: alignak.objects.service.Service
:param running: rules are evaluated at run time and parsing. True means runtime
:type running: bool
:return: root node of parsed tree
:rtype: alignak.dependencynode.DependencyNode
"""
node = DependencyNode()
pattern = self.eval_xof_pattern(node, pattern)
in_par = False
tmp = ''
son_is_not = False # We keep is the next son will be not or not
stacked_parenthesis = 0
for char in pattern:
if char == '(':
stacked_parenthesis += 1
in_par = True
tmp = tmp.strip()
# Maybe we just start a par, but we got some things in tmp
# that should not be good in fact !
if stacked_parenthesis == 1 and tmp != '':
# TODO : real error
print("ERROR : bad expression near", tmp)
continue
# If we are already in a par, add this (
# but not if it's the first one so
if stacked_parenthesis > 1:
tmp += char
elif char == ')':
stacked_parenthesis -= 1
if stacked_parenthesis < 0:
# TODO : real error
print("Error : bad expression near", tmp, "too much ')'")
continue
if stacked_parenthesis == 0:
tmp = tmp.strip()
son = self.eval_cor_pattern(tmp, hosts, services,
hostgroups, servicegroups, running)
# Maybe our son was notted
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
in_par = False
# OK now clean the tmp so we start clean
tmp = ''
continue
# ok here we are still in a huge par, we just close one sub one
tmp += char
# Expressions in par will be parsed in a sub node after. So just
# stack pattern
elif in_par:
tmp += char
# Until here, we're not in par
# Manage the NOT for an expression. Only allow ! at the beginning
# of a host or a host,service expression.
elif char == '!':
tmp = tmp.strip()
if tmp and tmp[0] != '!':
print("Error : bad expression near", tmp, "wrong position for '!'")
continue
# Flags next node not state
son_is_not = True
# DO NOT keep the c in tmp, we consumed it
elif char in ['&', '|']:
# Oh we got a real cut in an expression, if so, cut it
tmp = tmp.strip()
# Look at the rule viability
if node.operand is not None and node.operand != 'of:' and char != node.operand:
# Should be logged as a warning / info? :)
return None
if node.operand != 'of:':
node.operand = char
if tmp != '':
son = self.eval_cor_pattern(tmp, hosts, services,
hostgroups, servicegroups, running)
# Maybe our son was notted
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
tmp = ''
# Maybe it's a classic character or we're in par, if so, continue
else:
tmp += char
# Be sure to manage the trainling part when the line is done
tmp = tmp.strip()
if tmp != '':
son = self.eval_cor_pattern(tmp, hosts, services,
hostgroups, servicegroups, running)
# Maybe our son was notted
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
# We got our nodes, so we can update 0 values of of_values
# with the number of sons
node.switch_zeros_of_values()
return node |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:get_next_valid_time_from_t; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:timestamp; 6, comment; 7, block; 7, 8; 7, 10; 7, 17; 7, 21; 7, 30; 7, 37; 7, 41; 7, 42; 7, 234; 7, 235; 7, 243; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:timestamp; 13, call; 13, 14; 13, 15; 14, identifier:int; 15, argument_list; 15, 16; 16, identifier:timestamp; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:original_t; 20, identifier:timestamp; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:res_from_cache; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:find_next_valid_time_from_cache; 28, argument_list; 28, 29; 29, identifier:timestamp; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:res_from_cache; 33, None; 34, block; 34, 35; 35, return_statement; 35, 36; 36, identifier:res_from_cache; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:still_loop; 40, True; 41, comment; 42, while_statement; 42, 43; 42, 44; 43, identifier:still_loop; 44, block; 44, 45; 44, 49; 44, 50; 44, 54; 44, 72; 44, 87; 44, 136; 44, 197; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:local_min; 48, None; 49, comment; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:dr_mins; 53, list:[]; 54, for_statement; 54, 55; 54, 56; 54, 59; 55, identifier:daterange; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:dateranges; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:dr_mins; 64, identifier:append; 65, argument_list; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:daterange; 69, identifier:get_next_valid_time_from_t; 70, argument_list; 70, 71; 71, identifier:timestamp; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:s_dr_mins; 75, call; 75, 76; 75, 77; 76, identifier:sorted; 77, argument_list; 77, 78; 78, list_comprehension; 78, 79; 78, 80; 78, 83; 79, identifier:d; 80, for_in_clause; 80, 81; 80, 82; 81, identifier:d; 82, identifier:dr_mins; 83, if_clause; 83, 84; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:d; 86, None; 87, for_statement; 87, 88; 87, 89; 87, 90; 88, identifier:t01; 89, identifier:s_dr_mins; 90, block; 90, 91; 91, if_statement; 91, 92; 91, 98; 91, 99; 91, 108; 92, boolean_operator:and; 92, 93; 92, 97; 93, not_operator; 93, 94; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:exclude; 97, identifier:still_loop; 98, comment; 99, block; 99, 100; 99, 104; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:local_min; 103, identifier:t01; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:still_loop; 107, False; 108, else_clause; 108, 109; 109, block; 109, 110; 110, for_statement; 110, 111; 110, 112; 110, 115; 111, identifier:timeperiod; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:exclude; 115, block; 115, 116; 116, if_statement; 116, 117; 116, 126; 116, 127; 117, boolean_operator:and; 117, 118; 117, 125; 118, not_operator; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:timeperiod; 122, identifier:is_time_valid; 123, argument_list; 123, 124; 124, identifier:t01; 125, identifier:still_loop; 126, comment; 127, block; 127, 128; 127, 132; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:local_min; 131, identifier:t01; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:still_loop; 135, False; 136, if_statement; 136, 137; 136, 140; 136, 141; 137, comparison_operator:is; 137, 138; 137, 139; 138, identifier:local_min; 139, None; 140, comment; 141, block; 141, 142; 141, 146; 141, 171; 141, 186; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:exc_mins; 145, list:[]; 146, if_statement; 146, 147; 146, 150; 147, comparison_operator:!=; 147, 148; 147, 149; 148, identifier:s_dr_mins; 149, list:[]; 150, block; 150, 151; 151, for_statement; 151, 152; 151, 153; 151, 156; 152, identifier:timeperiod; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:exclude; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:exc_mins; 161, identifier:append; 162, argument_list; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:timeperiod; 166, identifier:get_next_invalid_time_from_t; 167, argument_list; 167, 168; 168, subscript; 168, 169; 168, 170; 169, identifier:s_dr_mins; 170, integer:0; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:s_exc_mins; 174, call; 174, 175; 174, 176; 175, identifier:sorted; 176, argument_list; 176, 177; 177, list_comprehension; 177, 178; 177, 179; 177, 182; 178, identifier:d; 179, for_in_clause; 179, 180; 179, 181; 180, identifier:d; 181, identifier:exc_mins; 182, if_clause; 182, 183; 183, comparison_operator:is; 183, 184; 183, 185; 184, identifier:d; 185, None; 186, if_statement; 186, 187; 186, 190; 187, comparison_operator:!=; 187, 188; 187, 189; 188, identifier:s_exc_mins; 189, list:[]; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:local_min; 194, subscript; 194, 195; 194, 196; 195, identifier:s_exc_mins; 196, integer:0; 197, if_statement; 197, 198; 197, 201; 197, 206; 198, comparison_operator:is; 198, 199; 198, 200; 199, identifier:local_min; 200, None; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:still_loop; 205, False; 206, else_clause; 206, 207; 207, block; 207, 208; 207, 212; 207, 213; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:timestamp; 211, identifier:local_min; 212, comment; 213, if_statement; 213, 214; 213, 225; 214, comparison_operator:>; 214, 215; 214, 216; 215, identifier:timestamp; 216, binary_operator:+; 216, 217; 216, 224; 217, binary_operator:+; 217, 218; 217, 219; 218, identifier:original_t; 219, binary_operator:*; 219, 220; 219, 223; 220, binary_operator:*; 220, 221; 220, 222; 221, integer:3600; 222, integer:24; 223, integer:366; 224, integer:1; 225, block; 225, 226; 225, 230; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:still_loop; 229, False; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:local_min; 233, None; 234, comment; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 242; 237, subscript; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:cache; 241, identifier:original_t; 242, identifier:local_min; 243, return_statement; 243, 244; 244, identifier:local_min | def get_next_valid_time_from_t(self, timestamp):
# pylint: disable=too-many-branches
"""
Get next valid time. If it's in cache, get it, otherwise define it.
The limit to find it is 1 year.
:param timestamp: number of seconds
:type timestamp: int or float
:return: Nothing or time in seconds
:rtype: None or int
"""
timestamp = int(timestamp)
original_t = timestamp
res_from_cache = self.find_next_valid_time_from_cache(timestamp)
if res_from_cache is not None:
return res_from_cache
still_loop = True
# Loop for all minutes...
while still_loop:
local_min = None
# Ok, not in cache...
dr_mins = []
for daterange in self.dateranges:
dr_mins.append(daterange.get_next_valid_time_from_t(timestamp))
s_dr_mins = sorted([d for d in dr_mins if d is not None])
for t01 in s_dr_mins:
if not self.exclude and still_loop:
# No Exclude so we are good
local_min = t01
still_loop = False
else:
for timeperiod in self.exclude:
if not timeperiod.is_time_valid(t01) and still_loop:
# OK we found a date that is not valid in any exclude timeperiod
local_min = t01
still_loop = False
if local_min is None:
# Looking for next invalid date
exc_mins = []
if s_dr_mins != []:
for timeperiod in self.exclude:
exc_mins.append(timeperiod.get_next_invalid_time_from_t(s_dr_mins[0]))
s_exc_mins = sorted([d for d in exc_mins if d is not None])
if s_exc_mins != []:
local_min = s_exc_mins[0]
if local_min is None:
still_loop = False
else:
timestamp = local_min
# No loop more than one year
if timestamp > original_t + 3600 * 24 * 366 + 1:
still_loop = False
local_min = None
# Ok, we update the cache...
self.cache[original_t] = local_min
return local_min |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:get_next_invalid_time_from_t; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:timestamp; 6, comment; 7, block; 7, 8; 7, 10; 7, 17; 7, 21; 7, 25; 7, 100; 7, 107; 7, 108; 7, 112; 7, 193; 7, 210; 7, 265; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:timestamp; 13, call; 13, 14; 13, 15; 14, identifier:int; 15, argument_list; 15, 16; 16, identifier:timestamp; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:original_t; 20, identifier:timestamp; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:dr_mins; 24, list:[]; 25, for_statement; 25, 26; 25, 27; 25, 30; 26, identifier:daterange; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:dateranges; 30, block; 30, 31; 30, 35; 30, 39; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:timestamp; 34, identifier:original_t; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:cont; 38, True; 39, while_statement; 39, 40; 39, 41; 40, identifier:cont; 41, block; 41, 42; 41, 51; 41, 84; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:start; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:daterange; 48, identifier:get_next_valid_time_from_t; 49, argument_list; 49, 50; 50, identifier:timestamp; 51, if_statement; 51, 52; 51, 55; 51, 78; 52, comparison_operator:is; 52, 53; 52, 54; 53, identifier:start; 54, None; 55, block; 55, 56; 55, 65; 55, 74; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:end; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:daterange; 62, identifier:get_next_invalid_time_from_t; 63, argument_list; 63, 64; 64, identifier:start; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:dr_mins; 69, identifier:append; 70, argument_list; 70, 71; 71, tuple; 71, 72; 71, 73; 72, identifier:start; 73, identifier:end; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:timestamp; 77, identifier:end; 78, else_clause; 78, 79; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:cont; 83, False; 84, if_statement; 84, 85; 84, 95; 85, comparison_operator:>; 85, 86; 85, 87; 86, identifier:timestamp; 87, binary_operator:+; 87, 88; 87, 89; 88, identifier:original_t; 89, parenthesized_expression; 89, 90; 90, binary_operator:*; 90, 91; 90, 94; 91, binary_operator:*; 91, 92; 91, 93; 92, integer:3600; 93, integer:24; 94, integer:365; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:cont; 99, False; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:periods; 103, call; 103, 104; 103, 105; 104, identifier:merge_periods; 105, argument_list; 105, 106; 106, identifier:dr_mins; 107, comment; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:dr_mins; 111, list:[]; 112, for_statement; 112, 113; 112, 114; 112, 117; 113, identifier:exclude; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:exclude; 117, block; 117, 118; 118, for_statement; 118, 119; 118, 120; 118, 123; 119, identifier:daterange; 120, attribute; 120, 121; 120, 122; 121, identifier:exclude; 122, identifier:dateranges; 123, block; 123, 124; 123, 128; 123, 132; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:timestamp; 127, identifier:original_t; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:cont; 131, True; 132, while_statement; 132, 133; 132, 134; 133, identifier:cont; 134, block; 134, 135; 134, 144; 134, 177; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:start; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:daterange; 141, identifier:get_next_valid_time_from_t; 142, argument_list; 142, 143; 143, identifier:timestamp; 144, if_statement; 144, 145; 144, 148; 144, 171; 145, comparison_operator:is; 145, 146; 145, 147; 146, identifier:start; 147, None; 148, block; 148, 149; 148, 158; 148, 167; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:end; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:daterange; 155, identifier:get_next_invalid_time_from_t; 156, argument_list; 156, 157; 157, identifier:start; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:dr_mins; 162, identifier:append; 163, argument_list; 163, 164; 164, tuple; 164, 165; 164, 166; 165, identifier:start; 166, identifier:end; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:timestamp; 170, identifier:end; 171, else_clause; 171, 172; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:cont; 176, False; 177, if_statement; 177, 178; 177, 188; 178, comparison_operator:>; 178, 179; 178, 180; 179, identifier:timestamp; 180, binary_operator:+; 180, 181; 180, 182; 181, identifier:original_t; 182, parenthesized_expression; 182, 183; 183, binary_operator:*; 183, 184; 183, 187; 184, binary_operator:*; 184, 185; 184, 186; 185, integer:3600; 186, integer:24; 187, integer:365; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:cont; 192, False; 193, if_statement; 193, 194; 193, 196; 193, 201; 194, not_operator; 194, 195; 195, identifier:dr_mins; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:periods_exclude; 200, list:[]; 201, else_clause; 201, 202; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:periods_exclude; 206, call; 206, 207; 206, 208; 207, identifier:merge_periods; 208, argument_list; 208, 209; 209, identifier:dr_mins; 210, if_statement; 210, 211; 210, 217; 210, 218; 210, 219; 211, comparison_operator:>=; 211, 212; 211, 216; 212, call; 212, 213; 212, 214; 213, identifier:len; 214, argument_list; 214, 215; 215, identifier:periods; 216, integer:1; 217, comment; 218, comment; 219, block; 219, 220; 219, 231; 219, 232; 219, 259; 220, if_statement; 220, 221; 220, 228; 221, comparison_operator:>; 221, 222; 221, 227; 222, subscript; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:periods; 225, integer:0; 226, integer:0; 227, identifier:original_t; 228, block; 228, 229; 229, return_statement; 229, 230; 230, identifier:original_t; 231, comment; 232, if_statement; 232, 233; 232, 239; 233, comparison_operator:>=; 233, 234; 233, 238; 234, call; 234, 235; 234, 236; 235, identifier:len; 236, argument_list; 236, 237; 237, identifier:periods_exclude; 238, integer:1; 239, block; 239, 240; 240, if_statement; 240, 241; 240, 252; 241, comparison_operator:<; 241, 242; 241, 247; 242, subscript; 242, 243; 242, 246; 243, subscript; 243, 244; 243, 245; 244, identifier:periods_exclude; 245, integer:0; 246, integer:0; 247, subscript; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:periods; 250, integer:0; 251, integer:1; 252, block; 252, 253; 253, return_statement; 253, 254; 254, subscript; 254, 255; 254, 258; 255, subscript; 255, 256; 255, 257; 256, identifier:periods_exclude; 257, integer:0; 258, integer:0; 259, return_statement; 259, 260; 260, subscript; 260, 261; 260, 264; 261, subscript; 261, 262; 261, 263; 262, identifier:periods; 263, integer:0; 264, integer:1; 265, return_statement; 265, 266; 266, identifier:original_t | def get_next_invalid_time_from_t(self, timestamp):
# pylint: disable=too-many-branches
"""
Get the next invalid time
:param timestamp: timestamp in seconds (of course)
:type timestamp: int or float
:return: timestamp of next invalid time
:rtype: int or float
"""
timestamp = int(timestamp)
original_t = timestamp
dr_mins = []
for daterange in self.dateranges:
timestamp = original_t
cont = True
while cont:
start = daterange.get_next_valid_time_from_t(timestamp)
if start is not None:
end = daterange.get_next_invalid_time_from_t(start)
dr_mins.append((start, end))
timestamp = end
else:
cont = False
if timestamp > original_t + (3600 * 24 * 365):
cont = False
periods = merge_periods(dr_mins)
# manage exclude periods
dr_mins = []
for exclude in self.exclude:
for daterange in exclude.dateranges:
timestamp = original_t
cont = True
while cont:
start = daterange.get_next_valid_time_from_t(timestamp)
if start is not None:
end = daterange.get_next_invalid_time_from_t(start)
dr_mins.append((start, end))
timestamp = end
else:
cont = False
if timestamp > original_t + (3600 * 24 * 365):
cont = False
if not dr_mins:
periods_exclude = []
else:
periods_exclude = merge_periods(dr_mins)
if len(periods) >= 1:
# if first valid period is after original timestamp, the first invalid time
# is the original timestamp
if periods[0][0] > original_t:
return original_t
# check the first period + first period of exclude
if len(periods_exclude) >= 1:
if periods_exclude[0][0] < periods[0][1]:
return periods_exclude[0][0]
return periods[0][1]
return original_t |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:is_correct; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 12; 5, 13; 5, 14; 5, 33; 5, 75; 5, 76; 5, 153; 5, 154; 5, 168; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:valid; 11, True; 12, comment; 13, comment; 14, for_statement; 14, 15; 14, 16; 14, 26; 15, identifier:timeperiod; 16, call; 16, 17; 16, 18; 17, identifier:list; 18, argument_list; 18, 19; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:items; 24, identifier:values; 25, argument_list; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:timeperiod; 31, identifier:rec_tag; 32, False; 33, for_statement; 33, 34; 33, 35; 33, 45; 34, identifier:timeperiod; 35, call; 35, 36; 35, 37; 36, identifier:list; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:items; 43, identifier:values; 44, argument_list; 45, block; 45, 46; 45, 65; 46, for_statement; 46, 47; 46, 48; 46, 58; 47, identifier:tmp_tp; 48, call; 48, 49; 48, 50; 49, identifier:list; 50, argument_list; 50, 51; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:items; 56, identifier:values; 57, argument_list; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:tmp_tp; 63, identifier:rec_tag; 64, False; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:valid; 68, boolean_operator:and; 68, 69; 68, 74; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:timeperiod; 72, identifier:check_exclude_rec; 73, argument_list; 74, identifier:valid; 75, comment; 76, for_statement; 76, 77; 76, 78; 76, 88; 77, identifier:timeperiod; 78, call; 78, 79; 78, 80; 79, identifier:list; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:items; 86, identifier:values; 87, argument_list; 88, block; 88, 89; 88, 93; 88, 94; 88, 137; 88, 145; 89, delete_statement; 89, 90; 90, attribute; 90, 91; 90, 92; 91, identifier:timeperiod; 92, identifier:rec_tag; 93, comment; 94, if_statement; 94, 95; 94, 101; 95, not_operator; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:timeperiod; 99, identifier:is_correct; 100, argument_list; 101, block; 101, 102; 101, 106; 101, 115; 101, 130; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:valid; 105, False; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:source; 109, call; 109, 110; 109, 111; 110, identifier:getattr; 111, argument_list; 111, 112; 111, 113; 111, 114; 112, identifier:timeperiod; 113, string:'imported_from'; 114, string:"unknown source"; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:msg; 118, binary_operator:%; 118, 119; 118, 120; 119, string:"Configuration in %s::%s is incorrect; from: %s"; 120, tuple; 120, 121; 120, 124; 120, 129; 121, attribute; 121, 122; 121, 123; 122, identifier:timeperiod; 123, identifier:my_type; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:timeperiod; 127, identifier:get_name; 128, argument_list; 129, identifier:source; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:add_error; 135, argument_list; 135, 136; 136, identifier:msg; 137, expression_statement; 137, 138; 138, augmented_assignment:+=; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:configuration_errors; 142, attribute; 142, 143; 142, 144; 143, identifier:timeperiod; 144, identifier:configuration_errors; 145, expression_statement; 145, 146; 146, augmented_assignment:+=; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:configuration_warnings; 150, attribute; 150, 151; 150, 152; 151, identifier:timeperiod; 152, identifier:configuration_warnings; 153, comment; 154, for_statement; 154, 155; 154, 156; 154, 157; 155, identifier:timeperiod; 156, identifier:self; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:valid; 161, boolean_operator:and; 161, 162; 161, 167; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:timeperiod; 165, identifier:is_correct; 166, argument_list; 167, identifier:valid; 168, return_statement; 168, 169; 169, identifier:valid | def is_correct(self):
"""
check if each properties of timeperiods are valid
:return: True if is correct, otherwise False
:rtype: bool
"""
valid = True
# We do not want a same hg to be explode again and again
# so we tag it
for timeperiod in list(self.items.values()):
timeperiod.rec_tag = False
for timeperiod in list(self.items.values()):
for tmp_tp in list(self.items.values()):
tmp_tp.rec_tag = False
valid = timeperiod.check_exclude_rec() and valid
# We clean the tags and collect the warning/erro messages
for timeperiod in list(self.items.values()):
del timeperiod.rec_tag
# Now other checks
if not timeperiod.is_correct():
valid = False
source = getattr(timeperiod, 'imported_from', "unknown source")
msg = "Configuration in %s::%s is incorrect; from: %s" % (
timeperiod.my_type, timeperiod.get_name(), source
)
self.add_error(msg)
self.configuration_errors += timeperiod.configuration_errors
self.configuration_warnings += timeperiod.configuration_warnings
# And check all timeperiods for correct (sunday is false)
for timeperiod in self:
valid = timeperiod.is_correct() and valid
return valid |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_scheduler_ordered_list; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:realm; 6, block; 6, 7; 6, 9; 6, 10; 6, 14; 6, 31; 6, 32; 6, 36; 6, 40; 6, 44; 6, 90; 6, 94; 6, 101; 6, 108; 6, 115; 6, 121; 6, 122; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:scheduler_links; 13, list:[]; 14, for_statement; 14, 15; 14, 16; 14, 19; 15, identifier:scheduler_link_uuid; 16, attribute; 16, 17; 16, 18; 17, identifier:realm; 18, identifier:schedulers; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:scheduler_links; 24, identifier:append; 25, argument_list; 25, 26; 26, subscript; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:schedulers; 30, identifier:scheduler_link_uuid; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:alive; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:spare; 39, list:[]; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:deads; 43, list:[]; 44, for_statement; 44, 45; 44, 46; 44, 47; 45, identifier:sdata; 46, identifier:scheduler_links; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 57; 48, 65; 48, 81; 49, boolean_operator:and; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:sdata; 52, identifier:alive; 53, not_operator; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:sdata; 56, identifier:spare; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:alive; 62, identifier:append; 63, argument_list; 63, 64; 64, identifier:sdata; 65, elif_clause; 65, 66; 65, 73; 66, boolean_operator:and; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:sdata; 69, identifier:alive; 70, attribute; 70, 71; 70, 72; 71, identifier:sdata; 72, identifier:spare; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:spare; 78, identifier:append; 79, argument_list; 79, 80; 80, identifier:sdata; 81, else_clause; 81, 82; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:deads; 87, identifier:append; 88, argument_list; 88, 89; 89, identifier:sdata; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:scheduler_links; 93, list:[]; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:scheduler_links; 98, identifier:extend; 99, argument_list; 99, 100; 100, identifier:alive; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:scheduler_links; 105, identifier:extend; 106, argument_list; 106, 107; 107, identifier:spare; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:scheduler_links; 112, identifier:extend; 113, argument_list; 113, 114; 114, identifier:deads; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:scheduler_links; 119, identifier:reverse; 120, argument_list; 121, comment; 122, return_statement; 122, 123; 123, identifier:scheduler_links | def get_scheduler_ordered_list(self, realm):
"""Get sorted scheduler list for a specific realm
List is ordered as: alive first, then spare (if any), then dead scheduler links
:param realm: realm we want scheduler from
:type realm: alignak.objects.realm.Realm
:return: sorted scheduler list
:rtype: list[alignak.objects.schedulerlink.SchedulerLink]
"""
# Get the schedulers for the required realm
scheduler_links = []
for scheduler_link_uuid in realm.schedulers:
scheduler_links.append(self.schedulers[scheduler_link_uuid])
# Now we sort the schedulers so we take alive, then spare, then dead,
alive = []
spare = []
deads = []
for sdata in scheduler_links:
if sdata.alive and not sdata.spare:
alive.append(sdata)
elif sdata.alive and sdata.spare:
spare.append(sdata)
else:
deads.append(sdata)
scheduler_links = []
scheduler_links.extend(alive)
scheduler_links.extend(spare)
scheduler_links.extend(deads)
scheduler_links.reverse() # I need to pop the list, so reverse the list...
return scheduler_links |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 9; 2, function_name:dispatch; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:test; 7, False; 8, comment; 9, block; 9, 10; 9, 12; 9, 25; 9, 37; 9, 50; 9, 57; 9, 63; 9, 64; 9, 182; 9, 274; 9, 375; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 17; 13, not_operator; 13, 14; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:new_to_dispatch; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:DispatcherError; 21, argument_list; 21, 22; 22, concatenated_string; 22, 23; 22, 24; 23, string:"Dispatcher cannot dispatch, "; 24, string:"because no configuration is prepared!"; 25, if_statement; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:first_dispatch_done; 29, block; 29, 30; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:DispatcherError; 33, argument_list; 33, 34; 34, concatenated_string; 34, 35; 34, 36; 35, string:"Dispatcher cannot dispatch, "; 36, string:"because the configuration is still dispatched!"; 37, if_statement; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:dispatch_ok; 41, block; 41, 42; 41, 49; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:logger; 46, identifier:info; 47, argument_list; 47, 48; 48, string:"Dispatching is already done and ok..."; 49, return_statement; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:logger; 54, identifier:info; 55, argument_list; 55, 56; 56, string:"Trying to send configuration to the satellites..."; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:dispatch_ok; 62, True; 63, comment; 64, for_statement; 64, 65; 64, 66; 64, 69; 64, 70; 65, identifier:link; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:arbiters; 69, comment; 70, block; 70, 71; 70, 80; 70, 88; 70, 96; 70, 112; 70, 129; 70, 139; 70, 149; 70, 161; 70, 167; 70, 174; 70, 175; 70, 176; 71, if_statement; 71, 72; 71, 77; 71, 78; 72, comparison_operator:==; 72, 73; 72, 74; 73, identifier:link; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:arbiter_link; 77, comment; 78, block; 78, 79; 79, continue_statement; 80, if_statement; 80, 81; 80, 85; 80, 86; 81, not_operator; 81, 82; 82, attribute; 82, 83; 82, 84; 83, identifier:link; 84, identifier:active; 85, comment; 86, block; 86, 87; 87, continue_statement; 88, if_statement; 88, 89; 88, 93; 88, 94; 89, not_operator; 89, 90; 90, attribute; 90, 91; 90, 92; 91, identifier:link; 92, identifier:spare; 93, comment; 94, block; 94, 95; 95, continue_statement; 96, if_statement; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:link; 99, identifier:configuration_sent; 100, block; 100, 101; 100, 111; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:logger; 105, identifier:debug; 106, argument_list; 106, 107; 106, 108; 107, string:"Arbiter %s already sent!"; 108, attribute; 108, 109; 108, 110; 109, identifier:link; 110, identifier:name; 111, continue_statement; 112, if_statement; 112, 113; 112, 117; 113, not_operator; 113, 114; 114, attribute; 114, 115; 114, 116; 115, identifier:link; 116, identifier:reachable; 117, block; 117, 118; 117, 128; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:logger; 122, identifier:debug; 123, argument_list; 123, 124; 123, 125; 124, string:"Arbiter %s is not reachable to receive its configuration"; 125, attribute; 125, 126; 125, 127; 126, identifier:link; 127, identifier:name; 128, continue_statement; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:logger; 133, identifier:info; 134, argument_list; 134, 135; 134, 136; 135, string:"Sending configuration to the arbiter %s"; 136, attribute; 136, 137; 136, 138; 137, identifier:link; 138, identifier:name; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:logger; 143, identifier:debug; 144, argument_list; 144, 145; 144, 146; 145, string:"- %s"; 146, attribute; 146, 147; 146, 148; 147, identifier:link; 148, identifier:cfg; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:link; 153, identifier:put_conf; 154, argument_list; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:link; 157, identifier:cfg; 158, keyword_argument; 158, 159; 158, 160; 159, identifier:test; 160, identifier:test; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:link; 165, identifier:configuration_sent; 166, True; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:logger; 171, identifier:info; 172, argument_list; 172, 173; 173, string:"- sent"; 174, comment; 175, comment; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:link; 180, identifier:do_not_run; 181, argument_list; 182, for_statement; 182, 183; 182, 184; 182, 187; 183, identifier:link; 184, attribute; 184, 185; 184, 186; 185, identifier:self; 186, identifier:schedulers; 187, block; 187, 188; 187, 204; 187, 212; 187, 229; 187, 239; 187, 249; 187, 261; 187, 267; 188, if_statement; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:link; 191, identifier:configuration_sent; 192, block; 192, 193; 192, 203; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:logger; 197, identifier:debug; 198, argument_list; 198, 199; 198, 200; 199, string:"Scheduler %s already sent!"; 200, attribute; 200, 201; 200, 202; 201, identifier:link; 202, identifier:name; 203, continue_statement; 204, if_statement; 204, 205; 204, 209; 204, 210; 205, not_operator; 205, 206; 206, attribute; 206, 207; 206, 208; 207, identifier:link; 208, identifier:active; 209, comment; 210, block; 210, 211; 211, continue_statement; 212, if_statement; 212, 213; 212, 217; 213, not_operator; 213, 214; 214, attribute; 214, 215; 214, 216; 215, identifier:link; 216, identifier:reachable; 217, block; 217, 218; 217, 228; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:logger; 222, identifier:debug; 223, argument_list; 223, 224; 223, 225; 224, string:"Scheduler %s is not reachable to receive its configuration"; 225, attribute; 225, 226; 225, 227; 226, identifier:link; 227, identifier:name; 228, continue_statement; 229, expression_statement; 229, 230; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:logger; 233, identifier:info; 234, argument_list; 234, 235; 234, 236; 235, string:"Sending configuration to the scheduler %s"; 236, attribute; 236, 237; 236, 238; 237, identifier:link; 238, identifier:name; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:logger; 243, identifier:debug; 244, argument_list; 244, 245; 244, 246; 245, string:"- %s"; 246, attribute; 246, 247; 246, 248; 247, identifier:link; 248, identifier:cfg; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:link; 253, identifier:put_conf; 254, argument_list; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:link; 257, identifier:cfg; 258, keyword_argument; 258, 259; 258, 260; 259, identifier:test; 260, identifier:test; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:link; 265, identifier:configuration_sent; 266, True; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:logger; 271, identifier:info; 272, argument_list; 272, 273; 273, string:"- sent"; 274, for_statement; 274, 275; 274, 276; 274, 279; 275, identifier:link; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:satellites; 279, block; 279, 280; 279, 299; 279, 307; 279, 327; 279, 340; 279, 350; 279, 362; 279, 368; 280, if_statement; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:link; 283, identifier:configuration_sent; 284, block; 284, 285; 284, 298; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:logger; 289, identifier:debug; 290, argument_list; 290, 291; 290, 292; 290, 295; 291, string:"%s %s already sent!"; 292, attribute; 292, 293; 292, 294; 293, identifier:link; 294, identifier:type; 295, attribute; 295, 296; 295, 297; 296, identifier:link; 297, identifier:name; 298, continue_statement; 299, if_statement; 299, 300; 299, 304; 299, 305; 300, not_operator; 300, 301; 301, attribute; 301, 302; 301, 303; 302, identifier:link; 303, identifier:active; 304, comment; 305, block; 305, 306; 306, continue_statement; 307, if_statement; 307, 308; 307, 312; 308, not_operator; 308, 309; 309, attribute; 309, 310; 309, 311; 310, identifier:link; 311, identifier:reachable; 312, block; 312, 313; 312, 326; 313, expression_statement; 313, 314; 314, call; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:logger; 317, identifier:warning; 318, argument_list; 318, 319; 318, 320; 318, 323; 319, string:"%s %s is not reachable to receive its configuration"; 320, attribute; 320, 321; 320, 322; 321, identifier:link; 322, identifier:type; 323, attribute; 323, 324; 323, 325; 324, identifier:link; 325, identifier:name; 326, continue_statement; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:logger; 331, identifier:info; 332, argument_list; 332, 333; 332, 334; 332, 337; 333, string:"Sending configuration to the %s %s"; 334, attribute; 334, 335; 334, 336; 335, identifier:link; 336, identifier:type; 337, attribute; 337, 338; 337, 339; 338, identifier:link; 339, identifier:name; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:logger; 344, identifier:debug; 345, argument_list; 345, 346; 345, 347; 346, string:"- %s"; 347, attribute; 347, 348; 347, 349; 348, identifier:link; 349, identifier:cfg; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:link; 354, identifier:put_conf; 355, argument_list; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:link; 358, identifier:cfg; 359, keyword_argument; 359, 360; 359, 361; 360, identifier:test; 361, identifier:test; 362, expression_statement; 362, 363; 363, assignment; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:link; 366, identifier:configuration_sent; 367, True; 368, expression_statement; 368, 369; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:logger; 372, identifier:info; 373, argument_list; 373, 374; 374, string:"- sent"; 375, if_statement; 375, 376; 375, 379; 375, 380; 376, attribute; 376, 377; 376, 378; 377, identifier:self; 378, identifier:dispatch_ok; 379, comment; 380, block; 380, 381; 380, 387; 381, expression_statement; 381, 382; 382, assignment; 382, 383; 382, 386; 383, attribute; 383, 384; 383, 385; 384, identifier:self; 385, identifier:new_to_dispatch; 386, False; 387, expression_statement; 387, 388; 388, assignment; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:self; 391, identifier:first_dispatch_done; 392, True | def dispatch(self, test=False): # pylint: disable=too-many-branches
"""
Send configuration to satellites
:return: None
"""
if not self.new_to_dispatch:
raise DispatcherError("Dispatcher cannot dispatch, "
"because no configuration is prepared!")
if self.first_dispatch_done:
raise DispatcherError("Dispatcher cannot dispatch, "
"because the configuration is still dispatched!")
if self.dispatch_ok:
logger.info("Dispatching is already done and ok...")
return
logger.info("Trying to send configuration to the satellites...")
self.dispatch_ok = True
# todo: the 3 loops hereunder may be factorized
for link in self.arbiters:
# If not me and a spare arbiter...
if link == self.arbiter_link:
# I exclude myself from the dispatching, I have my configuration ;)
continue
if not link.active:
# I exclude the daemons that are not active
continue
if not link.spare:
# Do not dispatch to a master arbiter!
continue
if link.configuration_sent:
logger.debug("Arbiter %s already sent!", link.name)
continue
if not link.reachable:
logger.debug("Arbiter %s is not reachable to receive its configuration",
link.name)
continue
logger.info("Sending configuration to the arbiter %s", link.name)
logger.debug("- %s", link.cfg)
link.put_conf(link.cfg, test=test)
link.configuration_sent = True
logger.info("- sent")
# Now that the spare arbiter has a configuration, tell him it must not run,
# because I'm not dead ;)
link.do_not_run()
for link in self.schedulers:
if link.configuration_sent:
logger.debug("Scheduler %s already sent!", link.name)
continue
if not link.active:
# I exclude the daemons that are not active
continue
if not link.reachable:
logger.debug("Scheduler %s is not reachable to receive its configuration",
link.name)
continue
logger.info("Sending configuration to the scheduler %s", link.name)
logger.debug("- %s", link.cfg)
link.put_conf(link.cfg, test=test)
link.configuration_sent = True
logger.info("- sent")
for link in self.satellites:
if link.configuration_sent:
logger.debug("%s %s already sent!", link.type, link.name)
continue
if not link.active:
# I exclude the daemons that are not active
continue
if not link.reachable:
logger.warning("%s %s is not reachable to receive its configuration",
link.type, link.name)
continue
logger.info("Sending configuration to the %s %s", link.type, link.name)
logger.debug("- %s", link.cfg)
link.put_conf(link.cfg, test=test)
link.configuration_sent = True
logger.info("- sent")
if self.dispatch_ok:
# Newly prepared configuration got dispatched correctly
self.new_to_dispatch = False
self.first_dispatch_done = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 1, 8; 2, function_name:_get_value_from_element; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:elt; 6, identifier:prop; 7, comment; 8, block; 8, 9; 8, 11; 8, 15; 8, 16; 8, 29; 8, 38; 8, 45; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:args; 14, None; 15, comment; 16, if_statement; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:prop; 21, identifier:tuple; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, pattern_list; 25, 26; 25, 27; 26, identifier:prop; 27, identifier:args; 28, identifier:prop; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:value; 32, call; 32, 33; 32, 34; 33, identifier:getattr; 34, argument_list; 34, 35; 34, 36; 34, 37; 35, identifier:elt; 36, identifier:prop; 37, None; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:is; 39, 40; 39, 41; 40, identifier:value; 41, None; 42, block; 42, 43; 43, return_statement; 43, 44; 44, string:'n/a'; 45, try_statement; 45, 46; 45, 47; 45, 116; 45, 127; 46, comment; 47, block; 47, 48; 47, 65; 47, 66; 47, 78; 47, 79; 47, 87; 47, 88; 47, 89; 47, 90; 47, 94; 47, 110; 48, if_statement; 48, 49; 48, 54; 48, 55; 49, call; 49, 50; 49, 51; 50, identifier:isinstance; 51, argument_list; 51, 52; 51, 53; 52, identifier:value; 53, identifier:list; 54, comment; 55, block; 55, 56; 56, return_statement; 56, 57; 57, binary_operator:%; 57, 58; 57, 59; 58, string:"[%s]"; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, string:','; 62, identifier:join; 63, argument_list; 63, 64; 64, identifier:value; 65, comment; 66, if_statement; 66, 67; 66, 75; 67, not_operator; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:isinstance; 70, argument_list; 70, 71; 70, 72; 71, identifier:value; 72, attribute; 72, 73; 72, 74; 73, identifier:collections; 74, identifier:Callable; 75, block; 75, 76; 76, return_statement; 76, 77; 77, identifier:value; 78, comment; 79, if_statement; 79, 80; 79, 82; 80, not_operator; 80, 81; 81, identifier:args; 82, block; 82, 83; 83, return_statement; 83, 84; 84, call; 84, 85; 84, 86; 85, identifier:value; 86, argument_list; 87, comment; 88, comment; 89, comment; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:real_args; 93, list:[]; 94, for_statement; 94, 95; 94, 96; 94, 97; 95, identifier:arg; 96, identifier:args; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:real_args; 102, identifier:append; 103, argument_list; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:getattr; 106, argument_list; 106, 107; 106, 108; 106, 109; 107, identifier:self; 108, identifier:arg; 109, None; 110, return_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:value; 113, argument_list; 113, 114; 114, list_splat; 114, 115; 115, identifier:real_args; 116, except_clause; 116, 117; 116, 118; 116, 119; 116, 120; 116, 121; 116, 122; 116, 123; 116, 124; 117, identifier:AttributeError; 118, comment; 119, comment; 120, comment; 121, comment; 122, comment; 123, comment; 124, block; 124, 125; 125, return_statement; 125, 126; 126, string:'n/a'; 127, except_clause; 127, 128; 127, 129; 128, identifier:UnicodeError; 129, block; 129, 130; 129, 146; 130, if_statement; 130, 131; 130, 136; 131, call; 131, 132; 131, 133; 132, identifier:isinstance; 133, argument_list; 133, 134; 133, 135; 134, identifier:value; 135, identifier:string_types; 136, block; 136, 137; 137, return_statement; 137, 138; 138, call; 138, 139; 138, 140; 139, identifier:str; 140, argument_list; 140, 141; 140, 142; 140, 143; 141, identifier:value; 142, string:'utf8'; 143, keyword_argument; 143, 144; 143, 145; 144, identifier:errors; 145, string:'ignore'; 146, return_statement; 146, 147; 147, string:'n/a' | def _get_value_from_element(self, elt, prop):
# pylint: disable=too-many-return-statements
"""Get value from an element's property.
the property may be a function to call.
If the property is not resolved (because not implemented), this function will return 'n/a'
:param elt: element
:type elt: object
:param prop: element property
:type prop: str
:return: getattr(elt, prop) or getattr(elt, prop)() (call)
:rtype: str
"""
args = None
# We have args to provide to the function
if isinstance(prop, tuple):
prop, args = prop
value = getattr(elt, prop, None)
if value is None:
return 'n/a'
try:
# If the macro is set to a list property
if isinstance(value, list):
# Return the list items, comma separated and bracketed
return "[%s]" % ','.join(value)
# If the macro is not set as a function to call
if not isinstance(value, collections.Callable):
return value
# Case of a function call with no arguments
if not args:
return value()
# Case where we need args to the function
# ex : HOSTGROUPNAME (we need hostgroups)
# ex : SHORTSTATUS (we need hosts and services if bp_rule)
real_args = []
for arg in args:
real_args.append(getattr(self, arg, None))
return value(*real_args)
except AttributeError:
# Commented because there are many unresolved macros and this log is spamming :/
# # Raise a warning and return a strange value when macro cannot be resolved
# warnings.warn(
# 'Error when getting the property value for a macro: %s',
# MacroWarning, stacklevel=2)
# Return a strange value when macro cannot be resolved
return 'n/a'
except UnicodeError:
if isinstance(value, string_types):
return str(value, 'utf8', errors='ignore')
return 'n/a' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_type_of_macro; 3, parameters; 3, 4; 3, 5; 4, identifier:macros; 5, identifier:objs; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, for_statement; 9, 10; 9, 11; 9, 12; 9, 13; 10, identifier:macro; 11, identifier:macros; 12, comment; 13, block; 13, 14; 13, 137; 13, 138; 14, if_statement; 14, 15; 14, 22; 14, 32; 14, 33; 14, 34; 14, 35; 14, 61; 14, 88; 14, 114; 14, 115; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:re; 18, identifier:match; 19, argument_list; 19, 20; 19, 21; 20, string:r'ARG\d'; 21, identifier:macro; 22, block; 22, 23; 22, 31; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 30; 25, subscript; 25, 26; 25, 29; 26, subscript; 26, 27; 26, 28; 27, identifier:macros; 28, identifier:macro; 29, string:'type'; 30, string:'ARGN'; 31, continue_statement; 32, comment; 33, comment; 34, comment; 35, elif_clause; 35, 36; 35, 43; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:re; 39, identifier:match; 40, argument_list; 40, 41; 40, 42; 41, string:r'_HOST\w'; 42, identifier:macro; 43, block; 43, 44; 43, 52; 43, 60; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 51; 46, subscript; 46, 47; 46, 50; 47, subscript; 47, 48; 47, 49; 48, identifier:macros; 49, identifier:macro; 50, string:'type'; 51, string:'CUSTOM'; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 59; 54, subscript; 54, 55; 54, 58; 55, subscript; 55, 56; 55, 57; 56, identifier:macros; 57, identifier:macro; 58, string:'class'; 59, string:'HOST'; 60, continue_statement; 61, elif_clause; 61, 62; 61, 69; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:re; 65, identifier:match; 66, argument_list; 66, 67; 66, 68; 67, string:r'_SERVICE\w'; 68, identifier:macro; 69, block; 69, 70; 69, 78; 69, 86; 69, 87; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 77; 72, subscript; 72, 73; 72, 76; 73, subscript; 73, 74; 73, 75; 74, identifier:macros; 75, identifier:macro; 76, string:'type'; 77, string:'CUSTOM'; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 85; 80, subscript; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:macros; 83, identifier:macro; 84, string:'class'; 85, string:'SERVICE'; 86, comment; 87, continue_statement; 88, elif_clause; 88, 89; 88, 96; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:re; 92, identifier:match; 93, argument_list; 93, 94; 93, 95; 94, string:r'_CONTACT\w'; 95, identifier:macro; 96, block; 96, 97; 96, 105; 96, 113; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 104; 99, subscript; 99, 100; 99, 103; 100, subscript; 100, 101; 100, 102; 101, identifier:macros; 102, identifier:macro; 103, string:'type'; 104, string:'CUSTOM'; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 112; 107, subscript; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:macros; 110, identifier:macro; 111, string:'class'; 112, string:'CONTACT'; 113, continue_statement; 114, comment; 115, elif_clause; 115, 116; 115, 127; 116, comparison_operator:>; 116, 117; 116, 126; 117, call; 117, 118; 117, 119; 118, identifier:len; 119, argument_list; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:macro; 123, identifier:split; 124, argument_list; 124, 125; 125, string:':'; 126, integer:1; 127, block; 127, 128; 127, 136; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 135; 130, subscript; 130, 131; 130, 134; 131, subscript; 131, 132; 131, 133; 132, identifier:macros; 133, identifier:macro; 134, string:'type'; 135, string:'ONDEMAND'; 136, continue_statement; 137, comment; 138, for_statement; 138, 139; 138, 140; 138, 141; 139, identifier:obj; 140, identifier:objs; 141, block; 141, 142; 142, if_statement; 142, 143; 142, 148; 143, comparison_operator:in; 143, 144; 143, 145; 144, identifier:macro; 145, attribute; 145, 146; 145, 147; 146, identifier:obj; 147, identifier:macros; 148, block; 148, 149; 148, 157; 148, 165; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 156; 151, subscript; 151, 152; 151, 155; 152, subscript; 152, 153; 152, 154; 153, identifier:macros; 154, identifier:macro; 155, string:'type'; 156, string:'object'; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 164; 159, subscript; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:macros; 162, identifier:macro; 163, string:'object'; 164, identifier:obj; 165, continue_statement | def _get_type_of_macro(macros, objs):
r"""Set macros types
Example::
ARG\d -> ARGN,
HOSTBLABLA -> class one and set Host in class)
_HOSTTOTO -> HOST CUSTOM MACRO TOTO
SERVICESTATEID:srv-1:Load$ -> MACRO SERVICESTATEID of the service Load of host srv-1
:param macros: macros list in a dictionary
:type macros: dict
:param objs: objects list, used to tag object macros
:type objs: list
:return: None
"""
for macro in macros:
# ARGN Macros
if re.match(r'ARG\d', macro):
macros[macro]['type'] = 'ARGN'
continue
# USERN macros
# are managed in the Config class, so no
# need to look that here
elif re.match(r'_HOST\w', macro):
macros[macro]['type'] = 'CUSTOM'
macros[macro]['class'] = 'HOST'
continue
elif re.match(r'_SERVICE\w', macro):
macros[macro]['type'] = 'CUSTOM'
macros[macro]['class'] = 'SERVICE'
# value of macro: re.split('_HOST', '_HOSTMAC_ADDRESS')[1]
continue
elif re.match(r'_CONTACT\w', macro):
macros[macro]['type'] = 'CUSTOM'
macros[macro]['class'] = 'CONTACT'
continue
# On demand macro
elif len(macro.split(':')) > 1:
macros[macro]['type'] = 'ONDEMAND'
continue
# OK, classical macro...
for obj in objs:
if macro in obj.macros:
macros[macro]['type'] = 'object'
macros[macro]['object'] = obj
continue |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 1, 8; 2, function_name:_resolve_ondemand; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:macro; 6, identifier:data; 7, comment; 8, block; 8, 9; 8, 11; 8, 20; 8, 27; 8, 33; 8, 34; 8, 229; 8, 230; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:elts; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:macro; 17, identifier:split; 18, argument_list; 18, 19; 19, string:':'; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:nb_parts; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:elts; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:macro_name; 30, subscript; 30, 31; 30, 32; 31, identifier:elts; 32, integer:0; 33, comment; 34, if_statement; 34, 35; 34, 38; 34, 130; 34, 131; 35, comparison_operator:==; 35, 36; 35, 37; 36, identifier:nb_parts; 37, integer:3; 38, block; 38, 39; 38, 43; 38, 55; 38, 56; 38, 57; 38, 58; 38, 86; 38, 87; 38, 99; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:val; 42, string:''; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, tuple_pattern; 45, 46; 45, 47; 46, identifier:host_name; 47, identifier:service_description; 48, tuple; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:elts; 51, integer:1; 52, subscript; 52, 53; 52, 54; 53, identifier:elts; 54, integer:2; 55, comment; 56, comment; 57, comment; 58, if_statement; 58, 59; 58, 62; 59, comparison_operator:==; 59, 60; 59, 61; 60, identifier:host_name; 61, string:''; 62, block; 62, 63; 63, for_statement; 63, 64; 63, 65; 63, 66; 64, identifier:elt; 65, identifier:data; 66, block; 66, 67; 67, if_statement; 67, 68; 67, 79; 68, boolean_operator:and; 68, 69; 68, 72; 69, comparison_operator:is; 69, 70; 69, 71; 70, identifier:elt; 71, None; 72, comparison_operator:==; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:elt; 75, identifier:__class__; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:host_class; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:host_name; 83, attribute; 83, 84; 83, 85; 84, identifier:elt; 85, identifier:host_name; 86, comment; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:serv; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:services; 95, identifier:find_srv_by_name_and_hostname; 96, argument_list; 96, 97; 96, 98; 97, identifier:host_name; 98, identifier:service_description; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:serv; 102, None; 103, block; 103, 104; 103, 110; 103, 118; 103, 128; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:cls; 107, attribute; 107, 108; 107, 109; 108, identifier:serv; 109, identifier:__class__; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:prop; 113, subscript; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:cls; 116, identifier:macros; 117, identifier:macro_name; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:val; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_get_value_from_element; 125, argument_list; 125, 126; 125, 127; 126, identifier:serv; 127, identifier:prop; 128, return_statement; 128, 129; 129, identifier:val; 130, comment; 131, else_clause; 131, 132; 132, block; 132, 133; 132, 137; 132, 143; 132, 144; 132, 145; 132, 173; 132, 227; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:val; 136, string:''; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:elt_name; 140, subscript; 140, 141; 140, 142; 141, identifier:elts; 142, integer:1; 143, comment; 144, comment; 145, if_statement; 145, 146; 145, 149; 146, comparison_operator:==; 146, 147; 146, 148; 147, identifier:elt_name; 148, string:''; 149, block; 149, 150; 150, for_statement; 150, 151; 150, 152; 150, 153; 151, identifier:elt; 152, identifier:data; 153, block; 153, 154; 154, if_statement; 154, 155; 154, 166; 155, boolean_operator:and; 155, 156; 155, 159; 156, comparison_operator:is; 156, 157; 156, 158; 157, identifier:elt; 158, None; 159, comparison_operator:==; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:elt; 162, identifier:__class__; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:host_class; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:elt_name; 170, attribute; 170, 171; 170, 172; 171, identifier:elt; 172, identifier:host_name; 173, for_statement; 173, 174; 173, 175; 173, 178; 174, identifier:od_list; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:lists_on_demand; 178, block; 178, 179; 178, 185; 178, 186; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:cls; 182, attribute; 182, 183; 182, 184; 183, identifier:od_list; 184, identifier:inner_class; 185, comment; 186, if_statement; 186, 187; 186, 192; 187, comparison_operator:in; 187, 188; 187, 189; 188, identifier:macro_name; 189, attribute; 189, 190; 189, 191; 190, identifier:cls; 191, identifier:macros; 192, block; 192, 193; 192, 201; 192, 210; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:prop; 196, subscript; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:cls; 199, identifier:macros; 200, identifier:macro_name; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:i; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:od_list; 207, identifier:find_by_name; 208, argument_list; 208, 209; 209, identifier:elt_name; 210, if_statement; 210, 211; 210, 214; 211, comparison_operator:is; 211, 212; 211, 213; 212, identifier:i; 213, None; 214, block; 214, 215; 214, 225; 214, 226; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:val; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:_get_value_from_element; 222, argument_list; 222, 223; 222, 224; 223, identifier:i; 224, identifier:prop; 225, comment; 226, break_statement; 227, return_statement; 227, 228; 228, identifier:val; 229, comment; 230, return_statement; 230, 231; 231, string:'n/a' | def _resolve_ondemand(self, macro, data):
# pylint: disable=too-many-locals
"""Get on demand macro value
If the macro cannot be resolved, this function will return 'n/a' rather than
an empty string, this to alert the caller of a potential problem.
:param macro: macro to parse
:type macro:
:param data: data to get value from
:type data:
:return: macro value
:rtype: str
"""
elts = macro.split(':')
nb_parts = len(elts)
macro_name = elts[0]
# 3 parts for a service, 2 for all others types...
if nb_parts == 3:
val = ''
(host_name, service_description) = (elts[1], elts[2])
# host_name can be void, so it's the host in data
# that is important. We use our self.host_class to
# find the host in the data :)
if host_name == '':
for elt in data:
if elt is not None and elt.__class__ == self.host_class:
host_name = elt.host_name
# Ok now we get service
serv = self.services.find_srv_by_name_and_hostname(host_name, service_description)
if serv is not None:
cls = serv.__class__
prop = cls.macros[macro_name]
val = self._get_value_from_element(serv, prop)
return val
# Ok, service was easy, now hard part
else:
val = ''
elt_name = elts[1]
# Special case: elt_name can be void
# so it's the host where it apply
if elt_name == '':
for elt in data:
if elt is not None and elt.__class__ == self.host_class:
elt_name = elt.host_name
for od_list in self.lists_on_demand:
cls = od_list.inner_class
# We search our type by looking at the macro
if macro_name in cls.macros:
prop = cls.macros[macro_name]
i = od_list.find_by_name(elt_name)
if i is not None:
val = self._get_value_from_element(i, prop)
# Ok we got our value :)
break
return val
# Return a strange value in this case rather than an empty string
return 'n/a' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 2, function_name:parse; 3, parameters; 3, 4; 4, identifier:self; 5, comment; 6, block; 6, 7; 6, 9; 6, 10; 6, 14; 6, 27; 6, 39; 6, 48; 6, 105; 6, 114; 6, 115; 6, 125; 6, 348; 6, 358; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:sub_directory; 13, string:'alignak.d'; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:dir_name; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:os; 21, identifier:path; 22, identifier:dirname; 23, argument_list; 23, 24; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:configuration_file; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:dir_name; 30, call; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:os; 34, identifier:path; 35, identifier:join; 36, argument_list; 36, 37; 36, 38; 37, identifier:dir_name; 38, identifier:sub_directory; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:cfg_files; 44, list:[self.configuration_file]; 44, 45; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:configuration_file; 48, if_statement; 48, 49; 48, 57; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:os; 53, identifier:path; 54, identifier:exists; 55, argument_list; 55, 56; 56, identifier:dir_name; 57, block; 57, 58; 58, for_statement; 58, 59; 58, 63; 58, 72; 59, pattern_list; 59, 60; 59, 61; 59, 62; 60, identifier:root; 61, identifier:_; 62, identifier:walk_files; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:os; 66, identifier:walk; 67, argument_list; 67, 68; 67, 69; 68, identifier:dir_name; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:followlinks; 71, True; 72, block; 72, 73; 73, for_statement; 73, 74; 73, 75; 73, 76; 74, identifier:found_file; 75, identifier:walk_files; 76, block; 76, 77; 76, 88; 77, if_statement; 77, 78; 77, 86; 78, not_operator; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:re; 82, identifier:search; 83, argument_list; 83, 84; 83, 85; 84, string:r"\.ini$"; 85, identifier:found_file; 86, block; 86, 87; 87, continue_statement; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:cfg_files; 94, identifier:append; 95, argument_list; 95, 96; 96, call; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:os; 100, identifier:path; 101, identifier:join; 102, argument_list; 102, 103; 102, 104; 103, identifier:root; 104, identifier:found_file; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 108; 107, identifier:print; 108, argument_list; 108, 109; 109, binary_operator:%; 109, 110; 109, 111; 110, string:"Loading configuration files: %s "; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:cfg_files; 114, comment; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:config; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:configparser; 123, identifier:ConfigParser; 124, argument_list; 125, try_statement; 125, 126; 125, 281; 125, 316; 126, block; 126, 127; 126, 138; 126, 170; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:config; 133, identifier:read; 134, argument_list; 134, 135; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:cfg_files; 138, if_statement; 138, 139; 138, 146; 139, comparison_operator:==; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:config; 144, identifier:_sections; 145, dictionary; 146, block; 146, 147; 146, 156; 146, 163; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 150; 149, identifier:print; 150, argument_list; 150, 151; 151, binary_operator:%; 151, 152; 151, 153; 152, string:"* bad formatted configuration file: %s "; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:configuration_file; 156, if_statement; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:embedded; 160, block; 160, 161; 161, raise_statement; 161, 162; 162, identifier:ValueError; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:sys; 167, identifier:exit; 168, argument_list; 168, 169; 169, integer:2; 170, for_statement; 170, 171; 170, 172; 170, 179; 171, identifier:section; 172, call; 172, 173; 172, 178; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:config; 177, identifier:sections; 178, argument_list; 179, block; 179, 180; 179, 192; 180, if_statement; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:verbose; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:print; 188, argument_list; 188, 189; 189, binary_operator:%; 189, 190; 189, 191; 190, string:"- section: %s"; 191, identifier:section; 192, for_statement; 192, 193; 192, 196; 192, 204; 193, tuple_pattern; 193, 194; 193, 195; 194, identifier:key; 195, identifier:value; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:config; 201, identifier:items; 202, argument_list; 202, 203; 203, identifier:section; 204, block; 204, 205; 204, 213; 204, 214; 204, 221; 204, 222; 204, 230; 204, 244; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:inner_property; 208, binary_operator:%; 208, 209; 208, 210; 209, string:"%s.%s"; 210, tuple; 210, 211; 210, 212; 211, identifier:section; 212, identifier:key; 213, comment; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 217; 216, identifier:setattr; 217, argument_list; 217, 218; 217, 219; 217, 220; 218, identifier:self; 219, identifier:inner_property; 220, identifier:value; 221, comment; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 229; 224, subscript; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:os; 227, identifier:environ; 228, identifier:inner_property; 229, identifier:value; 230, if_statement; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:verbose; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 238; 237, identifier:print; 238, argument_list; 238, 239; 239, binary_operator:%; 239, 240; 239, 241; 240, string:" %s = %s"; 241, tuple; 241, 242; 241, 243; 242, identifier:inner_property; 243, identifier:value; 244, if_statement; 244, 245; 244, 248; 244, 249; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:export; 248, comment; 249, block; 249, 250; 249, 261; 249, 269; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:inner_property; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:re; 256, identifier:sub; 257, argument_list; 257, 258; 257, 259; 257, 260; 258, string:'[^0-9a-zA-Z]+'; 259, string:'_'; 260, identifier:inner_property; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:inner_property; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:inner_property; 267, identifier:upper; 268, argument_list; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 272; 271, identifier:print; 272, argument_list; 272, 273; 273, binary_operator:%; 273, 274; 273, 275; 274, string:"export %s=%s"; 275, tuple; 275, 276; 275, 277; 276, identifier:inner_property; 277, call; 277, 278; 277, 279; 278, identifier:cmd_quote; 279, argument_list; 279, 280; 280, identifier:value; 281, except_clause; 281, 282; 281, 288; 282, as_pattern; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:configparser; 285, identifier:ParsingError; 286, as_pattern_target; 286, 287; 287, identifier:exp; 288, block; 288, 289; 288, 302; 288, 309; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 292; 291, identifier:print; 292, argument_list; 292, 293; 293, binary_operator:%; 293, 294; 293, 295; 294, string:"* parsing error in config file : %s\n%s"; 295, tuple; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:configuration_file; 299, attribute; 299, 300; 299, 301; 300, identifier:exp; 301, identifier:message; 302, if_statement; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:self; 305, identifier:embedded; 306, block; 306, 307; 307, return_statement; 307, 308; 308, False; 309, expression_statement; 309, 310; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:sys; 313, identifier:exit; 314, argument_list; 314, 315; 315, integer:3; 316, except_clause; 316, 317; 316, 323; 317, as_pattern; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:configparser; 320, identifier:InterpolationMissingOptionError; 321, as_pattern_target; 321, 322; 322, identifier:exp; 323, block; 323, 324; 323, 334; 323, 341; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 327; 326, identifier:print; 327, argument_list; 327, 328; 328, binary_operator:%; 328, 329; 328, 330; 329, string:"* incorrect or missing variable: %s"; 330, call; 330, 331; 330, 332; 331, identifier:str; 332, argument_list; 332, 333; 333, identifier:exp; 334, if_statement; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:self; 337, identifier:embedded; 338, block; 338, 339; 339, return_statement; 339, 340; 340, False; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:sys; 345, identifier:exit; 346, argument_list; 346, 347; 347, integer:3; 348, if_statement; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:self; 351, identifier:verbose; 352, block; 352, 353; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 356; 355, identifier:print; 356, argument_list; 356, 357; 357, string:"Configuration file parsed correctly"; 358, return_statement; 358, 359; 359, True | def parse(self):
# pylint: disable=too-many-branches
"""
Check if some extra configuration files are existing in an `alignak.d` sub directory
near the found configuration file.
Parse the Alignak configuration file(s)
Exit the script if some errors are encountered.
:return: True/False
"""
# Search if some ini files existe in an alignak.d sub-directory
sub_directory = 'alignak.d'
dir_name = os.path.dirname(self.configuration_file)
dir_name = os.path.join(dir_name, sub_directory)
self.cfg_files = [self.configuration_file]
if os.path.exists(dir_name):
for root, _, walk_files in os.walk(dir_name, followlinks=True):
for found_file in walk_files:
if not re.search(r"\.ini$", found_file):
continue
self.cfg_files.append(os.path.join(root, found_file))
print("Loading configuration files: %s " % self.cfg_files)
# Read and parse the found configuration files
self.config = configparser.ConfigParser()
try:
self.config.read(self.cfg_files)
if self.config._sections == {}:
print("* bad formatted configuration file: %s " % self.configuration_file)
if self.embedded:
raise ValueError
sys.exit(2)
for section in self.config.sections():
if self.verbose:
print("- section: %s" % section)
for (key, value) in self.config.items(section):
inner_property = "%s.%s" % (section, key)
# Set object property
setattr(self, inner_property, value)
# Set environment variable
os.environ[inner_property] = value
if self.verbose:
print(" %s = %s" % (inner_property, value))
if self.export:
# Allowed shell variables may only contain: [a-zA-z0-9_]
inner_property = re.sub('[^0-9a-zA-Z]+', '_', inner_property)
inner_property = inner_property.upper()
print("export %s=%s" % (inner_property, cmd_quote(value)))
except configparser.ParsingError as exp:
print("* parsing error in config file : %s\n%s"
% (self.configuration_file, exp.message))
if self.embedded:
return False
sys.exit(3)
except configparser.InterpolationMissingOptionError as exp:
print("* incorrect or missing variable: %s" % str(exp))
if self.embedded:
return False
sys.exit(3)
if self.verbose:
print("Configuration file parsed correctly")
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_modules; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:name; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:daemon_name; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:names_only; 13, True; 14, block; 14, 15; 14, 17; 14, 48; 14, 116; 15, expression_statement; 15, 16; 16, comment; 17, if_statement; 17, 18; 17, 21; 18, comparison_operator:is; 18, 19; 18, 20; 19, identifier:name; 20, None; 21, block; 21, 22; 21, 33; 21, 46; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:sections; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_search_sections; 29, argument_list; 29, 30; 30, binary_operator:+; 30, 31; 30, 32; 31, string:'module.'; 32, identifier:name; 33, if_statement; 33, 34; 33, 39; 34, comparison_operator:in; 34, 35; 34, 38; 35, binary_operator:+; 35, 36; 35, 37; 36, string:'module.'; 37, identifier:name; 38, identifier:sections; 39, block; 39, 40; 40, return_statement; 40, 41; 41, subscript; 41, 42; 41, 43; 42, identifier:sections; 43, binary_operator:+; 43, 44; 43, 45; 44, string:'module.'; 45, identifier:name; 46, return_statement; 46, 47; 47, dictionary; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:daemon_name; 51, None; 52, block; 52, 53; 52, 62; 52, 114; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:section; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:get_daemons; 60, argument_list; 60, 61; 61, identifier:daemon_name; 62, if_statement; 62, 63; 62, 70; 63, boolean_operator:and; 63, 64; 63, 67; 64, comparison_operator:in; 64, 65; 64, 66; 65, string:'modules'; 66, identifier:section; 67, subscript; 67, 68; 67, 69; 68, identifier:section; 69, string:'modules'; 70, block; 70, 71; 70, 75; 70, 112; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:modules; 74, list:[]; 75, for_statement; 75, 76; 75, 77; 75, 85; 76, identifier:module_name; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:section; 81, string:'modules'; 82, identifier:split; 83, argument_list; 83, 84; 84, string:','; 85, block; 85, 86; 86, if_statement; 86, 87; 86, 88; 86, 96; 87, identifier:names_only; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:modules; 93, identifier:append; 94, argument_list; 94, 95; 95, identifier:module_name; 96, else_clause; 96, 97; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:modules; 102, identifier:append; 103, argument_list; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:get_modules; 108, argument_list; 108, 109; 109, keyword_argument; 109, 110; 109, 111; 110, identifier:name; 111, identifier:module_name; 112, return_statement; 112, 113; 113, identifier:modules; 114, return_statement; 114, 115; 115, list:[]; 116, return_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:_search_sections; 121, argument_list; 121, 122; 122, string:'module.' | def get_modules(self, name=None, daemon_name=None, names_only=True):
"""
Get the modules configuration parameters
If name is provided, get the configuration for this module, else,
If daemon_name is provided, get the configuration for all the modules of this daemon, else
get the configuration of all the modules.
:param name: the searched module name
:param daemon_name: the modules of this daemon
:param names_only: if True only returns the modules names, else all the configuration data
:return: a dict containing the module(s) configuration parameters
"""
if name is not None:
sections = self._search_sections('module.' + name)
if 'module.' + name in sections:
return sections['module.' + name]
return {}
if daemon_name is not None:
section = self.get_daemons(daemon_name)
if 'modules' in section and section['modules']:
modules = []
for module_name in section['modules'].split(','):
if names_only:
modules.append(module_name)
else:
modules.append(self.get_modules(name=module_name))
return modules
return []
return self._search_sections('module.') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:daemon_connection_init; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:s_link; 6, default_parameter; 6, 7; 6, 8; 7, identifier:set_wait_new_conf; 8, False; 9, block; 9, 10; 9, 12; 9, 25; 9, 26; 9, 47; 9, 48; 9, 54; 9, 55; 9, 68; 9, 69; 9, 70; 9, 76; 9, 82; 9, 86; 9, 134; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:logger; 16, identifier:debug; 17, argument_list; 17, 18; 17, 19; 17, 22; 18, string:"Daemon connection initialization: %s %s"; 19, attribute; 19, 20; 19, 21; 20, identifier:s_link; 21, identifier:type; 22, attribute; 22, 23; 22, 24; 23, identifier:s_link; 24, identifier:name; 25, comment; 26, if_statement; 26, 27; 26, 31; 27, not_operator; 27, 28; 28, attribute; 28, 29; 28, 30; 29, identifier:s_link; 30, identifier:active; 31, block; 31, 32; 31, 45; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:logger; 36, identifier:warning; 37, argument_list; 37, 38; 37, 39; 37, 42; 38, string:"%s '%s' is not active, do not initialize its connection!"; 39, attribute; 39, 40; 39, 41; 40, identifier:s_link; 41, identifier:type; 42, attribute; 42, 43; 42, 44; 43, identifier:s_link; 44, identifier:name; 45, return_statement; 45, 46; 46, False; 47, comment; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:s_link; 52, identifier:create_connection; 53, argument_list; 54, comment; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:logger; 59, identifier:debug; 60, argument_list; 60, 61; 60, 62; 60, 65; 61, string:"[%s] Getting running identifier for '%s'"; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:name; 65, attribute; 65, 66; 65, 67; 66, identifier:s_link; 67, identifier:name; 68, comment; 69, comment; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:s_link; 74, identifier:alive; 75, True; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:s_link; 80, identifier:reachable; 81, True; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:got_a_running_id; 85, None; 86, for_statement; 86, 87; 86, 88; 86, 95; 87, identifier:_; 88, call; 88, 89; 88, 90; 89, identifier:range; 90, argument_list; 90, 91; 90, 92; 91, integer:0; 92, attribute; 92, 93; 92, 94; 93, identifier:s_link; 94, identifier:max_check_attempts; 95, block; 95, 96; 95, 104; 95, 127; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:got_a_running_id; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:s_link; 102, identifier:get_running_id; 103, argument_list; 104, if_statement; 104, 105; 104, 106; 105, identifier:got_a_running_id; 106, block; 106, 107; 106, 117; 106, 126; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:s_link; 111, identifier:last_connection; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:time; 115, identifier:time; 116, argument_list; 117, if_statement; 117, 118; 117, 119; 118, identifier:set_wait_new_conf; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:s_link; 124, identifier:wait_new_conf; 125, argument_list; 126, break_statement; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:time; 131, identifier:sleep; 132, argument_list; 132, 133; 133, float:0.3; 134, return_statement; 134, 135; 135, identifier:got_a_running_id | def daemon_connection_init(self, s_link, set_wait_new_conf=False):
"""Initialize a connection with the daemon for the provided satellite link
Initialize the connection (HTTP client) to the daemon and get its running identifier.
Returns True if it succeeds else if any error occur or the daemon is inactive
it returns False.
Assume the daemon should be reachable because we are initializing the connection...
as such, force set the link reachable property
If set_wait_new_conf is set, the daemon is requested to wait a new configuration if
we get a running identifier. This is used by the arbiter when a new configuration
must be dispatched
NB: if the daemon is configured as passive, or if it is a daemon link that is
inactive then it returns False without trying a connection.
:param s_link: link of the daemon to connect to
:type s_link: SatelliteLink
:param set_wait_new_conf: if the daemon must got the wait new configuration state
:type set_wait_new_conf: bool
:return: True if the connection is established, else False
"""
logger.debug("Daemon connection initialization: %s %s", s_link.type, s_link.name)
# If the link is not not active, I do not try to initialize the connection, just useless ;)
if not s_link.active:
logger.warning("%s '%s' is not active, do not initialize its connection!",
s_link.type, s_link.name)
return False
# Create the daemon connection
s_link.create_connection()
# Get the connection running identifier - first client / server communication
logger.debug("[%s] Getting running identifier for '%s'", self.name, s_link.name)
# Assume the daemon should be alive and reachable
# because we are initializing the connection...
s_link.alive = True
s_link.reachable = True
got_a_running_id = None
for _ in range(0, s_link.max_check_attempts):
got_a_running_id = s_link.get_running_id()
if got_a_running_id:
s_link.last_connection = time.time()
if set_wait_new_conf:
s_link.wait_new_conf()
break
time.sleep(0.3)
return got_a_running_id |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:do_daemon_init_and_start; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:set_proc_title; 7, True; 8, block; 8, 9; 8, 11; 8, 23; 8, 24; 8, 30; 8, 31; 8, 37; 8, 38; 8, 44; 8, 45; 8, 81; 8, 82; 8, 83; 8, 84; 8, 85; 8, 86; 8, 87; 8, 88; 8, 89; 8, 90; 8, 91; 8, 92; 8, 93; 8, 94; 8, 95; 8, 96; 8, 97; 8, 103; 8, 104; 8, 121; 8, 122; 8, 132; 8, 133; 8, 140; 8, 141; 8, 163; 8, 164; 8, 172; 8, 180; 8, 181; 8, 188; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 13; 12, identifier:set_proc_title; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:set_proctitle; 19, argument_list; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:name; 23, comment; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:change_to_user_group; 29, argument_list; 30, comment; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:change_to_workdir; 36, argument_list; 37, comment; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:check_parallel_run; 43, argument_list; 44, comment; 45, if_statement; 45, 46; 45, 49; 45, 67; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:is_daemon; 49, block; 49, 50; 50, if_statement; 50, 51; 50, 57; 51, not_operator; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:daemonize; 56, argument_list; 57, block; 57, 58; 57, 65; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:logger; 62, identifier:error; 63, argument_list; 63, 64; 64, string:"I could not daemonize myself :("; 65, return_statement; 65, 66; 66, False; 67, else_clause; 67, 68; 67, 69; 68, comment; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:write_pid; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:os; 79, identifier:getpid; 80, argument_list; 81, comment; 82, comment; 83, comment; 84, comment; 85, comment; 86, comment; 87, comment; 88, comment; 89, comment; 90, comment; 91, comment; 92, comment; 93, comment; 94, comment; 95, comment; 96, comment; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:setup_alignak_logger; 102, argument_list; 103, comment; 104, if_statement; 104, 105; 104, 111; 105, not_operator; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:setup_communication_daemon; 110, argument_list; 111, block; 111, 112; 111, 119; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:logger; 116, identifier:error; 117, argument_list; 117, 118; 118, string:"I could not setup my communication daemon :("; 119, return_statement; 119, 120; 120, False; 121, comment; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:sync_manager; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:_create_manager; 131, argument_list; 132, comment; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:logger; 137, identifier:info; 138, argument_list; 138, 139; 139, string:"Starting http_daemon thread"; 140, comment; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:http_thread; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:threading; 149, identifier:Thread; 150, argument_list; 150, 151; 150, 156; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:target; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:http_daemon_thread; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:name; 158, binary_operator:%; 158, 159; 158, 160; 159, string:'%s-http_thread'; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:name; 163, comment; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:http_thread; 170, identifier:daemon; 171, True; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 179; 174, attribute; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:http_thread; 178, identifier:start; 179, argument_list; 180, comment; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:logger; 185, identifier:info; 186, argument_list; 186, 187; 187, string:"HTTP daemon thread started"; 188, return_statement; 188, 189; 189, True | def do_daemon_init_and_start(self, set_proc_title=True):
"""Main daemon function.
Clean, allocates, initializes and starts all necessary resources to go in daemon mode.
The set_proc_title parameter is mainly useful for the Alignak unit tests.
This to avoid changing the test process name!
:param set_proc_title: if set (default), the process title is changed to the daemon name
:type set_proc_title: bool
:return: False if the HTTP daemon can not be initialized, else True
"""
if set_proc_title:
self.set_proctitle(self.name)
# Change to configured user/group account
self.change_to_user_group()
# Change the working directory
self.change_to_workdir()
# Check if I am still running
self.check_parallel_run()
# If we must daemonize, let's do it!
if self.is_daemon:
if not self.daemonize():
logger.error("I could not daemonize myself :(")
return False
else:
# Else, I set my own pid as the reference one
self.write_pid(os.getpid())
# # TODO: check if really necessary!
# # -------
# # Set ownership on some default log files. It may happen that these default
# # files are owned by a privileged user account
# try:
# for log_file in ['alignak.log', 'alignak-events.log']:
# if os.path.exists('/tmp/%s' % log_file):
# with open('/tmp/%s' % log_file, "w") as file_log_file:
# os.fchown(file_log_file.fileno(), self.uid, self.gid)
# if os.path.exists('/tmp/monitoring-log/%s' % log_file):
# with open('/tmp/monitoring-log/%s' % log_file, "w") as file_log_file:
# os.fchown(file_log_file.fileno(), self.uid, self.gid)
# except Exception as exp: # pylint: disable=broad-except
# # pragma: no cover
# print("Could not set default log files ownership, exception: %s" % str(exp))
# Configure the daemon logger
self.setup_alignak_logger()
# Setup the Web Services daemon
if not self.setup_communication_daemon():
logger.error("I could not setup my communication daemon :(")
return False
# Creating synchonisation manager (inter-daemon queues...)
self.sync_manager = self._create_manager()
# Start the CherryPy server through a detached thread
logger.info("Starting http_daemon thread")
# pylint: disable=bad-thread-instantiation
self.http_thread = threading.Thread(target=self.http_daemon_thread,
name='%s-http_thread' % self.name)
# Setting the thread as a daemon allows to Ctrl+C to kill the main daemon
self.http_thread.daemon = True
self.http_thread.start()
# time.sleep(1)
logger.info("HTTP daemon thread started")
return True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:make_a_pause; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:timeout; 7, float:0.0001; 8, default_parameter; 8, 9; 8, 10; 9, identifier:check_time_change; 10, True; 11, block; 11, 12; 11, 14; 11, 23; 11, 45; 11, 46; 11, 54; 11, 62; 11, 70; 11, 76; 11, 85; 11, 86; 11, 95; 11, 96; 11, 100; 11, 112; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 18; 15, comparison_operator:==; 15, 16; 15, 17; 16, identifier:timeout; 17, integer:0; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:timeout; 22, float:0.0001; 23, if_statement; 23, 24; 23, 26; 23, 27; 24, not_operator; 24, 25; 25, identifier:check_time_change; 26, comment; 27, block; 27, 28; 27, 35; 27, 41; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:time; 32, identifier:sleep; 33, argument_list; 33, 34; 34, identifier:timeout; 35, expression_statement; 35, 36; 36, augmented_assignment:+=; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:sleep_time; 40, identifier:timeout; 41, return_statement; 41, 42; 42, expression_list; 42, 43; 42, 44; 43, integer:0; 44, integer:0; 45, comment; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:before; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:time; 52, identifier:time; 53, argument_list; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:time_changed; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:check_for_system_time_change; 61, argument_list; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:after; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:time; 68, identifier:time; 69, argument_list; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:elapsed; 73, binary_operator:-; 73, 74; 73, 75; 74, identifier:after; 75, identifier:before; 76, if_statement; 76, 77; 76, 80; 77, comparison_operator:>; 77, 78; 77, 79; 78, identifier:elapsed; 79, identifier:timeout; 80, block; 80, 81; 81, return_statement; 81, 82; 82, expression_list; 82, 83; 82, 84; 83, identifier:elapsed; 84, identifier:time_changed; 85, comment; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:time; 90, identifier:sleep; 91, argument_list; 91, 92; 92, binary_operator:-; 92, 93; 92, 94; 93, identifier:timeout; 94, identifier:elapsed; 95, comment; 96, expression_statement; 96, 97; 97, augmented_assignment:+=; 97, 98; 97, 99; 98, identifier:before; 99, identifier:time_changed; 100, expression_statement; 100, 101; 101, augmented_assignment:+=; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:sleep_time; 105, binary_operator:-; 105, 106; 105, 111; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:time; 109, identifier:time; 110, argument_list; 111, identifier:before; 112, return_statement; 112, 113; 113, expression_list; 113, 114; 113, 115; 114, identifier:elapsed; 115, identifier:time_changed | def make_a_pause(self, timeout=0.0001, check_time_change=True):
""" Wait up to timeout and check for system time change.
This function checks if the system time changed since the last call. If so,
the difference is returned to the caller.
The duration of this call is removed from the timeout. If this duration is
greater than the required timeout, no sleep is executed and the extra time
is returned to the caller
If the required timeout was overlapped, then the first return value will be
greater than the required timeout.
If the required timeout is null, then the timeout value is set as a very short time
to keep a nice behavior to the system CPU ;)
:param timeout: timeout to wait for activity
:type timeout: float
:param check_time_change: True (default) to check if the system time changed
:type check_time_change: bool
:return:Returns a 2-tuple:
* first value is the time spent for the time change check
* second value is the time change difference
:rtype: tuple
"""
if timeout == 0:
timeout = 0.0001
if not check_time_change:
# Time to sleep
time.sleep(timeout)
self.sleep_time += timeout
return 0, 0
# Check is system time changed
before = time.time()
time_changed = self.check_for_system_time_change()
after = time.time()
elapsed = after - before
if elapsed > timeout:
return elapsed, time_changed
# Time to sleep
time.sleep(timeout - elapsed)
# Increase our sleep time for the time we slept
before += time_changed
self.sleep_time += time.time() - before
return elapsed, time_changed |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 1, 8; 2, function_name:explode_hostgroup; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:svc_dep; 6, identifier:hostgroups; 7, comment; 8, block; 8, 9; 8, 11; 8, 12; 8, 13; 8, 32; 8, 33; 8, 52; 8, 53; 8, 72; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:snames; 16, list_comprehension; 16, 17; 16, 22; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:d; 20, identifier:strip; 21, argument_list; 22, for_in_clause; 22, 23; 22, 24; 23, identifier:d; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:svc_dep; 28, identifier:service_description; 29, identifier:split; 30, argument_list; 30, 31; 31, string:','; 32, comment; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:dep_snames; 36, list_comprehension; 36, 37; 36, 42; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:d; 40, identifier:strip; 41, argument_list; 42, for_in_clause; 42, 43; 42, 44; 43, identifier:d; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:svc_dep; 48, identifier:dependent_service_description; 49, identifier:split; 50, argument_list; 50, 51; 51, string:','; 52, comment; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:hg_names; 56, list_comprehension; 56, 57; 56, 62; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:n; 60, identifier:strip; 61, argument_list; 62, for_in_clause; 62, 63; 62, 64; 63, identifier:n; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:svc_dep; 68, identifier:hostgroup_name; 69, identifier:split; 70, argument_list; 70, 71; 71, string:','; 72, for_statement; 72, 73; 72, 74; 72, 75; 73, identifier:hg_name; 74, identifier:hg_names; 75, block; 75, 76; 75, 85; 75, 104; 75, 108; 75, 127; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:hostgroup; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:hostgroups; 82, identifier:find_by_name; 83, argument_list; 83, 84; 84, identifier:hg_name; 85, if_statement; 85, 86; 85, 89; 86, comparison_operator:is; 86, 87; 86, 88; 87, identifier:hostgroup; 88, None; 89, block; 89, 90; 89, 96; 89, 103; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:err; 93, binary_operator:%; 93, 94; 93, 95; 94, string:"ERROR: the servicedependecy got an unknown hostgroup_name '%s'"; 95, identifier:hg_name; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:add_error; 101, argument_list; 101, 102; 102, identifier:err; 103, continue_statement; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:hnames; 107, list:[]; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:hnames; 112, identifier:extend; 113, argument_list; 113, 114; 114, list_comprehension; 114, 115; 114, 120; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:m; 118, identifier:strip; 119, argument_list; 120, for_in_clause; 120, 121; 120, 122; 121, identifier:m; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:hostgroup; 125, identifier:get_hosts; 126, argument_list; 127, for_statement; 127, 128; 127, 129; 127, 130; 128, identifier:hname; 129, identifier:hnames; 130, block; 130, 131; 131, for_statement; 131, 132; 131, 133; 131, 134; 132, identifier:dep_sname; 133, identifier:dep_snames; 134, block; 134, 135; 135, for_statement; 135, 136; 135, 137; 135, 138; 136, identifier:sname; 137, identifier:snames; 138, block; 138, 139; 138, 147; 138, 153; 138, 159; 138, 165; 138, 171; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:new_sd; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:svc_dep; 145, identifier:copy; 146, argument_list; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:new_sd; 151, identifier:host_name; 152, identifier:hname; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:new_sd; 157, identifier:service_description; 158, identifier:sname; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:new_sd; 163, identifier:dependent_host_name; 164, identifier:hname; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:new_sd; 169, identifier:dependent_service_description; 170, identifier:dep_sname; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:add_item; 176, argument_list; 176, 177; 177, identifier:new_sd | def explode_hostgroup(self, svc_dep, hostgroups):
# pylint: disable=too-many-locals
"""Explode a service dependency for each member of hostgroup
:param svc_dep: service dependency to explode
:type svc_dep: alignak.objects.servicedependency.Servicedependency
:param hostgroups: used to find hostgroup objects
:type hostgroups: alignak.objects.hostgroup.Hostgroups
:return:None
"""
# We will create a service dependency for each host part of the host group
# First get services
snames = [d.strip() for d in svc_dep.service_description.split(',')]
# And dep services
dep_snames = [d.strip() for d in svc_dep.dependent_service_description.split(',')]
# Now for each host into hostgroup we will create a service dependency object
hg_names = [n.strip() for n in svc_dep.hostgroup_name.split(',')]
for hg_name in hg_names:
hostgroup = hostgroups.find_by_name(hg_name)
if hostgroup is None:
err = "ERROR: the servicedependecy got an unknown hostgroup_name '%s'" % hg_name
self.add_error(err)
continue
hnames = []
hnames.extend([m.strip() for m in hostgroup.get_hosts()])
for hname in hnames:
for dep_sname in dep_snames:
for sname in snames:
new_sd = svc_dep.copy()
new_sd.host_name = hname
new_sd.service_description = sname
new_sd.dependent_host_name = hname
new_sd.dependent_service_description = dep_sname
self.add_item(new_sd) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:linkify_sd_by_s; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:hosts; 6, identifier:services; 7, block; 7, 8; 7, 10; 7, 14; 7, 20; 7, 26; 7, 238; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:to_del; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:errors; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:configuration_errors; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:warns; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:configuration_warnings; 26, for_statement; 26, 27; 26, 28; 26, 29; 27, identifier:servicedep; 28, identifier:self; 29, block; 29, 30; 30, try_statement; 30, 31; 30, 216; 31, block; 31, 32; 31, 38; 31, 44; 31, 45; 31, 55; 31, 116; 31, 124; 31, 130; 31, 136; 31, 137; 31, 147; 31, 208; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:s_name; 35, attribute; 35, 36; 35, 37; 36, identifier:servicedep; 37, identifier:dependent_service_description; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:hst_name; 41, attribute; 41, 42; 41, 43; 42, identifier:servicedep; 43, identifier:dependent_host_name; 44, comment; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:serv; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:services; 51, identifier:find_srv_by_name_and_hostname; 52, argument_list; 52, 53; 52, 54; 53, identifier:hst_name; 54, identifier:s_name; 55, if_statement; 55, 56; 55, 59; 56, comparison_operator:is; 56, 57; 56, 58; 57, identifier:serv; 58, None; 59, block; 59, 60; 59, 69; 59, 108; 59, 115; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:host; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:hosts; 66, identifier:find_by_name; 67, argument_list; 67, 68; 68, identifier:hst_name; 69, if_statement; 69, 70; 69, 80; 69, 92; 70, not_operator; 70, 71; 71, parenthesized_expression; 71, 72; 72, boolean_operator:and; 72, 73; 72, 74; 73, identifier:host; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:host; 77, identifier:is_excluded_for_sdesc; 78, argument_list; 78, 79; 79, identifier:s_name; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:errors; 85, identifier:append; 86, argument_list; 86, 87; 87, binary_operator:%; 87, 88; 87, 89; 88, string:"Service %s not found for host %s"; 89, tuple; 89, 90; 89, 91; 90, identifier:s_name; 91, identifier:hst_name; 92, elif_clause; 92, 93; 92, 94; 93, identifier:host; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:warns; 99, identifier:append; 100, argument_list; 100, 101; 101, binary_operator:%; 101, 102; 101, 105; 102, concatenated_string; 102, 103; 102, 104; 103, string:"Service %s is excluded from host %s ; "; 104, string:"removing this servicedependency as it's unusuable."; 105, tuple; 105, 106; 105, 107; 106, identifier:s_name; 107, identifier:hst_name; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:to_del; 112, identifier:append; 113, argument_list; 113, 114; 114, identifier:servicedep; 115, continue_statement; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:servicedep; 120, identifier:dependent_service_description; 121, attribute; 121, 122; 121, 123; 122, identifier:serv; 123, identifier:uuid; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:s_name; 127, attribute; 127, 128; 127, 129; 128, identifier:servicedep; 129, identifier:service_description; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:hst_name; 133, attribute; 133, 134; 133, 135; 134, identifier:servicedep; 135, identifier:host_name; 136, comment; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:serv; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:services; 143, identifier:find_srv_by_name_and_hostname; 144, argument_list; 144, 145; 144, 146; 145, identifier:hst_name; 146, identifier:s_name; 147, if_statement; 147, 148; 147, 151; 148, comparison_operator:is; 148, 149; 148, 150; 149, identifier:serv; 150, None; 151, block; 151, 152; 151, 161; 151, 200; 151, 207; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:host; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:hosts; 158, identifier:find_by_name; 159, argument_list; 159, 160; 160, identifier:hst_name; 161, if_statement; 161, 162; 161, 172; 161, 184; 162, not_operator; 162, 163; 163, parenthesized_expression; 163, 164; 164, boolean_operator:and; 164, 165; 164, 166; 165, identifier:host; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:host; 169, identifier:is_excluded_for_sdesc; 170, argument_list; 170, 171; 171, identifier:s_name; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:errors; 177, identifier:append; 178, argument_list; 178, 179; 179, binary_operator:%; 179, 180; 179, 181; 180, string:"Service %s not found for host %s"; 181, tuple; 181, 182; 181, 183; 182, identifier:s_name; 183, identifier:hst_name; 184, elif_clause; 184, 185; 184, 186; 185, identifier:host; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:warns; 191, identifier:append; 192, argument_list; 192, 193; 193, binary_operator:%; 193, 194; 193, 197; 194, concatenated_string; 194, 195; 194, 196; 195, string:"Service %s is excluded from host %s ; "; 196, string:"removing this servicedependency as it's unusuable."; 197, tuple; 197, 198; 197, 199; 198, identifier:s_name; 199, identifier:hst_name; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:to_del; 204, identifier:append; 205, argument_list; 205, 206; 206, identifier:servicedep; 207, continue_statement; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:servicedep; 212, identifier:service_description; 213, attribute; 213, 214; 213, 215; 214, identifier:serv; 215, identifier:uuid; 216, except_clause; 216, 217; 216, 221; 217, as_pattern; 217, 218; 217, 219; 218, identifier:AttributeError; 219, as_pattern_target; 219, 220; 220, identifier:err; 221, block; 221, 222; 221, 231; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:logger; 226, identifier:error; 227, argument_list; 227, 228; 227, 229; 227, 230; 228, string:"[servicedependency] fail to linkify by service %s: %s"; 229, identifier:servicedep; 230, identifier:err; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:to_del; 235, identifier:append; 236, argument_list; 236, 237; 237, identifier:servicedep; 238, for_statement; 238, 239; 238, 240; 238, 241; 239, identifier:servicedep; 240, identifier:to_del; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:remove_item; 247, argument_list; 247, 248; 248, identifier:servicedep | def linkify_sd_by_s(self, hosts, services):
"""Replace dependent_service_description and service_description
in service dependency by the real object
:param hosts: host list, used to look for a specific one
:type hosts: alignak.objects.host.Hosts
:param services: service list to look for a specific one
:type services: alignak.objects.service.Services
:return: None
"""
to_del = []
errors = self.configuration_errors
warns = self.configuration_warnings
for servicedep in self:
try:
s_name = servicedep.dependent_service_description
hst_name = servicedep.dependent_host_name
# The new member list, in id
serv = services.find_srv_by_name_and_hostname(hst_name, s_name)
if serv is None:
host = hosts.find_by_name(hst_name)
if not (host and host.is_excluded_for_sdesc(s_name)):
errors.append("Service %s not found for host %s" % (s_name, hst_name))
elif host:
warns.append("Service %s is excluded from host %s ; "
"removing this servicedependency as it's unusuable."
% (s_name, hst_name))
to_del.append(servicedep)
continue
servicedep.dependent_service_description = serv.uuid
s_name = servicedep.service_description
hst_name = servicedep.host_name
# The new member list, in id
serv = services.find_srv_by_name_and_hostname(hst_name, s_name)
if serv is None:
host = hosts.find_by_name(hst_name)
if not (host and host.is_excluded_for_sdesc(s_name)):
errors.append("Service %s not found for host %s" % (s_name, hst_name))
elif host:
warns.append("Service %s is excluded from host %s ; "
"removing this servicedependency as it's unusuable."
% (s_name, hst_name))
to_del.append(servicedep)
continue
servicedep.service_description = serv.uuid
except AttributeError as err:
logger.error("[servicedependency] fail to linkify by service %s: %s",
servicedep, err)
to_del.append(servicedep)
for servicedep in to_del:
self.remove_item(servicedep) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 2, function_name:init; 3, parameters; 3, 4; 4, identifier:self; 5, comment; 6, block; 6, 7; 6, 9; 6, 24; 6, 52; 6, 302; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 14; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:enabled; 14, block; 14, 15; 14, 22; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logger; 19, identifier:info; 20, argument_list; 20, 21; 21, string:" the module is disabled."; 22, return_statement; 22, 23; 23, True; 24, try_statement; 24, 25; 24, 34; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:connections; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:test_connection; 33, argument_list; 34, except_clause; 34, 35; 34, 39; 34, 40; 35, as_pattern; 35, 36; 35, 37; 36, identifier:Exception; 37, as_pattern_target; 37, 38; 38, identifier:exp; 39, comment; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:logger; 45, identifier:error; 46, argument_list; 46, 47; 46, 48; 47, string:"initialization, test connection failed. Error: %s"; 48, call; 48, 49; 48, 50; 49, identifier:str; 50, argument_list; 50, 51; 51, identifier:exp; 52, if_statement; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:influxdb_enabled; 56, block; 56, 57; 57, try_statement; 57, 58; 57, 59; 57, 284; 58, comment; 59, block; 59, 60; 59, 70; 59, 121; 59, 122; 59, 205; 59, 206; 59, 278; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:dbs; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:influx; 68, identifier:get_list_database; 69, argument_list; 70, for_statement; 70, 71; 70, 72; 70, 73; 70, 97; 71, identifier:db; 72, identifier:dbs; 73, block; 73, 74; 74, if_statement; 74, 75; 74, 85; 75, comparison_operator:==; 75, 76; 75, 82; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:db; 79, identifier:get; 80, argument_list; 80, 81; 81, string:'name'; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:influxdb_database; 85, block; 85, 86; 85, 96; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:logger; 90, identifier:info; 91, argument_list; 91, 92; 91, 93; 92, string:"the database %s is existing."; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:influxdb_database; 96, break_statement; 97, else_clause; 97, 98; 97, 99; 98, comment; 99, block; 99, 100; 99, 110; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:logger; 104, identifier:info; 105, argument_list; 105, 106; 105, 107; 106, string:"creating database %s..."; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:influxdb_database; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:influx; 116, identifier:create_database; 117, argument_list; 117, 118; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:influxdb_database; 121, comment; 122, if_statement; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:influxdb_retention_name; 126, block; 126, 127; 126, 137; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:rps; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:influx; 135, identifier:get_list_retention_policies; 136, argument_list; 137, for_statement; 137, 138; 137, 139; 137, 140; 137, 164; 138, identifier:rp; 139, identifier:rps; 140, block; 140, 141; 141, if_statement; 141, 142; 141, 152; 142, comparison_operator:==; 142, 143; 142, 149; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:rp; 146, identifier:get; 147, argument_list; 147, 148; 148, string:'name'; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:influxdb_retention_name; 152, block; 152, 153; 152, 163; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:logger; 157, identifier:info; 158, argument_list; 158, 159; 158, 160; 159, string:"the retention policy %s is existing."; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:influxdb_retention_name; 163, break_statement; 164, else_clause; 164, 165; 164, 166; 165, comment; 166, block; 166, 167; 166, 183; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:logger; 171, identifier:info; 172, argument_list; 172, 173; 172, 174; 172, 177; 172, 180; 173, string:"creating database retention policy: %s - %s - %s..."; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:influxdb_retention_name; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:influxdb_retention_duration; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:influxdb_retention_replication; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:influx; 189, identifier:create_retention_policy; 190, argument_list; 190, 191; 190, 194; 190, 197; 190, 200; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:influxdb_retention_name; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:influxdb_retention_duration; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:influxdb_retention_replication; 200, keyword_argument; 200, 201; 200, 202; 201, identifier:database; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:influxdb_database; 205, comment; 206, if_statement; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:influxdb_username; 210, block; 210, 211; 210, 221; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:users; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:influx; 219, identifier:get_list_users; 220, argument_list; 221, for_statement; 221, 222; 221, 223; 221, 224; 221, 248; 222, identifier:user; 223, identifier:users; 224, block; 224, 225; 225, if_statement; 225, 226; 225, 236; 226, comparison_operator:==; 226, 227; 226, 233; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:user; 230, identifier:get; 231, argument_list; 231, 232; 232, string:'user'; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:influxdb_username; 236, block; 236, 237; 236, 247; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:logger; 241, identifier:info; 242, argument_list; 242, 243; 242, 244; 243, string:"the user %s is existing."; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:influxdb_username; 247, break_statement; 248, else_clause; 248, 249; 248, 250; 249, comment; 250, block; 250, 251; 250, 261; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:logger; 255, identifier:info; 256, argument_list; 256, 257; 256, 258; 257, string:"creating user: %s..."; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:influxdb_username; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 268; 263, attribute; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:influx; 267, identifier:create_user; 268, argument_list; 268, 269; 268, 272; 268, 275; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:influxdb_username; 272, attribute; 272, 273; 272, 274; 273, identifier:self; 274, identifier:influxdb_password; 275, keyword_argument; 275, 276; 275, 277; 276, identifier:admin; 277, False; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:connections; 281, boolean_operator:or; 281, 282; 281, 283; 282, identifier:connections; 283, True; 284, except_clause; 284, 285; 284, 289; 284, 290; 285, as_pattern; 285, 286; 285, 287; 286, identifier:Exception; 287, as_pattern_target; 287, 288; 288, identifier:exp; 289, comment; 290, block; 290, 291; 291, expression_statement; 291, 292; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:logger; 295, identifier:error; 296, argument_list; 296, 297; 296, 298; 297, string:"InfluxDB, DB initialization failed. Error: %s"; 298, call; 298, 299; 298, 300; 299, identifier:str; 300, argument_list; 300, 301; 301, identifier:exp; 302, return_statement; 302, 303; 303, identifier:connections | def init(self): # pylint: disable=too-many-branches
"""Called by the daemon broker to initialize the module"""
if not self.enabled:
logger.info(" the module is disabled.")
return True
try:
connections = self.test_connection()
except Exception as exp: # pylint: disable=broad-except
logger.error("initialization, test connection failed. Error: %s", str(exp))
if self.influxdb_enabled:
try:
# Check that configured TSDB is existing, else creates...
dbs = self.influx.get_list_database()
for db in dbs:
if db.get('name') == self.influxdb_database:
logger.info("the database %s is existing.", self.influxdb_database)
break
else:
# Create the database
logger.info("creating database %s...", self.influxdb_database)
self.influx.create_database(self.influxdb_database)
# Check that configured TSDB retention is existing, else creates...
if self.influxdb_retention_name:
rps = self.influx.get_list_retention_policies()
for rp in rps:
if rp.get('name') == self.influxdb_retention_name:
logger.info("the retention policy %s is existing.",
self.influxdb_retention_name)
break
else:
# Create a retention policy for this database
logger.info("creating database retention policy: %s - %s - %s...",
self.influxdb_retention_name, self.influxdb_retention_duration,
self.influxdb_retention_replication)
self.influx.create_retention_policy(
self.influxdb_retention_name, self.influxdb_retention_duration,
self.influxdb_retention_replication, database=self.influxdb_database)
# Check that configured TSDB user is existing, else creates...
if self.influxdb_username:
users = self.influx.get_list_users()
for user in users:
if user.get('user') == self.influxdb_username:
logger.info("the user %s is existing.",
self.influxdb_username)
break
else:
# Create a retention policy for this database
logger.info("creating user: %s...", self.influxdb_username)
self.influx.create_user(self.influxdb_username, self.influxdb_password,
admin=False)
connections = connections or True
except Exception as exp: # pylint: disable=broad-except
logger.error("InfluxDB, DB initialization failed. Error: %s", str(exp))
return connections |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:get_metrics_from_perfdata; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:service; 6, identifier:perf_data; 7, block; 7, 8; 7, 10; 7, 14; 7, 21; 7, 193; 7, 202; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:result; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:metrics; 17, call; 17, 18; 17, 19; 18, identifier:PerfDatas; 19, argument_list; 19, 20; 20, identifier:perf_data; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:metric; 23, identifier:metrics; 24, block; 24, 25; 24, 37; 24, 51; 24, 60; 24, 72; 24, 77; 24, 78; 24, 94; 24, 95; 24, 114; 24, 133; 24, 152; 24, 171; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:logger; 29, identifier:debug; 30, argument_list; 30, 31; 30, 32; 30, 33; 30, 34; 31, string:"service: %s, metric: %s (%s)"; 32, identifier:service; 33, identifier:metric; 34, attribute; 34, 35; 34, 36; 35, identifier:metric; 36, identifier:__dict__; 37, if_statement; 37, 38; 37, 44; 38, comparison_operator:in; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:metric; 41, identifier:name; 42, list:['time']; 42, 43; 43, string:'time'; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:metric; 49, identifier:name; 50, string:"duration"; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:name; 54, call; 54, 55; 54, 56; 55, identifier:sanitize_name; 56, argument_list; 56, 57; 57, attribute; 57, 58; 57, 59; 58, identifier:metric; 59, identifier:name; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:name; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:multiple_values; 68, identifier:sub; 69, argument_list; 69, 70; 69, 71; 70, string:r'.\1'; 71, identifier:name; 72, if_statement; 72, 73; 72, 75; 73, not_operator; 73, 74; 74, identifier:name; 75, block; 75, 76; 76, continue_statement; 77, comment; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:name_value; 81, dictionary; 81, 82; 81, 87; 82, pair; 82, 83; 82, 84; 83, identifier:name; 84, attribute; 84, 85; 84, 86; 85, identifier:metric; 86, identifier:value; 87, pair; 87, 88; 87, 91; 88, binary_operator:+; 88, 89; 88, 90; 89, string:'uom_'; 90, identifier:name; 91, attribute; 91, 92; 91, 93; 92, identifier:metric; 93, identifier:uom; 94, comment; 95, if_statement; 95, 96; 95, 103; 96, boolean_operator:and; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:metric; 99, identifier:warning; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:send_warning; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 111; 106, subscript; 106, 107; 106, 108; 107, identifier:name_value; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:name; 110, string:'_warn'; 111, attribute; 111, 112; 111, 113; 112, identifier:metric; 113, identifier:warning; 114, if_statement; 114, 115; 114, 122; 115, boolean_operator:and; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:metric; 118, identifier:critical; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:send_critical; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 130; 125, subscript; 125, 126; 125, 127; 126, identifier:name_value; 127, binary_operator:+; 127, 128; 127, 129; 128, identifier:name; 129, string:'_crit'; 130, attribute; 130, 131; 130, 132; 131, identifier:metric; 132, identifier:critical; 133, if_statement; 133, 134; 133, 141; 134, boolean_operator:and; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:metric; 137, identifier:min; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:send_min; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 146; 145, identifier:name_value; 146, binary_operator:+; 146, 147; 146, 148; 147, identifier:name; 148, string:'_min'; 149, attribute; 149, 150; 149, 151; 150, identifier:metric; 151, identifier:min; 152, if_statement; 152, 153; 152, 160; 153, boolean_operator:and; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:metric; 156, identifier:max; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:send_max; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 168; 163, subscript; 163, 164; 163, 165; 164, identifier:name_value; 165, binary_operator:+; 165, 166; 165, 167; 166, identifier:name; 167, string:'_max'; 168, attribute; 168, 169; 168, 170; 169, identifier:metric; 170, identifier:max; 171, for_statement; 171, 172; 171, 175; 171, 180; 172, pattern_list; 172, 173; 172, 174; 173, identifier:key; 174, identifier:value; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:name_value; 178, identifier:items; 179, argument_list; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:result; 185, identifier:append; 186, argument_list; 186, 187; 187, tuple; 187, 188; 187, 189; 187, 190; 188, identifier:key; 189, identifier:value; 190, attribute; 190, 191; 190, 192; 191, identifier:metric; 192, identifier:uom; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:logger; 197, identifier:debug; 198, argument_list; 198, 199; 198, 200; 198, 201; 199, string:"Metrics: %s - %s"; 200, identifier:service; 201, identifier:result; 202, return_statement; 202, 203; 203, identifier:result | def get_metrics_from_perfdata(self, service, perf_data):
"""Decode the performance data to build a metrics list"""
result = []
metrics = PerfDatas(perf_data)
for metric in metrics:
logger.debug("service: %s, metric: %s (%s)", service, metric, metric.__dict__)
if metric.name in ['time']:
metric.name = "duration"
name = sanitize_name(metric.name)
name = self.multiple_values.sub(r'.\1', name)
if not name:
continue
# get metric value and its thresholds values if they exist
name_value = {
name: metric.value,
'uom_' + name: metric.uom
}
# Get or ignore extra values depending upon module configuration
if metric.warning and self.send_warning:
name_value[name + '_warn'] = metric.warning
if metric.critical and self.send_critical:
name_value[name + '_crit'] = metric.critical
if metric.min and self.send_min:
name_value[name + '_min'] = metric.min
if metric.max and self.send_max:
name_value[name + '_max'] = metric.max
for key, value in name_value.items():
result.append((key, value, metric.uom))
logger.debug("Metrics: %s - %s", service, result)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:manage_service_check_result_brok; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:b; 6, comment; 7, block; 7, 8; 7, 10; 7, 22; 7, 34; 7, 42; 7, 50; 7, 58; 7, 59; 7, 80; 7, 101; 7, 102; 7, 116; 7, 128; 7, 129; 7, 174; 7, 175; 7, 182; 7, 255; 7, 256; 7, 263; 7, 304; 7, 305; 7, 337; 7, 338; 7, 375; 7, 379; 7, 400; 7, 401; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:host_name; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:b; 17, identifier:data; 18, identifier:get; 19, argument_list; 19, 20; 19, 21; 20, string:'host_name'; 21, None; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:service_description; 25, call; 25, 26; 25, 31; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:b; 29, identifier:data; 30, identifier:get; 31, argument_list; 31, 32; 31, 33; 32, string:'service_description'; 33, None; 34, if_statement; 34, 35; 34, 40; 35, boolean_operator:or; 35, 36; 35, 38; 36, not_operator; 36, 37; 37, identifier:host_name; 38, not_operator; 38, 39; 39, identifier:service_description; 40, block; 40, 41; 41, return_statement; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:service_id; 45, binary_operator:+; 45, 46; 45, 49; 46, binary_operator:+; 46, 47; 46, 48; 47, identifier:host_name; 48, string:"/"; 49, identifier:service_description; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:logger; 54, identifier:debug; 55, argument_list; 55, 56; 55, 57; 56, string:"service check result: %s"; 57, identifier:service_id; 58, comment; 59, if_statement; 59, 60; 59, 70; 60, boolean_operator:and; 60, 61; 60, 65; 61, not_operator; 61, 62; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:ignore_unknown; 65, comparison_operator:not; 65, 66; 65, 67; 66, identifier:host_name; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:hosts_cache; 70, block; 70, 71; 70, 79; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:logger; 75, identifier:warning; 76, argument_list; 76, 77; 76, 78; 77, string:"received service check result for an unknown host: %s"; 78, identifier:service_id; 79, return_statement; 80, if_statement; 80, 81; 80, 91; 81, boolean_operator:and; 81, 82; 81, 87; 82, comparison_operator:not; 82, 83; 82, 84; 83, identifier:service_id; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:services_cache; 87, not_operator; 87, 88; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:ignore_unknown; 91, block; 91, 92; 91, 100; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:logger; 96, identifier:warning; 97, argument_list; 97, 98; 97, 99; 98, string:"received service check result for an unknown service: %s"; 99, identifier:service_id; 100, return_statement; 101, comment; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:metrics; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:get_metrics_from_perfdata; 109, argument_list; 109, 110; 109, 111; 110, identifier:service_description; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:b; 114, identifier:data; 115, string:'perf_data'; 116, if_statement; 116, 117; 116, 119; 117, not_operator; 117, 118; 118, identifier:metrics; 119, block; 119, 120; 119, 127; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:logger; 124, identifier:debug; 125, argument_list; 125, 126; 126, string:"no metrics to send ..."; 127, return_statement; 128, comment; 129, if_statement; 129, 130; 129, 140; 129, 161; 130, comparison_operator:>=; 130, 131; 130, 134; 130, 139; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:ignore_latency_limit; 134, subscript; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:b; 137, identifier:data; 138, string:'latency'; 139, integer:0; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:check_time; 144, binary_operator:-; 144, 145; 144, 153; 145, call; 145, 146; 145, 147; 146, identifier:int; 147, argument_list; 147, 148; 148, subscript; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:b; 151, identifier:data; 152, string:'last_chk'; 153, call; 153, 154; 153, 155; 154, identifier:int; 155, argument_list; 155, 156; 156, subscript; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:b; 159, identifier:data; 160, string:'latency'; 161, else_clause; 161, 162; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:check_time; 166, call; 166, 167; 166, 168; 167, identifier:int; 168, argument_list; 168, 169; 169, subscript; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:b; 172, identifier:data; 173, string:'last_chk'; 174, comment; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:hname; 178, call; 178, 179; 178, 180; 179, identifier:sanitize_name; 180, argument_list; 180, 181; 181, identifier:host_name; 182, if_statement; 182, 183; 182, 188; 183, comparison_operator:in; 183, 184; 183, 185; 184, identifier:host_name; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:hosts_cache; 188, block; 188, 189; 188, 222; 189, if_statement; 189, 190; 189, 201; 190, call; 190, 191; 190, 198; 191, attribute; 191, 192; 191, 197; 192, subscript; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:hosts_cache; 196, identifier:host_name; 197, identifier:get; 198, argument_list; 198, 199; 198, 200; 199, string:'_GRAPHITE_GROUP'; 200, None; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:hname; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, string:"."; 208, identifier:join; 209, argument_list; 209, 210; 210, tuple; 210, 211; 210, 221; 211, call; 211, 212; 211, 219; 212, attribute; 212, 213; 212, 218; 213, subscript; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:hosts_cache; 217, identifier:host_name; 218, identifier:get; 219, argument_list; 219, 220; 220, string:'_GRAPHITE_GROUP'; 221, identifier:hname; 222, if_statement; 222, 223; 222, 234; 223, call; 223, 224; 223, 231; 224, attribute; 224, 225; 224, 230; 225, subscript; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:hosts_cache; 229, identifier:host_name; 230, identifier:get; 231, argument_list; 231, 232; 231, 233; 232, string:'_GRAPHITE_PRE'; 233, None; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:hname; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, string:"."; 241, identifier:join; 242, argument_list; 242, 243; 243, tuple; 243, 244; 243, 254; 244, call; 244, 245; 244, 252; 245, attribute; 245, 246; 245, 251; 246, subscript; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:hosts_cache; 250, identifier:host_name; 251, identifier:get; 252, argument_list; 252, 253; 253, string:'_GRAPHITE_PRE'; 254, identifier:hname; 255, comment; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:desc; 259, call; 259, 260; 259, 261; 260, identifier:sanitize_name; 261, argument_list; 261, 262; 262, identifier:service_description; 263, if_statement; 263, 264; 263, 269; 264, comparison_operator:in; 264, 265; 264, 266; 265, identifier:service_id; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:services_cache; 269, block; 269, 270; 270, if_statement; 270, 271; 270, 282; 271, call; 271, 272; 271, 279; 272, attribute; 272, 273; 272, 278; 273, subscript; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:services_cache; 277, identifier:service_id; 278, identifier:get; 279, argument_list; 279, 280; 279, 281; 280, string:'_GRAPHITE_POST'; 281, None; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:desc; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, string:"."; 289, identifier:join; 290, argument_list; 290, 291; 291, tuple; 291, 292; 291, 293; 292, identifier:desc; 293, call; 293, 294; 293, 301; 294, attribute; 294, 295; 294, 300; 295, subscript; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:services_cache; 299, identifier:service_id; 300, identifier:get; 301, argument_list; 301, 302; 301, 303; 302, string:'_GRAPHITE_POST'; 303, None; 304, comment; 305, if_statement; 305, 306; 305, 309; 305, 324; 306, attribute; 306, 307; 306, 308; 307, identifier:self; 308, identifier:graphite_data_source; 309, block; 309, 310; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:path; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, string:'.'; 316, identifier:join; 317, argument_list; 317, 318; 318, tuple; 318, 319; 318, 320; 318, 323; 319, identifier:hname; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:graphite_data_source; 323, identifier:desc; 324, else_clause; 324, 325; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 329; 328, identifier:path; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, string:'.'; 332, identifier:join; 333, argument_list; 333, 334; 334, tuple; 334, 335; 334, 336; 335, identifier:hname; 336, identifier:desc; 337, comment; 338, if_statement; 338, 339; 338, 354; 339, boolean_operator:and; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:self; 342, identifier:realms_prefix; 343, call; 343, 344; 343, 351; 344, attribute; 344, 345; 344, 350; 345, subscript; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:self; 348, identifier:hosts_cache; 349, identifier:host_name; 350, identifier:get; 351, argument_list; 351, 352; 351, 353; 352, string:'realm_name'; 353, None; 354, block; 354, 355; 355, expression_statement; 355, 356; 356, assignment; 356, 357; 356, 358; 357, identifier:path; 358, call; 358, 359; 358, 362; 359, attribute; 359, 360; 359, 361; 360, string:'.'; 361, identifier:join; 362, argument_list; 362, 363; 363, tuple; 363, 364; 363, 374; 364, call; 364, 365; 364, 372; 365, attribute; 365, 366; 365, 371; 366, subscript; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:self; 369, identifier:hosts_cache; 370, identifier:host_name; 371, identifier:get; 372, argument_list; 372, 373; 373, string:'realm_name'; 374, identifier:path; 375, expression_statement; 375, 376; 376, assignment; 376, 377; 376, 378; 377, identifier:realm_name; 378, None; 379, if_statement; 379, 380; 379, 385; 380, comparison_operator:in; 380, 381; 380, 382; 381, identifier:host_name; 382, attribute; 382, 383; 382, 384; 383, identifier:self; 384, identifier:hosts_cache; 385, block; 385, 386; 386, expression_statement; 386, 387; 387, assignment; 387, 388; 387, 389; 388, identifier:realm_name; 389, call; 389, 390; 389, 397; 390, attribute; 390, 391; 390, 396; 391, subscript; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:self; 394, identifier:hosts_cache; 395, identifier:host_name; 396, identifier:get; 397, argument_list; 397, 398; 397, 399; 398, string:'realm_name'; 399, None; 400, comment; 401, expression_statement; 401, 402; 402, call; 402, 403; 402, 406; 403, attribute; 403, 404; 403, 405; 404, identifier:self; 405, identifier:send_to_tsdb; 406, argument_list; 406, 407; 406, 408; 406, 409; 406, 410; 406, 411; 406, 412; 407, identifier:realm_name; 408, identifier:host_name; 409, identifier:service_description; 410, identifier:metrics; 411, identifier:check_time; 412, identifier:path | def manage_service_check_result_brok(self, b): # pylint: disable=too-many-branches
"""A service check result brok has just arrived ..."""
host_name = b.data.get('host_name', None)
service_description = b.data.get('service_description', None)
if not host_name or not service_description:
return
service_id = host_name+"/"+service_description
logger.debug("service check result: %s", service_id)
# If host and service initial status broks have not been received, ignore ...
if not self.ignore_unknown and host_name not in self.hosts_cache:
logger.warning("received service check result for an unknown host: %s", service_id)
return
if service_id not in self.services_cache and not self.ignore_unknown:
logger.warning("received service check result for an unknown service: %s", service_id)
return
# Decode received metrics
metrics = self.get_metrics_from_perfdata(service_description, b.data['perf_data'])
if not metrics:
logger.debug("no metrics to send ...")
return
# If checks latency is ignored
if self.ignore_latency_limit >= b.data['latency'] > 0:
check_time = int(b.data['last_chk']) - int(b.data['latency'])
else:
check_time = int(b.data['last_chk'])
# Custom hosts variables
hname = sanitize_name(host_name)
if host_name in self.hosts_cache:
if self.hosts_cache[host_name].get('_GRAPHITE_GROUP', None):
hname = ".".join((self.hosts_cache[host_name].get('_GRAPHITE_GROUP'), hname))
if self.hosts_cache[host_name].get('_GRAPHITE_PRE', None):
hname = ".".join((self.hosts_cache[host_name].get('_GRAPHITE_PRE'), hname))
# Custom services variables
desc = sanitize_name(service_description)
if service_id in self.services_cache:
if self.services_cache[service_id].get('_GRAPHITE_POST', None):
desc = ".".join((desc, self.services_cache[service_id].get('_GRAPHITE_POST', None)))
# Graphite data source
if self.graphite_data_source:
path = '.'.join((hname, self.graphite_data_source, desc))
else:
path = '.'.join((hname, desc))
# Realm as a prefix
if self.realms_prefix and self.hosts_cache[host_name].get('realm_name', None):
path = '.'.join((self.hosts_cache[host_name].get('realm_name'), path))
realm_name = None
if host_name in self.hosts_cache:
realm_name = self.hosts_cache[host_name].get('realm_name', None)
# Send metrics
self.send_to_tsdb(realm_name, host_name, service_description, metrics, check_time, path) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:manage_host_check_result_brok; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:b; 6, comment; 7, block; 7, 8; 7, 10; 7, 22; 7, 27; 7, 35; 7, 36; 7, 57; 7, 58; 7, 72; 7, 84; 7, 85; 7, 130; 7, 131; 7, 138; 7, 211; 7, 212; 7, 266; 7, 267; 7, 304; 7, 308; 7, 329; 7, 330; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:host_name; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:b; 17, identifier:data; 18, identifier:get; 19, argument_list; 19, 20; 19, 21; 20, string:'host_name'; 21, None; 22, if_statement; 22, 23; 22, 25; 23, not_operator; 23, 24; 24, identifier:host_name; 25, block; 25, 26; 26, return_statement; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:logger; 31, identifier:debug; 32, argument_list; 32, 33; 32, 34; 33, string:"host check result: %s"; 34, identifier:host_name; 35, comment; 36, if_statement; 36, 37; 36, 47; 37, boolean_operator:and; 37, 38; 37, 43; 38, comparison_operator:not; 38, 39; 38, 40; 39, identifier:host_name; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:hosts_cache; 43, not_operator; 43, 44; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:ignore_unknown; 47, block; 47, 48; 47, 56; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:logger; 52, identifier:warning; 53, argument_list; 53, 54; 53, 55; 54, string:"received host check result for an unknown host: %s"; 55, identifier:host_name; 56, return_statement; 57, comment; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:metrics; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:get_metrics_from_perfdata; 65, argument_list; 65, 66; 65, 67; 66, string:'host_check'; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:b; 70, identifier:data; 71, string:'perf_data'; 72, if_statement; 72, 73; 72, 75; 73, not_operator; 73, 74; 74, identifier:metrics; 75, block; 75, 76; 75, 83; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:logger; 80, identifier:debug; 81, argument_list; 81, 82; 82, string:"no metrics to send ..."; 83, return_statement; 84, comment; 85, if_statement; 85, 86; 85, 96; 85, 117; 86, comparison_operator:>=; 86, 87; 86, 90; 86, 95; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:ignore_latency_limit; 90, subscript; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:b; 93, identifier:data; 94, string:'latency'; 95, integer:0; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:check_time; 100, binary_operator:-; 100, 101; 100, 109; 101, call; 101, 102; 101, 103; 102, identifier:int; 103, argument_list; 103, 104; 104, subscript; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:b; 107, identifier:data; 108, string:'last_chk'; 109, call; 109, 110; 109, 111; 110, identifier:int; 111, argument_list; 111, 112; 112, subscript; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:b; 115, identifier:data; 116, string:'latency'; 117, else_clause; 117, 118; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:check_time; 122, call; 122, 123; 122, 124; 123, identifier:int; 124, argument_list; 124, 125; 125, subscript; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:b; 128, identifier:data; 129, string:'last_chk'; 130, comment; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:hname; 134, call; 134, 135; 134, 136; 135, identifier:sanitize_name; 136, argument_list; 136, 137; 137, identifier:host_name; 138, if_statement; 138, 139; 138, 144; 139, comparison_operator:in; 139, 140; 139, 141; 140, identifier:host_name; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:hosts_cache; 144, block; 144, 145; 144, 178; 145, if_statement; 145, 146; 145, 157; 146, call; 146, 147; 146, 154; 147, attribute; 147, 148; 147, 153; 148, subscript; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:hosts_cache; 152, identifier:host_name; 153, identifier:get; 154, argument_list; 154, 155; 154, 156; 155, string:'_GRAPHITE_GROUP'; 156, None; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:hname; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, string:"."; 164, identifier:join; 165, argument_list; 165, 166; 166, tuple; 166, 167; 166, 177; 167, call; 167, 168; 167, 175; 168, attribute; 168, 169; 168, 174; 169, subscript; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:hosts_cache; 173, identifier:host_name; 174, identifier:get; 175, argument_list; 175, 176; 176, string:'_GRAPHITE_GROUP'; 177, identifier:hname; 178, if_statement; 178, 179; 178, 190; 179, call; 179, 180; 179, 187; 180, attribute; 180, 181; 180, 186; 181, subscript; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:hosts_cache; 185, identifier:host_name; 186, identifier:get; 187, argument_list; 187, 188; 187, 189; 188, string:'_GRAPHITE_PRE'; 189, None; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:hname; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, string:"."; 197, identifier:join; 198, argument_list; 198, 199; 199, tuple; 199, 200; 199, 210; 200, call; 200, 201; 200, 208; 201, attribute; 201, 202; 201, 207; 202, subscript; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:hosts_cache; 206, identifier:host_name; 207, identifier:get; 208, argument_list; 208, 209; 209, string:'_GRAPHITE_PRE'; 210, identifier:hname; 211, comment; 212, if_statement; 212, 213; 212, 216; 212, 251; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:graphite_data_source; 216, block; 216, 217; 216, 230; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:path; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, string:'.'; 223, identifier:join; 224, argument_list; 224, 225; 225, tuple; 225, 226; 225, 227; 226, identifier:hname; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:graphite_data_source; 230, if_statement; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:hostcheck; 234, block; 234, 235; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:path; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, string:'.'; 241, identifier:join; 242, argument_list; 242, 243; 243, tuple; 243, 244; 243, 245; 243, 248; 244, identifier:hname; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:graphite_data_source; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:hostcheck; 251, else_clause; 251, 252; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:path; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, string:'.'; 259, identifier:join; 260, argument_list; 260, 261; 261, tuple; 261, 262; 261, 263; 262, identifier:hname; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:hostcheck; 266, comment; 267, if_statement; 267, 268; 267, 283; 268, boolean_operator:and; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:realms_prefix; 272, call; 272, 273; 272, 280; 273, attribute; 273, 274; 273, 279; 274, subscript; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:hosts_cache; 278, identifier:host_name; 279, identifier:get; 280, argument_list; 280, 281; 280, 282; 281, string:'realm_name'; 282, None; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:path; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, string:'.'; 290, identifier:join; 291, argument_list; 291, 292; 292, tuple; 292, 293; 292, 303; 293, call; 293, 294; 293, 301; 294, attribute; 294, 295; 294, 300; 295, subscript; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:hosts_cache; 299, identifier:host_name; 300, identifier:get; 301, argument_list; 301, 302; 302, string:'realm_name'; 303, identifier:path; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:realm_name; 307, None; 308, if_statement; 308, 309; 308, 314; 309, comparison_operator:in; 309, 310; 309, 311; 310, identifier:host_name; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:hosts_cache; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:realm_name; 318, call; 318, 319; 318, 326; 319, attribute; 319, 320; 319, 325; 320, subscript; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:self; 323, identifier:hosts_cache; 324, identifier:host_name; 325, identifier:get; 326, argument_list; 326, 327; 326, 328; 327, string:'realm_name'; 328, None; 329, comment; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:self; 334, identifier:send_to_tsdb; 335, argument_list; 335, 336; 335, 337; 335, 338; 335, 341; 335, 342; 335, 343; 336, identifier:realm_name; 337, identifier:host_name; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:hostcheck; 341, identifier:metrics; 342, identifier:check_time; 343, identifier:path | def manage_host_check_result_brok(self, b): # pylint: disable=too-many-branches
"""An host check result brok has just arrived..."""
host_name = b.data.get('host_name', None)
if not host_name:
return
logger.debug("host check result: %s", host_name)
# If host initial status brok has not been received, ignore ...
if host_name not in self.hosts_cache and not self.ignore_unknown:
logger.warning("received host check result for an unknown host: %s", host_name)
return
# Decode received metrics
metrics = self.get_metrics_from_perfdata('host_check', b.data['perf_data'])
if not metrics:
logger.debug("no metrics to send ...")
return
# If checks latency is ignored
if self.ignore_latency_limit >= b.data['latency'] > 0:
check_time = int(b.data['last_chk']) - int(b.data['latency'])
else:
check_time = int(b.data['last_chk'])
# Custom hosts variables
hname = sanitize_name(host_name)
if host_name in self.hosts_cache:
if self.hosts_cache[host_name].get('_GRAPHITE_GROUP', None):
hname = ".".join((self.hosts_cache[host_name].get('_GRAPHITE_GROUP'), hname))
if self.hosts_cache[host_name].get('_GRAPHITE_PRE', None):
hname = ".".join((self.hosts_cache[host_name].get('_GRAPHITE_PRE'), hname))
# Graphite data source
if self.graphite_data_source:
path = '.'.join((hname, self.graphite_data_source))
if self.hostcheck:
path = '.'.join((hname, self.graphite_data_source, self.hostcheck))
else:
path = '.'.join((hname, self.hostcheck))
# Realm as a prefix
if self.realms_prefix and self.hosts_cache[host_name].get('realm_name', None):
path = '.'.join((self.hosts_cache[host_name].get('realm_name'), path))
realm_name = None
if host_name in self.hosts_cache:
realm_name = self.hosts_cache[host_name].get('realm_name', None)
# Send metrics
self.send_to_tsdb(realm_name, host_name, self.hostcheck, metrics, check_time, path) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:resolve_elements; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 31; 5, 32; 5, 46; 5, 61; 5, 62; 5, 63; 5, 75; 5, 81; 5, 82; 5, 86; 5, 146; 5, 147; 5, 168; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:leaf; 13, block; 13, 14; 13, 24; 14, if_statement; 14, 15; 14, 19; 15, not_operator; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:content; 19, block; 19, 20; 20, return_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:set; 23, argument_list; 24, return_statement; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:set; 27, argument_list; 27, 28; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:content; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:not_nodes; 35, list_comprehension; 35, 36; 35, 37; 35, 42; 36, identifier:s; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:s; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:sons; 42, if_clause; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:s; 45, identifier:not_value; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:positiv_nodes; 49, list_comprehension; 49, 50; 49, 51; 49, 56; 50, identifier:s; 51, for_in_clause; 51, 52; 51, 53; 52, identifier:s; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:sons; 56, if_clause; 56, 57; 57, not_operator; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:s; 60, identifier:not_value; 61, comment; 62, comment; 63, if_statement; 63, 64; 63, 68; 64, not_operator; 64, 65; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:operand; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:operand; 74, string:'|'; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:res; 78, call; 78, 79; 78, 80; 79, identifier:set; 80, argument_list; 81, comment; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:i; 85, integer:0; 86, for_statement; 86, 87; 86, 88; 86, 89; 87, identifier:node; 88, identifier:positiv_nodes; 89, block; 89, 90; 89, 98; 89, 142; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:node_members; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:node; 96, identifier:resolve_elements; 97, argument_list; 98, if_statement; 98, 99; 98, 104; 98, 114; 99, comparison_operator:==; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:operand; 103, string:'|'; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:res; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:res; 111, identifier:union; 112, argument_list; 112, 113; 113, identifier:node_members; 114, elif_clause; 114, 115; 114, 120; 114, 121; 115, comparison_operator:==; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:operand; 119, string:'&'; 120, comment; 121, block; 121, 122; 122, if_statement; 122, 123; 122, 126; 122, 131; 123, comparison_operator:==; 123, 124; 123, 125; 124, identifier:i; 125, integer:0; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:res; 130, identifier:node_members; 131, else_clause; 131, 132; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:res; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:res; 139, identifier:intersection; 140, argument_list; 140, 141; 141, identifier:node_members; 142, expression_statement; 142, 143; 143, augmented_assignment:+=; 143, 144; 143, 145; 144, identifier:i; 145, integer:1; 146, comment; 147, for_statement; 147, 148; 147, 149; 147, 150; 148, identifier:node; 149, identifier:not_nodes; 150, block; 150, 151; 150, 159; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:node_members; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:node; 157, identifier:resolve_elements; 158, argument_list; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:res; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:res; 165, identifier:difference; 166, argument_list; 166, 167; 167, identifier:node_members; 168, return_statement; 168, 169; 169, identifier:res | def resolve_elements(self):
"""Get element of this node recursively
Compute rules with OR or AND rule then NOT rules.
:return: set of element
:rtype: set
"""
# If it's a leaf, we just need to dump a set with the content of the node
if self.leaf:
if not self.content:
return set()
return set(self.content)
# first got the not ones in a list, and the other in the other list
not_nodes = [s for s in self.sons if s.not_value]
positiv_nodes = [s for s in self.sons if not s.not_value] # ok a not not is hard to read..
# By default we are using a OR rule
if not self.operand:
self.operand = '|'
res = set()
# The operand will change the positiv loop only
i = 0
for node in positiv_nodes:
node_members = node.resolve_elements()
if self.operand == '|':
res = res.union(node_members)
elif self.operand == '&':
# The first elements of an AND rule should be used
if i == 0:
res = node_members
else:
res = res.intersection(node_members)
i += 1
# And we finally remove all NOT elements from the result
for node in not_nodes:
node_members = node.resolve_elements()
res = res.difference(node_members)
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:eval_cor_pattern; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:pattern; 6, comment; 7, block; 7, 8; 7, 10; 7, 18; 7, 22; 7, 23; 7, 24; 7, 37; 7, 43; 7, 44; 7, 45; 7, 46; 7, 123; 7, 127; 7, 131; 7, 135; 7, 384; 7, 385; 7, 393; 7, 416; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:pattern; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:pattern; 16, identifier:strip; 17, argument_list; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:complex_node; 21, False; 22, comment; 23, comment; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:char; 26, string:'()+&|,'; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:in; 29, 30; 29, 31; 30, identifier:char; 31, identifier:pattern; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:complex_node; 36, True; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:node; 40, call; 40, 41; 40, 42; 41, identifier:ComplexExpressionNode; 42, argument_list; 43, comment; 44, comment; 45, comment; 46, if_statement; 46, 47; 46, 49; 46, 50; 46, 51; 47, not_operator; 47, 48; 48, identifier:complex_node; 49, comment; 50, comment; 51, block; 51, 52; 51, 74; 51, 82; 51, 88; 51, 99; 51, 121; 52, if_statement; 52, 53; 52, 59; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:pattern; 56, identifier:startswith; 57, argument_list; 57, 58; 58, string:'!'; 59, block; 59, 60; 59, 66; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:node; 64, identifier:not_value; 65, True; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:pattern; 69, subscript; 69, 70; 69, 71; 70, identifier:pattern; 71, slice; 71, 72; 71, 73; 72, integer:1; 73, colon; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:node; 78, identifier:operand; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:ctx; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:node; 86, identifier:leaf; 87, True; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, pattern_list; 90, 91; 90, 92; 91, identifier:obj; 92, identifier:error; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:find_object; 97, argument_list; 97, 98; 98, identifier:pattern; 99, if_statement; 99, 100; 99, 103; 99, 110; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:obj; 102, None; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:node; 108, identifier:content; 109, identifier:obj; 110, else_clause; 110, 111; 111, block; 111, 112; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 119; 114, attribute; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:node; 117, identifier:configuration_errors; 118, identifier:append; 119, argument_list; 119, 120; 120, identifier:error; 121, return_statement; 121, 122; 122, identifier:node; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:in_par; 126, False; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:tmp; 130, string:''; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:stacked_par; 134, integer:0; 135, for_statement; 135, 136; 135, 137; 135, 138; 136, identifier:char; 137, identifier:pattern; 138, block; 138, 139; 139, if_statement; 139, 140; 139, 145; 139, 146; 139, 198; 139, 257; 139, 308; 139, 377; 139, 378; 140, comparison_operator:in; 140, 141; 140, 142; 141, identifier:char; 142, tuple; 142, 143; 142, 144; 143, string:','; 144, string:'|'; 145, comment; 146, block; 146, 147; 147, if_statement; 147, 148; 147, 149; 147, 154; 148, identifier:in_par; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, augmented_assignment:+=; 151, 152; 151, 153; 152, identifier:tmp; 153, identifier:char; 154, else_clause; 154, 155; 154, 156; 155, comment; 156, block; 156, 157; 156, 165; 156, 171; 156, 194; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:tmp; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:tmp; 163, identifier:strip; 164, argument_list; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:node; 169, identifier:operand; 170, string:'|'; 171, if_statement; 171, 172; 171, 175; 172, comparison_operator:!=; 172, 173; 172, 174; 173, identifier:tmp; 174, string:''; 175, block; 175, 176; 175, 185; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:son; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:eval_cor_pattern; 183, argument_list; 183, 184; 184, identifier:tmp; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 192; 187, attribute; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:node; 190, identifier:sons; 191, identifier:append; 192, argument_list; 192, 193; 193, identifier:son; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:tmp; 197, string:''; 198, elif_clause; 198, 199; 198, 204; 198, 205; 199, comparison_operator:in; 199, 200; 199, 201; 200, identifier:char; 201, tuple; 201, 202; 201, 203; 202, string:'&'; 203, string:'+'; 204, comment; 205, block; 205, 206; 206, if_statement; 206, 207; 206, 208; 206, 213; 207, identifier:in_par; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, augmented_assignment:+=; 210, 211; 210, 212; 211, identifier:tmp; 212, identifier:char; 213, else_clause; 213, 214; 213, 215; 214, comment; 215, block; 215, 216; 215, 224; 215, 230; 215, 253; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:tmp; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:tmp; 222, identifier:strip; 223, argument_list; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:node; 228, identifier:operand; 229, string:'&'; 230, if_statement; 230, 231; 230, 234; 231, comparison_operator:!=; 231, 232; 231, 233; 232, identifier:tmp; 233, string:''; 234, block; 234, 235; 234, 244; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:son; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:eval_cor_pattern; 242, argument_list; 242, 243; 243, identifier:tmp; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 251; 246, attribute; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:node; 249, identifier:sons; 250, identifier:append; 251, argument_list; 251, 252; 252, identifier:son; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:tmp; 256, string:''; 257, elif_clause; 257, 258; 257, 261; 258, comparison_operator:==; 258, 259; 258, 260; 259, identifier:char; 260, string:'('; 261, block; 261, 262; 261, 266; 261, 270; 261, 278; 261, 279; 261, 280; 261, 297; 261, 298; 261, 299; 262, expression_statement; 262, 263; 263, augmented_assignment:+=; 263, 264; 263, 265; 264, identifier:stacked_par; 265, integer:1; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:in_par; 269, True; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:tmp; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:tmp; 276, identifier:strip; 277, argument_list; 278, comment; 279, comment; 280, if_statement; 280, 281; 280, 288; 280, 289; 281, boolean_operator:and; 281, 282; 281, 285; 282, comparison_operator:==; 282, 283; 282, 284; 283, identifier:stacked_par; 284, integer:1; 285, comparison_operator:!=; 285, 286; 285, 287; 286, identifier:tmp; 287, string:''; 288, comment; 289, block; 289, 290; 289, 296; 290, expression_statement; 290, 291; 291, call; 291, 292; 291, 293; 292, identifier:print; 293, argument_list; 293, 294; 293, 295; 294, string:"ERROR : bad expression near"; 295, identifier:tmp; 296, continue_statement; 297, comment; 298, comment; 299, if_statement; 299, 300; 299, 303; 300, comparison_operator:>; 300, 301; 300, 302; 301, identifier:stacked_par; 302, integer:1; 303, block; 303, 304; 304, expression_statement; 304, 305; 305, augmented_assignment:+=; 305, 306; 305, 307; 306, identifier:tmp; 307, identifier:char; 308, elif_clause; 308, 309; 308, 312; 309, comparison_operator:==; 309, 310; 309, 311; 310, identifier:char; 311, string:')'; 312, block; 312, 313; 312, 317; 312, 331; 312, 372; 312, 373; 313, expression_statement; 313, 314; 314, augmented_assignment:-=; 314, 315; 314, 316; 315, identifier:stacked_par; 316, integer:1; 317, if_statement; 317, 318; 317, 321; 317, 322; 318, comparison_operator:<; 318, 319; 318, 320; 319, identifier:stacked_par; 320, integer:0; 321, comment; 322, block; 322, 323; 322, 330; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 326; 325, identifier:print; 326, argument_list; 326, 327; 326, 328; 326, 329; 327, string:"Error : bad expression near"; 328, identifier:tmp; 329, string:"too much ')'"; 330, continue_statement; 331, if_statement; 331, 332; 331, 335; 332, comparison_operator:==; 332, 333; 332, 334; 333, identifier:stacked_par; 334, integer:0; 335, block; 335, 336; 335, 344; 335, 353; 335, 362; 335, 366; 335, 367; 335, 371; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:tmp; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:tmp; 342, identifier:strip; 343, argument_list; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 347; 346, identifier:son; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:self; 350, identifier:eval_cor_pattern; 351, argument_list; 351, 352; 352, identifier:tmp; 353, expression_statement; 353, 354; 354, call; 354, 355; 354, 360; 355, attribute; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:node; 358, identifier:sons; 359, identifier:append; 360, argument_list; 360, 361; 361, identifier:son; 362, expression_statement; 362, 363; 363, assignment; 363, 364; 363, 365; 364, identifier:in_par; 365, False; 366, comment; 367, expression_statement; 367, 368; 368, assignment; 368, 369; 368, 370; 369, identifier:tmp; 370, string:''; 371, continue_statement; 372, comment; 373, expression_statement; 373, 374; 374, augmented_assignment:+=; 374, 375; 374, 376; 375, identifier:tmp; 376, identifier:char; 377, comment; 378, else_clause; 378, 379; 379, block; 379, 380; 380, expression_statement; 380, 381; 381, augmented_assignment:+=; 381, 382; 381, 383; 382, identifier:tmp; 383, identifier:char; 384, comment; 385, expression_statement; 385, 386; 386, assignment; 386, 387; 386, 388; 387, identifier:tmp; 388, call; 388, 389; 388, 392; 389, attribute; 389, 390; 389, 391; 390, identifier:tmp; 391, identifier:strip; 392, argument_list; 393, if_statement; 393, 394; 393, 397; 394, comparison_operator:!=; 394, 395; 394, 396; 395, identifier:tmp; 396, string:''; 397, block; 397, 398; 397, 407; 398, expression_statement; 398, 399; 399, assignment; 399, 400; 399, 401; 400, identifier:son; 401, call; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:self; 404, identifier:eval_cor_pattern; 405, argument_list; 405, 406; 406, identifier:tmp; 407, expression_statement; 407, 408; 408, call; 408, 409; 408, 414; 409, attribute; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, identifier:node; 412, identifier:sons; 413, identifier:append; 414, argument_list; 414, 415; 415, identifier:son; 416, return_statement; 416, 417; 417, identifier:node | def eval_cor_pattern(self, pattern): # pylint:disable=too-many-branches
"""Parse and build recursively a tree of ComplexExpressionNode from pattern
:param pattern: pattern to parse
:type pattern: str
:return: root node of parsed tree
:type: alignak.complexexpression.ComplexExpressionNode
"""
pattern = pattern.strip()
complex_node = False
# Look if it's a complex pattern (with rule) or
# if it's a leaf of it, like a host/service
for char in '()+&|,':
if char in pattern:
complex_node = True
node = ComplexExpressionNode()
# if it's a single expression like !linux or production
# (where "linux" and "production" are hostgroup names)
# we will get the objects from it and return a leaf node
if not complex_node:
# If it's a not value, tag the node and find
# the name without this ! operator
if pattern.startswith('!'):
node.not_value = True
pattern = pattern[1:]
node.operand = self.ctx
node.leaf = True
obj, error = self.find_object(pattern)
if obj is not None:
node.content = obj
else:
node.configuration_errors.append(error)
return node
in_par = False
tmp = ''
stacked_par = 0
for char in pattern:
if char in (',', '|'):
# Maybe we are in a par, if so, just stack it
if in_par:
tmp += char
else:
# Oh we got a real cut in an expression, if so, cut it
tmp = tmp.strip()
node.operand = '|'
if tmp != '':
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
tmp = ''
elif char in ('&', '+'):
# Maybe we are in a par, if so, just stack it
if in_par:
tmp += char
else:
# Oh we got a real cut in an expression, if so, cut it
tmp = tmp.strip()
node.operand = '&'
if tmp != '':
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
tmp = ''
elif char == '(':
stacked_par += 1
in_par = True
tmp = tmp.strip()
# Maybe we just start a par, but we got some things in tmp
# that should not be good in fact !
if stacked_par == 1 and tmp != '':
# TODO : real error
print("ERROR : bad expression near", tmp)
continue
# If we are already in a par, add this (
# but not if it's the first one so
if stacked_par > 1:
tmp += char
elif char == ')':
stacked_par -= 1
if stacked_par < 0:
# TODO : real error
print("Error : bad expression near", tmp, "too much ')'")
continue
if stacked_par == 0:
tmp = tmp.strip()
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
in_par = False
# OK now clean the tmp so we start clean
tmp = ''
continue
# ok here we are still in a huge par, we just close one sub one
tmp += char
# Maybe it's a classic character, if so, continue
else:
tmp += char
# Be sure to manage the trainling part when the line is done
tmp = tmp.strip()
if tmp != '':
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
return node |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:find_object; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:pattern; 6, block; 6, 7; 6, 9; 6, 13; 6, 17; 6, 25; 6, 71; 6, 72; 6, 184; 6, 195; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:obj; 12, None; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:error; 16, None; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:pattern; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:pattern; 23, identifier:strip; 24, argument_list; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:==; 26, 27; 26, 28; 27, identifier:pattern; 28, string:'*'; 29, block; 29, 30; 29, 67; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:obj; 33, list_comprehension; 33, 34; 33, 37; 33, 51; 34, attribute; 34, 35; 34, 36; 35, identifier:h; 36, identifier:host_name; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:h; 39, call; 39, 40; 39, 41; 40, identifier:list; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 50; 43, attribute; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:all_elements; 48, identifier:items; 49, identifier:values; 50, argument_list; 51, if_clause; 51, 52; 52, boolean_operator:and; 52, 53; 52, 61; 53, comparison_operator:!=; 53, 54; 53, 60; 54, call; 54, 55; 54, 56; 55, identifier:getattr; 56, argument_list; 56, 57; 56, 58; 56, 59; 57, identifier:h; 58, string:'host_name'; 59, string:''; 60, string:''; 61, not_operator; 61, 62; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:h; 65, identifier:is_tpl; 66, argument_list; 67, return_statement; 67, 68; 68, expression_list; 68, 69; 68, 70; 69, identifier:obj; 70, identifier:error; 71, comment; 72, if_statement; 72, 73; 72, 78; 72, 79; 73, comparison_operator:==; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:ctx; 77, string:'hostgroups'; 78, comment; 79, block; 79, 80; 79, 91; 79, 92; 79, 110; 79, 111; 79, 119; 79, 126; 79, 127; 79, 180; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:hgr; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:grps; 88, identifier:find_by_name; 89, argument_list; 89, 90; 90, identifier:pattern; 91, comment; 92, if_statement; 92, 93; 92, 95; 93, not_operator; 93, 94; 94, identifier:hgr; 95, block; 95, 96; 95, 106; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:error; 99, binary_operator:%; 99, 100; 99, 101; 100, string:"Error : cannot find the %s of the expression '%s'"; 101, tuple; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:ctx; 105, identifier:pattern; 106, return_statement; 106, 107; 107, expression_list; 107, 108; 107, 109; 108, identifier:hgr; 109, identifier:error; 110, comment; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:elts; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:hgr; 117, identifier:get_hosts; 118, argument_list; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:elts; 122, call; 122, 123; 122, 124; 123, identifier:strip_and_uniq; 124, argument_list; 124, 125; 125, identifier:elts; 126, comment; 127, if_statement; 127, 128; 127, 131; 128, comparison_operator:in; 128, 129; 128, 130; 129, string:'*'; 130, identifier:elts; 131, block; 131, 132; 131, 172; 131, 173; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:elts; 136, identifier:extend; 137, argument_list; 137, 138; 138, list_comprehension; 138, 139; 138, 142; 138, 156; 139, attribute; 139, 140; 139, 141; 140, identifier:h; 141, identifier:host_name; 142, for_in_clause; 142, 143; 142, 144; 143, identifier:h; 144, call; 144, 145; 144, 146; 145, identifier:list; 146, argument_list; 146, 147; 147, call; 147, 148; 147, 155; 148, attribute; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:all_elements; 153, identifier:items; 154, identifier:values; 155, argument_list; 156, if_clause; 156, 157; 157, boolean_operator:and; 157, 158; 157, 166; 158, comparison_operator:!=; 158, 159; 158, 165; 159, call; 159, 160; 159, 161; 160, identifier:getattr; 161, argument_list; 161, 162; 161, 163; 161, 164; 162, identifier:h; 163, string:'host_name'; 164, string:''; 165, string:''; 166, not_operator; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:h; 170, identifier:is_tpl; 171, argument_list; 172, comment; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:elts; 177, identifier:remove; 178, argument_list; 178, 179; 179, string:'*'; 180, return_statement; 180, 181; 181, expression_list; 181, 182; 181, 183; 182, identifier:elts; 183, identifier:error; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:obj; 187, call; 187, 188; 187, 193; 188, attribute; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:grps; 192, identifier:find_hosts_that_use_template; 193, argument_list; 193, 194; 194, identifier:pattern; 195, return_statement; 195, 196; 196, expression_list; 196, 197; 196, 198; 197, identifier:obj; 198, identifier:error | def find_object(self, pattern):
"""Get a list of host corresponding to the pattern regarding the context
:param pattern: pattern to find
:type pattern: str
:return: Host list matching pattern (hostgroup name, template, all)
:rtype: list[alignak.objects.host.Host]
"""
obj = None
error = None
pattern = pattern.strip()
if pattern == '*':
obj = [h.host_name for h in list(self.all_elements.items.values())
if getattr(h, 'host_name', '') != '' and not h.is_tpl()]
return obj, error
# Ok a more classic way
if self.ctx == 'hostgroups':
# Ok try to find this hostgroup
hgr = self.grps.find_by_name(pattern)
# Maybe it's an known one?
if not hgr:
error = "Error : cannot find the %s of the expression '%s'" % (self.ctx, pattern)
return hgr, error
# Ok the group is found, get the elements!
elts = hgr.get_hosts()
elts = strip_and_uniq(elts)
# Maybe the hostgroup memebrs is '*', if so expand with all hosts
if '*' in elts:
elts.extend([h.host_name for h in list(self.all_elements.items.values())
if getattr(h, 'host_name', '') != '' and not h.is_tpl()])
# And remove this strange hostname too :)
elts.remove('*')
return elts, error
obj = self.grps.find_hosts_that_use_template(pattern)
return obj, error |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 2, function_name:clean_queues; 3, parameters; 3, 4; 4, identifier:self; 5, comment; 6, block; 6, 7; 6, 9; 6, 10; 6, 30; 6, 49; 6, 68; 6, 94; 6, 95; 6, 96; 6, 97; 6, 98; 6, 104; 6, 258; 6, 259; 6, 260; 6, 266; 6, 340; 6, 346; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, if_statement; 10, 11; 10, 21; 11, comparison_operator:==; 11, 12; 11, 20; 12, call; 12, 13; 12, 14; 13, identifier:getattr; 14, argument_list; 14, 15; 14, 18; 14, 19; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:pushed_conf; 18, string:'tick_clean_queues'; 19, integer:0; 20, integer:0; 21, block; 21, 22; 21, 29; 22, expression_statement; 22, 23; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:logger; 26, identifier:debug; 27, argument_list; 27, 28; 28, string:"No queues cleaning..."; 29, return_statement; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:max_checks; 33, binary_operator:*; 33, 34; 33, 35; 34, identifier:MULTIPLIER_MAX_CHECKS; 35, parenthesized_expression; 35, 36; 36, binary_operator:+; 36, 37; 36, 43; 37, call; 37, 38; 37, 39; 38, identifier:len; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:hosts; 43, call; 43, 44; 43, 45; 44, identifier:len; 45, argument_list; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:services; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:max_broks; 52, binary_operator:*; 52, 53; 52, 54; 53, identifier:MULTIPLIER_MAX_BROKS; 54, parenthesized_expression; 54, 55; 55, binary_operator:+; 55, 56; 55, 62; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:hosts; 62, call; 62, 63; 62, 64; 63, identifier:len; 64, argument_list; 64, 65; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:services; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:max_actions; 71, binary_operator:*; 71, 72; 71, 80; 72, binary_operator:*; 72, 73; 72, 74; 73, identifier:MULTIPLIER_MAX_ACTIONS; 74, call; 74, 75; 74, 76; 75, identifier:len; 76, argument_list; 76, 77; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:contacts; 80, parenthesized_expression; 80, 81; 81, binary_operator:+; 81, 82; 81, 88; 82, call; 82, 83; 82, 84; 83, identifier:len; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:hosts; 88, call; 88, 89; 88, 90; 89, identifier:len; 90, argument_list; 90, 91; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:services; 94, comment; 95, comment; 96, comment; 97, comment; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:nb_checks_dropped; 103, integer:0; 104, if_statement; 104, 105; 104, 115; 104, 116; 105, boolean_operator:and; 105, 106; 105, 107; 106, identifier:max_checks; 107, comparison_operator:>; 107, 108; 107, 114; 108, call; 108, 109; 108, 110; 109, identifier:len; 110, argument_list; 110, 111; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:checks; 114, identifier:max_checks; 115, comment; 116, block; 116, 117; 116, 134; 116, 148; 116, 157; 116, 166; 116, 179; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:to_del_checks; 120, list_comprehension; 120, 121; 120, 122; 121, identifier:c; 122, for_in_clause; 122, 123; 122, 124; 123, identifier:c; 124, call; 124, 125; 124, 126; 125, identifier:list; 126, argument_list; 126, 127; 127, call; 127, 128; 127, 133; 128, attribute; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:checks; 132, identifier:values; 133, argument_list; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:to_del_checks; 138, identifier:sort; 139, argument_list; 139, 140; 140, keyword_argument; 140, 141; 140, 142; 141, identifier:key; 142, lambda; 142, 143; 142, 145; 143, lambda_parameters; 143, 144; 144, identifier:x; 145, attribute; 145, 146; 145, 147; 146, identifier:x; 147, identifier:creation_time; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:to_del_checks; 151, subscript; 151, 152; 151, 153; 152, identifier:to_del_checks; 153, slice; 153, 154; 153, 155; 154, colon; 155, unary_operator:-; 155, 156; 156, identifier:max_checks; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:nb_checks_dropped; 162, call; 162, 163; 162, 164; 163, identifier:len; 164, argument_list; 164, 165; 165, identifier:to_del_checks; 166, if_statement; 166, 167; 166, 168; 167, identifier:to_del_checks; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:logger; 173, identifier:warning; 174, argument_list; 174, 175; 174, 176; 175, string:"I have to drop some checks (%d)..., sorry :("; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:nb_checks_dropped; 179, for_statement; 179, 180; 179, 181; 179, 182; 180, identifier:chk; 181, identifier:to_del_checks; 182, block; 182, 183; 182, 189; 182, 201; 182, 209; 182, 210; 182, 217; 182, 218; 182, 219; 182, 236; 182, 251; 182, 257; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:c_id; 186, attribute; 186, 187; 186, 188; 187, identifier:chk; 188, identifier:uuid; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:items; 192, call; 192, 193; 192, 194; 193, identifier:getattr; 194, argument_list; 194, 195; 194, 196; 195, identifier:self; 196, binary_operator:+; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:chk; 199, identifier:ref_type; 200, string:'s'; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:elt; 204, subscript; 204, 205; 204, 206; 205, identifier:items; 206, attribute; 206, 207; 206, 208; 207, identifier:chk; 208, identifier:ref; 209, comment; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:elt; 214, identifier:remove_in_progress_check; 215, argument_list; 215, 216; 216, identifier:chk; 217, comment; 218, comment; 219, for_statement; 219, 220; 219, 221; 219, 224; 220, identifier:dependent_checks; 221, attribute; 221, 222; 221, 223; 222, identifier:chk; 223, identifier:depend_on_me; 224, block; 224, 225; 225, expression_statement; 225, 226; 226, call; 226, 227; 226, 232; 227, attribute; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:dependent_checks; 230, identifier:depend_on; 231, identifier:remove; 232, argument_list; 232, 233; 233, attribute; 233, 234; 233, 235; 234, identifier:chk; 235, identifier:uuid; 236, for_statement; 236, 237; 236, 238; 236, 241; 237, identifier:c_temp; 238, attribute; 238, 239; 238, 240; 239, identifier:chk; 240, identifier:depend_on; 241, block; 241, 242; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 249; 244, attribute; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:c_temp; 247, identifier:depend_on_me; 248, identifier:remove; 249, argument_list; 249, 250; 250, identifier:chk; 251, delete_statement; 251, 252; 252, subscript; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:checks; 256, identifier:c_id; 257, comment; 258, comment; 259, comment; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:nb_broks_dropped; 265, integer:0; 266, for_statement; 266, 267; 266, 268; 266, 280; 267, identifier:broker_link; 268, call; 268, 269; 268, 270; 269, identifier:list; 270, argument_list; 270, 271; 271, call; 271, 272; 271, 279; 272, attribute; 272, 273; 272, 278; 273, attribute; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:my_daemon; 277, identifier:brokers; 278, identifier:values; 279, argument_list; 280, block; 280, 281; 281, if_statement; 281, 282; 281, 292; 282, boolean_operator:and; 282, 283; 282, 284; 283, identifier:max_broks; 284, comparison_operator:>; 284, 285; 284, 291; 285, call; 285, 286; 285, 287; 286, identifier:len; 287, argument_list; 287, 288; 288, attribute; 288, 289; 288, 290; 289, identifier:broker_link; 290, identifier:broks; 291, identifier:max_broks; 292, block; 292, 293; 292, 310; 292, 327; 292, 328; 292, 329; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:logger; 297, identifier:warning; 298, argument_list; 298, 299; 298, 302; 298, 308; 298, 309; 299, concatenated_string; 299, 300; 299, 301; 300, string:"I have to drop some broks (%d > %d) for the broker %s "; 301, string:"..., sorry :("; 302, call; 302, 303; 302, 304; 303, identifier:len; 304, argument_list; 304, 305; 305, attribute; 305, 306; 305, 307; 306, identifier:broker_link; 307, identifier:broks; 308, identifier:max_broks; 309, identifier:broker_link; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:kept_broks; 313, call; 313, 314; 313, 315; 314, identifier:sorted; 315, argument_list; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:broker_link; 318, identifier:broks; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:key; 321, lambda; 321, 322; 321, 324; 322, lambda_parameters; 322, 323; 323, identifier:x; 324, attribute; 324, 325; 324, 326; 325, identifier:x; 326, identifier:creation_time; 327, comment; 328, comment; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:broker_link; 333, identifier:broks; 334, subscript; 334, 335; 334, 336; 335, identifier:kept_broks; 336, slice; 336, 337; 336, 338; 336, 339; 337, integer:0; 338, colon; 339, identifier:max_broks; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:self; 344, identifier:nb_actions_dropped; 345, integer:0; 346, if_statement; 346, 347; 346, 357; 347, boolean_operator:and; 347, 348; 347, 349; 348, identifier:max_actions; 349, comparison_operator:>; 349, 350; 349, 356; 350, call; 350, 351; 350, 352; 351, identifier:len; 352, argument_list; 352, 353; 353, attribute; 353, 354; 353, 355; 354, identifier:self; 355, identifier:actions; 356, identifier:max_actions; 357, block; 357, 358; 357, 372; 357, 389; 357, 403; 357, 412; 357, 421; 358, expression_statement; 358, 359; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:logger; 362, identifier:warning; 363, argument_list; 363, 364; 363, 365; 363, 371; 364, string:"I have to del some actions (currently: %d, max: %d)..., sorry :("; 365, call; 365, 366; 365, 367; 366, identifier:len; 367, argument_list; 367, 368; 368, attribute; 368, 369; 368, 370; 369, identifier:self; 370, identifier:actions; 371, identifier:max_actions; 372, expression_statement; 372, 373; 373, assignment; 373, 374; 373, 375; 374, identifier:to_del_actions; 375, list_comprehension; 375, 376; 375, 377; 376, identifier:c; 377, for_in_clause; 377, 378; 377, 379; 378, identifier:c; 379, call; 379, 380; 379, 381; 380, identifier:list; 381, argument_list; 381, 382; 382, call; 382, 383; 382, 388; 383, attribute; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:self; 386, identifier:actions; 387, identifier:values; 388, argument_list; 389, expression_statement; 389, 390; 390, call; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:to_del_actions; 393, identifier:sort; 394, argument_list; 394, 395; 395, keyword_argument; 395, 396; 395, 397; 396, identifier:key; 397, lambda; 397, 398; 397, 400; 398, lambda_parameters; 398, 399; 399, identifier:x; 400, attribute; 400, 401; 400, 402; 401, identifier:x; 402, identifier:creation_time; 403, expression_statement; 403, 404; 404, assignment; 404, 405; 404, 406; 405, identifier:to_del_actions; 406, subscript; 406, 407; 406, 408; 407, identifier:to_del_actions; 408, slice; 408, 409; 408, 410; 409, colon; 410, unary_operator:-; 410, 411; 411, identifier:max_actions; 412, expression_statement; 412, 413; 413, assignment; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:self; 416, identifier:nb_actions_dropped; 417, call; 417, 418; 417, 419; 418, identifier:len; 419, argument_list; 419, 420; 420, identifier:to_del_actions; 421, for_statement; 421, 422; 421, 423; 421, 424; 422, identifier:act; 423, identifier:to_del_actions; 424, block; 424, 425; 424, 446; 425, if_statement; 425, 426; 425, 431; 426, comparison_operator:==; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:act; 429, identifier:is_a; 430, string:'notification'; 431, block; 431, 432; 432, expression_statement; 432, 433; 433, call; 433, 434; 433, 444; 434, attribute; 434, 435; 434, 443; 435, call; 435, 436; 435, 439; 436, attribute; 436, 437; 436, 438; 437, identifier:self; 438, identifier:find_item_by_id; 439, argument_list; 439, 440; 440, attribute; 440, 441; 440, 442; 441, identifier:act; 442, identifier:ref; 443, identifier:remove_in_progress_notification; 444, argument_list; 444, 445; 445, identifier:act; 446, delete_statement; 446, 447; 447, subscript; 447, 448; 447, 451; 448, attribute; 448, 449; 448, 450; 449, identifier:self; 450, identifier:actions; 451, attribute; 451, 452; 451, 453; 452, identifier:act; 453, identifier:uuid | def clean_queues(self):
# pylint: disable=too-many-locals
"""Reduces internal list size to max allowed
* checks and broks : 5 * length of hosts + services
* actions : 5 * length of hosts + services + contacts
:return: None
"""
# If we set the interval at 0, we bail out
if getattr(self.pushed_conf, 'tick_clean_queues', 0) == 0:
logger.debug("No queues cleaning...")
return
max_checks = MULTIPLIER_MAX_CHECKS * (len(self.hosts) + len(self.services))
max_broks = MULTIPLIER_MAX_BROKS * (len(self.hosts) + len(self.services))
max_actions = MULTIPLIER_MAX_ACTIONS * len(self.contacts) * (len(self.hosts) +
len(self.services))
# For checks, it's not very simple:
# For checks, they may be referred to their host/service
# We do not just del them in the check list, but also in their service/host
# We want id of lower than max_id - 2*max_checks
self.nb_checks_dropped = 0
if max_checks and len(self.checks) > max_checks:
# keys does not ensure sorted keys. Max is slow but we have no other way.
to_del_checks = [c for c in list(self.checks.values())]
to_del_checks.sort(key=lambda x: x.creation_time)
to_del_checks = to_del_checks[:-max_checks]
self.nb_checks_dropped = len(to_del_checks)
if to_del_checks:
logger.warning("I have to drop some checks (%d)..., sorry :(",
self.nb_checks_dropped)
for chk in to_del_checks:
c_id = chk.uuid
items = getattr(self, chk.ref_type + 's')
elt = items[chk.ref]
# First remove the link in host/service
elt.remove_in_progress_check(chk)
# Then in dependent checks (I depend on, or check
# depend on me)
for dependent_checks in chk.depend_on_me:
dependent_checks.depend_on.remove(chk.uuid)
for c_temp in chk.depend_on:
c_temp.depend_on_me.remove(chk)
del self.checks[c_id] # Final Bye bye ...
# For broks and actions, it's more simple
# or broks, manage global but also all brokers
self.nb_broks_dropped = 0
for broker_link in list(self.my_daemon.brokers.values()):
if max_broks and len(broker_link.broks) > max_broks:
logger.warning("I have to drop some broks (%d > %d) for the broker %s "
"..., sorry :(", len(broker_link.broks), max_broks, broker_link)
kept_broks = sorted(broker_link.broks, key=lambda x: x.creation_time)
# Delete the oldest broks to keep the max_broks most recent...
# todo: is it a good choice !
broker_link.broks = kept_broks[0:max_broks]
self.nb_actions_dropped = 0
if max_actions and len(self.actions) > max_actions:
logger.warning("I have to del some actions (currently: %d, max: %d)..., sorry :(",
len(self.actions), max_actions)
to_del_actions = [c for c in list(self.actions.values())]
to_del_actions.sort(key=lambda x: x.creation_time)
to_del_actions = to_del_actions[:-max_actions]
self.nb_actions_dropped = len(to_del_actions)
for act in to_del_actions:
if act.is_a == 'notification':
self.find_item_by_id(act.ref).remove_in_progress_notification(act)
del self.actions[act.uuid] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:scatter_master_notifications; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 17; 5, 55; 5, 69; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:now; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:time; 14, identifier:time; 15, argument_list; 16, comment; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:notifications; 20, list_comprehension; 20, 21; 20, 22; 20, 31; 21, identifier:a; 22, for_in_clause; 22, 23; 22, 24; 23, identifier:a; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:actions; 29, identifier:values; 30, argument_list; 31, if_clause; 31, 32; 32, boolean_operator:and; 32, 33; 32, 49; 33, boolean_operator:and; 33, 34; 33, 45; 34, boolean_operator:and; 34, 35; 34, 40; 35, comparison_operator:==; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:a; 38, identifier:is_a; 39, string:u'notification'; 40, comparison_operator:==; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:a; 43, identifier:status; 44, identifier:ACT_STATUS_SCHEDULED; 45, not_operator; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:a; 48, identifier:contact; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:a; 52, identifier:is_launchable; 53, argument_list; 53, 54; 54, identifier:now; 55, if_statement; 55, 56; 55, 57; 56, identifier:notifications; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:logger; 62, identifier:debug; 63, argument_list; 63, 64; 63, 65; 64, string:"Scatter master notification: %d notifications"; 65, call; 65, 66; 65, 67; 66, identifier:len; 67, argument_list; 67, 68; 68, identifier:notifications; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:notification; 71, identifier:notifications; 72, block; 72, 73; 72, 81; 72, 82; 72, 83; 72, 84; 72, 95; 72, 99; 72, 103; 72, 123; 72, 206; 72, 207; 72, 208; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:logger; 77, identifier:debug; 78, argument_list; 78, 79; 78, 80; 79, string:"Scheduler got a master notification: %s"; 80, identifier:notification; 81, comment; 82, comment; 83, comment; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:item; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:find_item_by_id; 91, argument_list; 91, 92; 92, attribute; 92, 93; 92, 94; 93, identifier:notification; 94, identifier:ref; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:children; 98, list:[]; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:notification_period; 102, None; 103, if_statement; 103, 104; 103, 112; 104, comparison_operator:is; 104, 105; 104, 111; 105, call; 105, 106; 105, 107; 106, identifier:getattr; 107, argument_list; 107, 108; 107, 109; 107, 110; 108, identifier:item; 109, string:'notification_period'; 110, None; 111, None; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:notification_period; 116, subscript; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:timeperiods; 120, attribute; 120, 121; 120, 122; 121, identifier:item; 122, identifier:notification_period; 123, if_statement; 123, 124; 123, 141; 123, 142; 123, 143; 123, 144; 124, not_operator; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:item; 128, identifier:is_blocking_notifications; 129, argument_list; 129, 130; 129, 131; 129, 134; 129, 137; 129, 140; 130, identifier:notification_period; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:hosts; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:services; 137, attribute; 137, 138; 137, 139; 138, identifier:notification; 139, identifier:type; 140, identifier:now; 141, comment; 142, comment; 143, comment; 144, block; 144, 145; 144, 180; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:children; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:item; 151, identifier:scatter_notification; 152, argument_list; 152, 153; 152, 154; 152, 157; 152, 160; 152, 163; 152, 166; 152, 169; 153, identifier:notification; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:contacts; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:notificationways; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:timeperiods; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:macromodulations; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:escalations; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:find_item_by_id; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 176; 175, identifier:getattr; 176, argument_list; 176, 177; 176, 178; 176, 179; 177, identifier:item; 178, string:"host"; 179, None; 180, for_statement; 180, 181; 180, 182; 180, 183; 181, identifier:notif; 182, identifier:children; 183, block; 183, 184; 183, 192; 183, 198; 183, 199; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:logger; 188, identifier:debug; 189, argument_list; 189, 190; 189, 191; 190, string:" - child notification: %s"; 191, identifier:notif; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:notif; 196, identifier:status; 197, identifier:ACT_STATUS_SCHEDULED; 198, comment; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:add; 204, argument_list; 204, 205; 205, identifier:notif; 206, comment; 207, comment; 208, if_statement; 208, 209; 208, 214; 208, 215; 208, 302; 209, comparison_operator:==; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:notification; 212, identifier:type; 213, string:u'PROBLEM'; 214, comment; 215, block; 215, 216; 215, 231; 216, if_statement; 216, 217; 216, 218; 216, 219; 216, 220; 216, 221; 216, 222; 217, identifier:children; 218, comment; 219, comment; 220, comment; 221, comment; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:item; 227, identifier:current_notification_number; 228, attribute; 228, 229; 228, 230; 229, identifier:notification; 230, identifier:notif_nb; 231, if_statement; 231, 232; 231, 241; 231, 242; 231, 243; 231, 244; 231, 245; 231, 246; 231, 247; 231, 248; 231, 284; 232, boolean_operator:and; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:item; 235, identifier:notification_interval; 236, comparison_operator:is; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:notification; 239, identifier:t_to_go; 240, None; 241, comment; 242, comment; 243, comment; 244, comment; 245, comment; 246, comment; 247, comment; 248, block; 248, 249; 248, 266; 248, 276; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:notification; 253, identifier:t_to_go; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:item; 257, identifier:get_next_notification_time; 258, argument_list; 258, 259; 258, 260; 258, 263; 259, identifier:notification; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:escalations; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:timeperiods; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:notification; 270, identifier:notif_nb; 271, binary_operator:+; 271, 272; 271, 275; 272, attribute; 272, 273; 272, 274; 273, identifier:item; 274, identifier:current_notification_number; 275, integer:1; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:logger; 280, identifier:debug; 281, argument_list; 281, 282; 281, 283; 282, string:"Repeat master notification: %s"; 283, identifier:notification; 284, else_clause; 284, 285; 284, 286; 285, comment; 286, block; 286, 287; 286, 294; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:item; 291, identifier:remove_in_progress_notification; 292, argument_list; 292, 293; 293, identifier:notification; 294, expression_statement; 294, 295; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:logger; 298, identifier:debug; 299, argument_list; 299, 300; 299, 301; 300, string:"Remove master notification (no repeat): %s"; 301, identifier:notification; 302, else_clause; 302, 303; 302, 304; 303, comment; 304, block; 304, 305; 304, 313; 304, 314; 305, expression_statement; 305, 306; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:logger; 309, identifier:debug; 310, argument_list; 310, 311; 310, 312; 311, string:"Remove master notification (no more a problem): %s"; 312, identifier:notification; 313, comment; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:item; 318, identifier:remove_in_progress_notification; 319, argument_list; 319, 320; 320, identifier:notification | def scatter_master_notifications(self):
"""Generate children notifications from a master notification
Also update notification number
Master notification are raised when a notification must be sent out. They are not
launched by reactionners (only children are) but they are used to build the
children notifications.
From one master notification, several children notifications may be built,
indeed one per each contact...
:return: None
"""
now = time.time()
# We only want the master scheduled notifications that are immediately launchable
notifications = [a for a in self.actions.values()
if a.is_a == u'notification' and a.status == ACT_STATUS_SCHEDULED
and not a.contact and a.is_launchable(now)]
if notifications:
logger.debug("Scatter master notification: %d notifications",
len(notifications))
for notification in notifications:
logger.debug("Scheduler got a master notification: %s", notification)
# This is a "master" notification created by an host/service.
# We use it to create children notifications (for the contacts and
# notification_commands) which are executed in the reactionner.
item = self.find_item_by_id(notification.ref)
children = []
notification_period = None
if getattr(item, 'notification_period', None) is not None:
notification_period = self.timeperiods[item.notification_period]
if not item.is_blocking_notifications(notification_period,
self.hosts, self.services,
notification.type, now):
# If it is possible to send notifications
# of this type at the current time, then create
# a single notification for each contact of this item.
children = item.scatter_notification(
notification, self.contacts, self.notificationways, self.timeperiods,
self.macromodulations, self.escalations,
self.find_item_by_id(getattr(item, "host", None))
)
for notif in children:
logger.debug(" - child notification: %s", notif)
notif.status = ACT_STATUS_SCHEDULED
# Add the notification to the scheduler objects
self.add(notif)
# If we have notification_interval then schedule
# the next notification (problems only)
if notification.type == u'PROBLEM':
# Update the ref notif number after raise the one of the notification
if children:
# notif_nb of the master notification
# was already current_notification_number+1.
# If notifications were sent,
# then host/service-counter will also be incremented
item.current_notification_number = notification.notif_nb
if item.notification_interval and notification.t_to_go is not None:
# We must continue to send notifications.
# Just leave it in the actions list and set it to "scheduled"
# and it will be found again later
# Ask the service/host to compute the next notif time. It can be just
# a.t_to_go + item.notification_interval*item.__class__.interval_length
# or maybe before because we have an
# escalation that need to raise up before
notification.t_to_go = item.get_next_notification_time(notification,
self.escalations,
self.timeperiods)
notification.notif_nb = item.current_notification_number + 1
logger.debug("Repeat master notification: %s", notification)
else:
# Wipe out this master notification. It is a master one
item.remove_in_progress_notification(notification)
logger.debug("Remove master notification (no repeat): %s", notification)
else:
# Wipe out this master notification.
logger.debug("Remove master notification (no more a problem): %s", notification)
# We don't repeat recover/downtime/flap/etc...
item.remove_in_progress_notification(notification) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:log_initial_states; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 21; 5, 22; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, for_statement; 9, 10; 9, 11; 9, 14; 10, identifier:elt; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:hosts; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:elt; 19, identifier:raise_initial_state; 20, argument_list; 21, comment; 22, for_statement; 22, 23; 22, 24; 22, 27; 23, identifier:elt; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:services; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:elt; 32, identifier:raise_initial_state; 33, argument_list | def log_initial_states(self):
"""Raise hosts and services initial status logs
First, raise hosts status and then services. This to allow the events log
to be a little sorted.
:return: None
"""
# Raise hosts initial status broks
for elt in self.hosts:
elt.raise_initial_state()
# And then services initial status broks
for elt in self.services:
elt.raise_initial_state() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 1, 7; 2, function_name:get_retention_data; 3, parameters; 3, 4; 4, identifier:self; 5, comment; 6, comment; 7, block; 7, 8; 7, 10; 7, 20; 7, 112; 7, 125; 7, 126; 7, 222; 7, 235; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:retention_data; 13, dictionary; 13, 14; 13, 17; 14, pair; 14, 15; 14, 16; 15, string:'hosts'; 16, dictionary; 17, pair; 17, 18; 17, 19; 18, string:'services'; 19, dictionary; 20, for_statement; 20, 21; 20, 22; 20, 25; 21, identifier:host; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:hosts; 25, block; 25, 26; 25, 30; 25, 31; 25, 39; 25, 50; 25, 102; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:h_dict; 29, dictionary; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:properties; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:host; 37, identifier:__class__; 38, identifier:properties; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:properties; 43, identifier:update; 44, argument_list; 44, 45; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:host; 48, identifier:__class__; 49, identifier:running_properties; 50, for_statement; 50, 51; 50, 54; 50, 62; 51, pattern_list; 51, 52; 51, 53; 52, identifier:prop; 53, identifier:entry; 54, call; 54, 55; 54, 56; 55, identifier:list; 56, argument_list; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:properties; 60, identifier:items; 61, argument_list; 62, block; 62, 63; 62, 70; 62, 78; 62, 79; 62, 85; 62, 96; 63, if_statement; 63, 64; 63, 68; 64, not_operator; 64, 65; 65, attribute; 65, 66; 65, 67; 66, identifier:entry; 67, identifier:retention; 68, block; 68, 69; 69, continue_statement; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:val; 73, call; 73, 74; 73, 75; 74, identifier:getattr; 75, argument_list; 75, 76; 75, 77; 76, identifier:host; 77, identifier:prop; 78, comment; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:prepare_retention; 82, attribute; 82, 83; 82, 84; 83, identifier:entry; 84, identifier:retention_preparation; 85, if_statement; 85, 86; 85, 87; 86, identifier:prepare_retention; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:val; 91, call; 91, 92; 91, 93; 92, identifier:prepare_retention; 93, argument_list; 93, 94; 93, 95; 94, identifier:host; 95, identifier:val; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 101; 98, subscript; 98, 99; 98, 100; 99, identifier:h_dict; 100, identifier:prop; 101, identifier:val; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 111; 104, subscript; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:retention_data; 107, string:'hosts'; 108, attribute; 108, 109; 108, 110; 109, identifier:host; 110, identifier:host_name; 111, identifier:h_dict; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:logger; 116, identifier:info; 117, argument_list; 117, 118; 117, 119; 118, string:'%d hosts sent to retention'; 119, call; 119, 120; 119, 121; 120, identifier:len; 121, argument_list; 121, 122; 122, subscript; 122, 123; 122, 124; 123, identifier:retention_data; 124, string:'hosts'; 125, comment; 126, for_statement; 126, 127; 126, 128; 126, 131; 127, identifier:service; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:services; 131, block; 131, 132; 131, 136; 131, 137; 131, 145; 131, 156; 131, 208; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:s_dict; 135, dictionary; 136, comment; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:properties; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:service; 143, identifier:__class__; 144, identifier:properties; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:properties; 149, identifier:update; 150, argument_list; 150, 151; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:service; 154, identifier:__class__; 155, identifier:running_properties; 156, for_statement; 156, 157; 156, 160; 156, 168; 157, pattern_list; 157, 158; 157, 159; 158, identifier:prop; 159, identifier:entry; 160, call; 160, 161; 160, 162; 161, identifier:list; 162, argument_list; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:properties; 166, identifier:items; 167, argument_list; 168, block; 168, 169; 168, 176; 168, 184; 168, 185; 168, 191; 168, 202; 169, if_statement; 169, 170; 169, 174; 170, not_operator; 170, 171; 171, attribute; 171, 172; 171, 173; 172, identifier:entry; 173, identifier:retention; 174, block; 174, 175; 175, continue_statement; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:val; 179, call; 179, 180; 179, 181; 180, identifier:getattr; 181, argument_list; 181, 182; 181, 183; 182, identifier:service; 183, identifier:prop; 184, comment; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:prepare_retention; 188, attribute; 188, 189; 188, 190; 189, identifier:entry; 190, identifier:retention_preparation; 191, if_statement; 191, 192; 191, 193; 192, identifier:prepare_retention; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:val; 197, call; 197, 198; 197, 199; 198, identifier:prepare_retention; 199, argument_list; 199, 200; 199, 201; 200, identifier:service; 201, identifier:val; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:s_dict; 206, identifier:prop; 207, identifier:val; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 221; 210, subscript; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:retention_data; 213, string:'services'; 214, tuple; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:service; 217, identifier:host_name; 218, attribute; 218, 219; 218, 220; 219, identifier:service; 220, identifier:service_description; 221, identifier:s_dict; 222, expression_statement; 222, 223; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:logger; 226, identifier:info; 227, argument_list; 227, 228; 227, 229; 228, string:'%d services sent to retention'; 229, call; 229, 230; 229, 231; 230, identifier:len; 231, argument_list; 231, 232; 232, subscript; 232, 233; 232, 234; 233, identifier:retention_data; 234, string:'services'; 235, return_statement; 235, 236; 236, identifier:retention_data | def get_retention_data(self): # pylint: disable=too-many-branches,too-many-statements
# pylint: disable=too-many-locals
"""Get all hosts and services data to be sent to the retention storage.
This function only prepares the data because a module is in charge of making
the data survive to the scheduler restart.
todo: Alignak scheduler creates two separate dictionaries: hosts and services
It would be better to merge the services into the host dictionary!
:return: dict containing host and service data
:rtype: dict
"""
retention_data = {
'hosts': {}, 'services': {}
}
for host in self.hosts:
h_dict = {}
# Get the hosts properties and running properties
properties = host.__class__.properties
properties.update(host.__class__.running_properties)
for prop, entry in list(properties.items()):
if not entry.retention:
continue
val = getattr(host, prop)
# If a preparation function exists...
prepare_retention = entry.retention_preparation
if prepare_retention:
val = prepare_retention(host, val)
h_dict[prop] = val
retention_data['hosts'][host.host_name] = h_dict
logger.info('%d hosts sent to retention', len(retention_data['hosts']))
# Same for services
for service in self.services:
s_dict = {}
# Get the services properties and running properties
properties = service.__class__.properties
properties.update(service.__class__.running_properties)
for prop, entry in list(properties.items()):
if not entry.retention:
continue
val = getattr(service, prop)
# If a preparation function exists...
prepare_retention = entry.retention_preparation
if prepare_retention:
val = prepare_retention(service, val)
s_dict[prop] = val
retention_data['services'][(service.host_name, service.service_description)] = s_dict
logger.info('%d services sent to retention', len(retention_data['services']))
return retention_data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 1, 8; 2, function_name:restore_retention_data_item; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:data; 6, identifier:item; 7, comment; 8, block; 8, 9; 8, 11; 8, 12; 8, 20; 8, 31; 8, 91; 8, 92; 8, 140; 8, 141; 8, 147; 8, 148; 8, 149; 8, 238; 8, 239; 8, 272; 8, 301; 8, 302; 8, 303; 8, 304; 8, 310; 8, 316; 8, 354; 8, 360; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:properties; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:item; 18, identifier:__class__; 19, identifier:properties; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:properties; 24, identifier:update; 25, argument_list; 25, 26; 26, attribute; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:item; 29, identifier:__class__; 30, identifier:running_properties; 31, for_statement; 31, 32; 31, 35; 31, 43; 32, pattern_list; 32, 33; 32, 34; 33, identifier:prop; 34, identifier:entry; 35, call; 35, 36; 35, 37; 36, identifier:list; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:properties; 41, identifier:items; 42, argument_list; 43, block; 43, 44; 43, 51; 43, 57; 43, 58; 43, 64; 44, if_statement; 44, 45; 44, 49; 45, not_operator; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:entry; 48, identifier:retention; 49, block; 49, 50; 50, continue_statement; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:not; 52, 53; 52, 54; 53, identifier:prop; 54, identifier:data; 55, block; 55, 56; 56, continue_statement; 57, comment; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:restore_retention; 61, attribute; 61, 62; 61, 63; 62, identifier:entry; 63, identifier:retention_restoration; 64, if_statement; 64, 65; 64, 66; 64, 80; 65, identifier:restore_retention; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:setattr; 70, argument_list; 70, 71; 70, 72; 70, 73; 71, identifier:item; 72, identifier:prop; 73, call; 73, 74; 73, 75; 74, identifier:restore_retention; 75, argument_list; 75, 76; 75, 77; 76, identifier:item; 77, subscript; 77, 78; 77, 79; 78, identifier:data; 79, identifier:prop; 80, else_clause; 80, 81; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, call; 83, 84; 83, 85; 84, identifier:setattr; 85, argument_list; 85, 86; 85, 87; 85, 88; 86, identifier:item; 87, identifier:prop; 88, subscript; 88, 89; 88, 90; 89, identifier:data; 90, identifier:prop; 91, comment; 92, for_statement; 92, 93; 92, 94; 92, 97; 93, identifier:notification_uuid; 94, attribute; 94, 95; 94, 96; 95, identifier:item; 96, identifier:notifications_in_progress; 97, block; 97, 98; 97, 106; 97, 107; 97, 115; 97, 124; 97, 132; 97, 133; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:notification; 101, subscript; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:item; 104, identifier:notifications_in_progress; 105, identifier:notification_uuid; 106, comment; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, subscript; 109, 110; 109, 111; 110, identifier:notification; 111, string:'ref'; 112, attribute; 112, 113; 112, 114; 113, identifier:item; 114, identifier:uuid; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:my_notification; 118, call; 118, 119; 118, 120; 119, identifier:Notification; 120, argument_list; 120, 121; 121, keyword_argument; 121, 122; 121, 123; 122, identifier:params; 123, identifier:notification; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 131; 126, subscript; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:item; 129, identifier:notifications_in_progress; 130, identifier:notification_uuid; 131, identifier:my_notification; 132, comment; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:add; 138, argument_list; 138, 139; 139, identifier:my_notification; 140, comment; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:item; 145, identifier:update_in_checking; 146, argument_list; 147, comment; 148, comment; 149, for_statement; 149, 150; 149, 151; 149, 154; 150, identifier:downtime_uuid; 151, subscript; 151, 152; 151, 153; 152, identifier:data; 153, string:'downtimes'; 154, block; 154, 155; 154, 163; 154, 164; 154, 172; 154, 181; 154, 201; 154, 202; 154, 203; 154, 231; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:downtime; 158, subscript; 158, 159; 158, 162; 159, subscript; 159, 160; 159, 161; 160, identifier:data; 161, string:'downtimes'; 162, identifier:downtime_uuid; 163, comment; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:downtime; 168, string:'ref'; 169, attribute; 169, 170; 169, 171; 170, identifier:item; 171, identifier:uuid; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:my_downtime; 175, call; 175, 176; 175, 177; 176, identifier:Downtime; 177, argument_list; 177, 178; 178, keyword_argument; 178, 179; 178, 180; 179, identifier:params; 180, identifier:downtime; 181, if_statement; 181, 182; 181, 185; 182, subscript; 182, 183; 182, 184; 183, identifier:downtime; 184, string:'comment_id'; 185, block; 185, 186; 186, if_statement; 186, 187; 186, 194; 187, comparison_operator:not; 187, 188; 187, 191; 188, subscript; 188, 189; 188, 190; 189, identifier:downtime; 190, string:'comment_id'; 191, subscript; 191, 192; 191, 193; 192, identifier:data; 193, string:'comments'; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:downtime; 199, string:'comment_id'; 200, string:''; 201, comment; 202, comment; 203, if_statement; 203, 204; 203, 209; 204, comparison_operator:in; 204, 205; 204, 206; 205, string:'uuid'; 206, subscript; 206, 207; 206, 208; 207, identifier:downtime; 208, string:'comment_id'; 209, block; 209, 210; 209, 221; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 217; 212, attribute; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:data; 215, string:'comments'; 216, identifier:append; 217, argument_list; 217, 218; 218, subscript; 218, 219; 218, 220; 219, identifier:downtime; 220, string:'comment_id'; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:downtime; 225, string:'comment_id'; 226, subscript; 226, 227; 226, 230; 227, subscript; 227, 228; 227, 229; 228, identifier:downtime; 229, string:'comment_id'; 230, string:'uuid'; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:item; 235, identifier:add_downtime; 236, argument_list; 236, 237; 237, identifier:my_downtime; 238, comment; 239, for_statement; 239, 240; 239, 241; 239, 244; 240, identifier:comment_uuid; 241, subscript; 241, 242; 241, 243; 242, identifier:data; 243, string:'comments'; 244, block; 244, 245; 244, 253; 244, 254; 244, 262; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:comment; 248, subscript; 248, 249; 248, 252; 249, subscript; 249, 250; 249, 251; 250, identifier:data; 251, string:'comments'; 252, identifier:comment_uuid; 253, comment; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:comment; 258, string:'ref'; 259, attribute; 259, 260; 259, 261; 260, identifier:item; 261, identifier:uuid; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:item; 266, identifier:add_comment; 267, argument_list; 267, 268; 268, call; 268, 269; 268, 270; 269, identifier:Comment; 270, argument_list; 270, 271; 271, identifier:comment; 272, if_statement; 272, 273; 272, 278; 272, 279; 273, comparison_operator:is; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:item; 276, identifier:acknowledgement; 277, None; 278, comment; 279, block; 279, 280; 279, 290; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 287; 282, subscript; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:item; 285, identifier:acknowledgement; 286, string:'ref'; 287, attribute; 287, 288; 287, 289; 288, identifier:item; 289, identifier:uuid; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:item; 294, identifier:acknowledgement; 295, call; 295, 296; 295, 297; 296, identifier:Acknowledge; 297, argument_list; 297, 298; 298, attribute; 298, 299; 298, 300; 299, identifier:item; 300, identifier:acknowledgement; 301, comment; 302, comment; 303, comment; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:new_notified_contacts; 307, call; 307, 308; 307, 309; 308, identifier:set; 309, argument_list; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 313; 312, identifier:new_notified_contacts_ids; 313, call; 313, 314; 313, 315; 314, identifier:set; 315, argument_list; 316, for_statement; 316, 317; 316, 318; 316, 321; 317, identifier:contact_name; 318, attribute; 318, 319; 318, 320; 319, identifier:item; 320, identifier:notified_contacts; 321, block; 321, 322; 321, 333; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:contact; 325, call; 325, 326; 325, 331; 326, attribute; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:self; 329, identifier:contacts; 330, identifier:find_by_name; 331, argument_list; 331, 332; 332, identifier:contact_name; 333, if_statement; 333, 334; 333, 337; 334, comparison_operator:is; 334, 335; 334, 336; 335, identifier:contact; 336, None; 337, block; 337, 338; 337, 345; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:new_notified_contacts; 342, identifier:add; 343, argument_list; 343, 344; 344, identifier:contact_name; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:new_notified_contacts_ids; 349, identifier:add; 350, argument_list; 350, 351; 351, attribute; 351, 352; 351, 353; 352, identifier:contact; 353, identifier:uuid; 354, expression_statement; 354, 355; 355, assignment; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:item; 358, identifier:notified_contacts; 359, identifier:new_notified_contacts; 360, expression_statement; 360, 361; 361, assignment; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:item; 364, identifier:notified_contacts_ids; 365, identifier:new_notified_contacts_ids | def restore_retention_data_item(self, data, item):
# pylint: disable=too-many-branches, too-many-locals
"""
Restore data in item
:param data: retention data of the item
:type data: dict
:param item: host or service item
:type item: alignak.objects.host.Host | alignak.objects.service.Service
:return: None
"""
# Manage the properties and running properties
properties = item.__class__.properties
properties.update(item.__class__.running_properties)
for prop, entry in list(properties.items()):
if not entry.retention:
continue
if prop not in data:
continue
# If a restoration function exists...
restore_retention = entry.retention_restoration
if restore_retention:
setattr(item, prop, restore_retention(item, data[prop]))
else:
setattr(item, prop, data[prop])
# Now manage all linked objects load from/ previous run
for notification_uuid in item.notifications_in_progress:
notification = item.notifications_in_progress[notification_uuid]
# Update the notification referenced object
notification['ref'] = item.uuid
my_notification = Notification(params=notification)
item.notifications_in_progress[notification_uuid] = my_notification
# Add a notification in the scheduler actions
self.add(my_notification)
# todo: is it useful? We do not save/restore checks in the retention data...
item.update_in_checking()
# And also add downtimes and comments
# Downtimes are in a list..
for downtime_uuid in data['downtimes']:
downtime = data['downtimes'][downtime_uuid]
# Update the downtime referenced object
downtime['ref'] = item.uuid
my_downtime = Downtime(params=downtime)
if downtime['comment_id']:
if downtime['comment_id'] not in data['comments']:
downtime['comment_id'] = ''
# case comment_id has comment dict instead uuid
# todo: This should never happen! Why this code ?
if 'uuid' in downtime['comment_id']:
data['comments'].append(downtime['comment_id'])
downtime['comment_id'] = downtime['comment_id']['uuid']
item.add_downtime(my_downtime)
# Comments are in a list..
for comment_uuid in data['comments']:
comment = data['comments'][comment_uuid]
# Update the comment referenced object
comment['ref'] = item.uuid
item.add_comment(Comment(comment))
if item.acknowledgement is not None:
# Update the comment referenced object
item.acknowledgement['ref'] = item.uuid
item.acknowledgement = Acknowledge(item.acknowledgement)
# Relink the notified_contacts as a set() of true contacts objects
# if it was loaded from the retention, it's now a list of contacts
# names
new_notified_contacts = set()
new_notified_contacts_ids = set()
for contact_name in item.notified_contacts:
contact = self.contacts.find_by_name(contact_name)
if contact is not None:
new_notified_contacts.add(contact_name)
new_notified_contacts_ids.add(contact.uuid)
item.notified_contacts = new_notified_contacts
item.notified_contacts_ids = new_notified_contacts_ids |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:fill_initial_broks; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:broker_name; 6, comment; 7, block; 7, 8; 7, 10; 7, 14; 7, 26; 7, 100; 7, 121; 7, 136; 7, 137; 7, 145; 7, 153; 7, 154; 7, 155; 7, 183; 7, 198; 7, 213; 7, 320; 7, 321; 7, 339; 7, 347; 7, 362; 7, 374; 7, 375; 7, 381; 7, 382; 7, 388; 7, 399; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:broker_uuid; 13, None; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:logger; 18, identifier:debug; 19, argument_list; 19, 20; 19, 21; 20, string:"My brokers: %s"; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:my_daemon; 25, identifier:brokers; 26, for_statement; 26, 27; 26, 28; 26, 40; 26, 72; 27, identifier:broker_link; 28, call; 28, 29; 28, 30; 29, identifier:list; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 39; 32, attribute; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:my_daemon; 37, identifier:brokers; 38, identifier:values; 39, argument_list; 40, block; 40, 41; 40, 49; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:logger; 45, identifier:debug; 46, argument_list; 46, 47; 46, 48; 47, string:"Searching broker: %s"; 48, identifier:broker_link; 49, if_statement; 49, 50; 49, 55; 50, comparison_operator:==; 50, 51; 50, 52; 51, identifier:broker_name; 52, attribute; 52, 53; 52, 54; 53, identifier:broker_link; 54, identifier:name; 55, block; 55, 56; 55, 62; 55, 71; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:broker_uuid; 59, attribute; 59, 60; 59, 61; 60, identifier:broker_link; 61, identifier:uuid; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:logger; 66, identifier:info; 67, argument_list; 67, 68; 67, 69; 67, 70; 68, string:"Filling initial broks for: %s (%s)"; 69, identifier:broker_name; 70, identifier:broker_uuid; 71, break_statement; 72, else_clause; 72, 73; 73, block; 73, 74; 73, 98; 74, if_statement; 74, 75; 74, 78; 74, 79; 74, 88; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:pushed_conf; 78, comment; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:logger; 84, identifier:error; 85, argument_list; 85, 86; 85, 87; 86, string:"Requested initial broks for an unknown broker: %s"; 87, identifier:broker_name; 88, else_clause; 88, 89; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:logger; 94, identifier:info; 95, argument_list; 95, 96; 95, 97; 96, string:"Requested initial broks for an unknown broker: %s"; 97, identifier:broker_name; 98, return_statement; 98, 99; 99, integer:0; 100, if_statement; 100, 101; 100, 110; 101, attribute; 101, 102; 101, 109; 102, subscript; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:my_daemon; 107, identifier:brokers; 108, identifier:broker_uuid; 109, identifier:initialized; 110, block; 110, 111; 110, 119; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:logger; 115, identifier:warning; 116, argument_list; 116, 117; 116, 118; 117, string:"The broker %s still got its initial broks..."; 118, identifier:broker_name; 119, return_statement; 119, 120; 120, integer:0; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:initial_broks_count; 124, call; 124, 125; 124, 126; 125, identifier:len; 126, argument_list; 126, 127; 127, attribute; 127, 128; 127, 135; 128, subscript; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:my_daemon; 133, identifier:brokers; 134, identifier:broker_uuid; 135, identifier:broks; 136, comment; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:brok; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:get_program_status_brok; 144, argument_list; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:add_brok; 150, argument_list; 150, 151; 150, 152; 151, identifier:brok; 152, identifier:broker_uuid; 153, comment; 154, comment; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:initial_status_types; 158, tuple; 158, 159; 158, 162; 158, 165; 158, 168; 158, 171; 158, 174; 158, 177; 158, 180; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:timeperiods; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:commands; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:contacts; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:contactgroups; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:hosts; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:hostgroups; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:services; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:servicegroups; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:pushed_conf; 189, identifier:skip_initial_broks; 190, call; 190, 191; 190, 192; 191, identifier:getattr; 192, argument_list; 192, 193; 192, 196; 192, 197; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:pushed_conf; 196, string:'skip_initial_broks'; 197, False; 198, expression_statement; 198, 199; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:logger; 202, identifier:debug; 203, argument_list; 203, 204; 203, 205; 204, string:"Skipping initial broks? %s"; 205, call; 205, 206; 205, 207; 206, identifier:str; 207, argument_list; 207, 208; 208, attribute; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:pushed_conf; 212, identifier:skip_initial_broks; 213, if_statement; 213, 214; 213, 220; 213, 221; 213, 222; 214, not_operator; 214, 215; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:pushed_conf; 219, identifier:skip_initial_broks; 220, comment; 221, comment; 222, block; 222, 223; 222, 266; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:initial_status_types; 226, tuple; 226, 227; 226, 230; 226, 233; 226, 236; 226, 239; 226, 242; 226, 245; 226, 248; 226, 251; 226, 254; 226, 257; 226, 260; 226, 263; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:realms; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:timeperiods; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:commands; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:notificationways; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:contacts; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:contactgroups; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:hosts; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:hostgroups; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:hostdependencies; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:services; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:servicegroups; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:servicedependencies; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:escalations; 266, for_statement; 266, 267; 266, 268; 266, 269; 267, identifier:tab; 268, identifier:initial_status_types; 269, block; 269, 270; 270, for_statement; 270, 271; 270, 272; 270, 273; 270, 274; 270, 275; 271, identifier:item; 272, identifier:tab; 273, comment; 274, comment; 275, block; 275, 276; 275, 280; 275, 303; 275, 312; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:member_items; 279, None; 280, if_statement; 280, 281; 280, 286; 281, call; 281, 282; 281, 283; 282, identifier:hasattr; 283, argument_list; 283, 284; 283, 285; 284, identifier:item; 285, string:'members'; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:member_items; 290, call; 290, 291; 290, 292; 291, identifier:getattr; 292, argument_list; 292, 293; 292, 294; 293, identifier:self; 294, call; 294, 295; 294, 300; 295, attribute; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:item; 298, identifier:my_type; 299, identifier:replace; 300, argument_list; 300, 301; 300, 302; 301, string:"group"; 302, string:"s"; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 306; 305, identifier:brok; 306, call; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:item; 309, identifier:get_initial_status_brok; 310, argument_list; 310, 311; 311, identifier:member_items; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:self; 316, identifier:add_brok; 317, argument_list; 317, 318; 317, 319; 318, identifier:brok; 319, identifier:broker_uuid; 320, comment; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:brok; 324, call; 324, 325; 324, 326; 325, identifier:Brok; 326, argument_list; 326, 327; 327, dictionary; 327, 328; 327, 331; 328, pair; 328, 329; 328, 330; 329, string:'type'; 330, string:'initial_broks_done'; 331, pair; 331, 332; 331, 333; 332, string:'data'; 333, dictionary; 333, 334; 334, pair; 334, 335; 334, 336; 335, string:'instance_id'; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:instance_id; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:self; 343, identifier:add_brok; 344, argument_list; 344, 345; 344, 346; 345, identifier:brok; 346, identifier:broker_uuid; 347, expression_statement; 347, 348; 348, assignment; 348, 349; 348, 350; 349, identifier:final_broks_count; 350, call; 350, 351; 350, 352; 351, identifier:len; 352, argument_list; 352, 353; 353, attribute; 353, 354; 353, 361; 354, subscript; 354, 355; 354, 360; 355, attribute; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:my_daemon; 359, identifier:brokers; 360, identifier:broker_uuid; 361, identifier:broks; 362, expression_statement; 362, 363; 363, assignment; 363, 364; 363, 373; 364, attribute; 364, 365; 364, 372; 365, subscript; 365, 366; 365, 371; 366, attribute; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:self; 369, identifier:my_daemon; 370, identifier:brokers; 371, identifier:broker_uuid; 372, identifier:initialized; 373, True; 374, comment; 375, expression_statement; 375, 376; 376, call; 376, 377; 376, 380; 377, attribute; 377, 378; 377, 379; 378, identifier:self; 379, identifier:send_broks_to_modules; 380, argument_list; 381, comment; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:self; 386, identifier:raised_initial_broks; 387, True; 388, expression_statement; 388, 389; 389, call; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:logger; 392, identifier:info; 393, argument_list; 393, 394; 393, 395; 393, 398; 394, string:"Created %d initial broks for %s"; 395, binary_operator:-; 395, 396; 395, 397; 396, identifier:final_broks_count; 397, identifier:initial_broks_count; 398, identifier:broker_name; 399, return_statement; 399, 400; 400, binary_operator:-; 400, 401; 400, 402; 401, identifier:final_broks_count; 402, identifier:initial_broks_count | def fill_initial_broks(self, broker_name):
# pylint: disable=too-many-branches
"""Create initial broks for a specific broker
:param broker_name: broker name
:type broker_name: str
:return: number of created broks
"""
broker_uuid = None
logger.debug("My brokers: %s", self.my_daemon.brokers)
for broker_link in list(self.my_daemon.brokers.values()):
logger.debug("Searching broker: %s", broker_link)
if broker_name == broker_link.name:
broker_uuid = broker_link.uuid
logger.info("Filling initial broks for: %s (%s)", broker_name, broker_uuid)
break
else:
if self.pushed_conf:
# I am yet configured but I do not know this broker ! Something went wrong!!!
logger.error("Requested initial broks for an unknown broker: %s", broker_name)
else:
logger.info("Requested initial broks for an unknown broker: %s", broker_name)
return 0
if self.my_daemon.brokers[broker_uuid].initialized:
logger.warning("The broker %s still got its initial broks...", broker_name)
return 0
initial_broks_count = len(self.my_daemon.brokers[broker_uuid].broks)
# First the program status
brok = self.get_program_status_brok()
self.add_brok(brok, broker_uuid)
# We can't call initial_status from all this types
# The order is important, service need host...
initial_status_types = (self.timeperiods, self.commands,
self.contacts, self.contactgroups,
self.hosts, self.hostgroups,
self.services, self.servicegroups)
self.pushed_conf.skip_initial_broks = getattr(self.pushed_conf, 'skip_initial_broks', False)
logger.debug("Skipping initial broks? %s", str(self.pushed_conf.skip_initial_broks))
if not self.pushed_conf.skip_initial_broks:
# We call initial_status from all this types
# The order is important, service need host...
initial_status_types = (self.realms, self.timeperiods, self.commands,
self.notificationways, self.contacts, self.contactgroups,
self.hosts, self.hostgroups, self.hostdependencies,
self.services, self.servicegroups, self.servicedependencies,
self.escalations)
for tab in initial_status_types:
for item in tab:
# Awful! simply to get the group members property name... :(
# todo: replace this!
member_items = None
if hasattr(item, 'members'):
member_items = getattr(self, item.my_type.replace("group", "s"))
brok = item.get_initial_status_brok(member_items)
self.add_brok(brok, broker_uuid)
# Add a brok to say that we finished all initial_pass
brok = Brok({'type': 'initial_broks_done', 'data': {'instance_id': self.instance_id}})
self.add_brok(brok, broker_uuid)
final_broks_count = len(self.my_daemon.brokers[broker_uuid].broks)
self.my_daemon.brokers[broker_uuid].initialized = True
# Send the initial broks to our modules
self.send_broks_to_modules()
# We now have raised all the initial broks
self.raised_initial_broks = True
logger.info("Created %d initial broks for %s",
final_broks_count - initial_broks_count, broker_name)
return final_broks_count - initial_broks_count |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 2, function_name:consume_results; 3, parameters; 3, 4; 4, identifier:self; 5, comment; 6, block; 6, 7; 6, 9; 6, 10; 6, 11; 6, 21; 6, 41; 6, 42; 6, 173; 6, 174; 6, 178; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:queue_size; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:waiting_results; 19, identifier:qsize; 20, argument_list; 21, for_statement; 21, 22; 21, 23; 21, 27; 22, identifier:_; 23, call; 23, 24; 23, 25; 24, identifier:range; 25, argument_list; 25, 26; 26, identifier:queue_size; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:manage_results; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:waiting_results; 39, identifier:get; 40, argument_list; 41, comment; 42, for_statement; 42, 43; 42, 44; 42, 54; 43, identifier:chk; 44, call; 44, 45; 44, 46; 45, identifier:list; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:checks; 52, identifier:values; 53, argument_list; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 61; 56, comparison_operator:==; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:chk; 59, identifier:status; 60, identifier:ACT_STATUS_WAIT_CONSUME; 61, block; 61, 62; 61, 70; 61, 81; 61, 85; 61, 105; 61, 149; 61, 150; 61, 151; 61, 152; 61, 153; 61, 154; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:logger; 66, identifier:debug; 67, argument_list; 67, 68; 67, 69; 68, string:"Consuming: %s"; 69, identifier:chk; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:item; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:find_item_by_id; 77, argument_list; 77, 78; 78, attribute; 78, 79; 78, 80; 79, identifier:chk; 80, identifier:ref; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:notification_period; 84, None; 85, if_statement; 85, 86; 85, 94; 86, comparison_operator:is; 86, 87; 86, 93; 87, call; 87, 88; 87, 89; 88, identifier:getattr; 89, argument_list; 89, 90; 89, 91; 89, 92; 90, identifier:item; 91, string:'notification_period'; 92, None; 93, None; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:notification_period; 98, subscript; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:timeperiods; 102, attribute; 102, 103; 102, 104; 103, identifier:item; 104, identifier:notification_period; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:dep_checks; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:item; 111, identifier:consume_result; 112, argument_list; 112, 113; 112, 114; 112, 115; 112, 118; 112, 121; 112, 124; 112, 127; 112, 130; 112, 133; 112, 136; 112, 139; 113, identifier:chk; 114, identifier:notification_period; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:hosts; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:services; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:timeperiods; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:macromodulations; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:checkmodulations; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:businessimpactmodulations; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:resultmodulations; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:checks; 139, boolean_operator:and; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:pushed_conf; 144, identifier:log_active_checks; 145, not_operator; 145, 146; 146, attribute; 146, 147; 146, 148; 147, identifier:chk; 148, identifier:passive_check; 149, comment; 150, comment; 151, comment; 152, comment; 153, comment; 154, for_statement; 154, 155; 154, 156; 154, 157; 155, identifier:check; 156, identifier:dep_checks; 157, block; 157, 158; 157, 166; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:logger; 162, identifier:debug; 163, argument_list; 163, 164; 163, 165; 164, string:"-> raised a dependency check: %s"; 165, identifier:chk; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:add; 171, argument_list; 171, 172; 172, identifier:check; 173, comment; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:have_resolved_checks; 177, True; 178, while_statement; 178, 179; 178, 180; 179, identifier:have_resolved_checks; 180, block; 180, 181; 180, 185; 180, 186; 180, 235; 180, 236; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:have_resolved_checks; 184, False; 185, comment; 186, for_statement; 186, 187; 186, 188; 186, 198; 187, identifier:chk; 188, call; 188, 189; 188, 190; 189, identifier:list; 190, argument_list; 190, 191; 191, call; 191, 192; 191, 197; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:checks; 196, identifier:values; 197, argument_list; 198, block; 198, 199; 199, if_statement; 199, 200; 199, 205; 200, comparison_operator:==; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:chk; 203, identifier:status; 204, identifier:ACT_STATUS_WAITING_ME; 205, block; 205, 206; 205, 228; 205, 229; 206, for_statement; 206, 207; 206, 208; 206, 211; 206, 212; 207, identifier:dependent_checks; 208, attribute; 208, 209; 208, 210; 209, identifier:chk; 210, identifier:depend_on_me; 211, comment; 212, block; 212, 213; 212, 224; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 220; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:dependent_checks; 218, identifier:depend_on; 219, identifier:remove; 220, argument_list; 220, 221; 221, attribute; 221, 222; 221, 223; 222, identifier:chk; 223, identifier:uuid; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:have_resolved_checks; 227, True; 228, comment; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:chk; 233, identifier:status; 234, identifier:ACT_STATUS_ZOMBIE; 235, comment; 236, for_statement; 236, 237; 236, 238; 236, 248; 237, identifier:chk; 238, call; 238, 239; 238, 240; 239, identifier:list; 240, argument_list; 240, 241; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:checks; 246, identifier:values; 247, argument_list; 248, block; 248, 249; 249, if_statement; 249, 250; 249, 260; 250, boolean_operator:and; 250, 251; 250, 256; 251, comparison_operator:==; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:chk; 254, identifier:status; 255, identifier:ACT_STATUS_WAIT_DEPEND; 256, not_operator; 256, 257; 257, attribute; 257, 258; 257, 259; 258, identifier:chk; 259, identifier:depend_on; 260, block; 260, 261; 260, 272; 260, 276; 260, 296; 260, 340; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:item; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:find_item_by_id; 268, argument_list; 268, 269; 269, attribute; 269, 270; 269, 271; 270, identifier:chk; 271, identifier:ref; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:notification_period; 275, None; 276, if_statement; 276, 277; 276, 285; 277, comparison_operator:is; 277, 278; 277, 284; 278, call; 278, 279; 278, 280; 279, identifier:getattr; 280, argument_list; 280, 281; 280, 282; 280, 283; 281, identifier:item; 282, string:'notification_period'; 283, None; 284, None; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:notification_period; 289, subscript; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:self; 292, identifier:timeperiods; 293, attribute; 293, 294; 293, 295; 294, identifier:item; 295, identifier:notification_period; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:dep_checks; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:item; 302, identifier:consume_result; 303, argument_list; 303, 304; 303, 305; 303, 306; 303, 309; 303, 312; 303, 315; 303, 318; 303, 321; 303, 324; 303, 327; 303, 330; 304, identifier:chk; 305, identifier:notification_period; 306, attribute; 306, 307; 306, 308; 307, identifier:self; 308, identifier:hosts; 309, attribute; 309, 310; 309, 311; 310, identifier:self; 311, identifier:services; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:timeperiods; 315, attribute; 315, 316; 315, 317; 316, identifier:self; 317, identifier:macromodulations; 318, attribute; 318, 319; 318, 320; 319, identifier:self; 320, identifier:checkmodulations; 321, attribute; 321, 322; 321, 323; 322, identifier:self; 323, identifier:businessimpactmodulations; 324, attribute; 324, 325; 324, 326; 325, identifier:self; 326, identifier:resultmodulations; 327, attribute; 327, 328; 327, 329; 328, identifier:self; 329, identifier:checks; 330, boolean_operator:and; 330, 331; 330, 336; 331, attribute; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:self; 334, identifier:pushed_conf; 335, identifier:log_active_checks; 336, not_operator; 336, 337; 337, attribute; 337, 338; 337, 339; 338, identifier:chk; 339, identifier:passive_check; 340, for_statement; 340, 341; 340, 342; 340, 343; 341, identifier:check; 342, identifier:dep_checks; 343, block; 343, 344; 344, expression_statement; 344, 345; 345, call; 345, 346; 345, 349; 346, attribute; 346, 347; 346, 348; 347, identifier:self; 348, identifier:add; 349, argument_list; 349, 350; 350, identifier:check | def consume_results(self): # pylint: disable=too-many-branches
"""Handle results waiting in waiting_results list.
Check ref will call consume result and update their status
:return: None
"""
# All results are in self.waiting_results
# We need to get them first
queue_size = self.waiting_results.qsize()
for _ in range(queue_size):
self.manage_results(self.waiting_results.get())
# Then we consume them
for chk in list(self.checks.values()):
if chk.status == ACT_STATUS_WAIT_CONSUME:
logger.debug("Consuming: %s", chk)
item = self.find_item_by_id(chk.ref)
notification_period = None
if getattr(item, 'notification_period', None) is not None:
notification_period = self.timeperiods[item.notification_period]
dep_checks = item.consume_result(chk, notification_period, self.hosts,
self.services, self.timeperiods,
self.macromodulations, self.checkmodulations,
self.businessimpactmodulations,
self.resultmodulations, self.checks,
self.pushed_conf.log_active_checks and
not chk.passive_check)
# # Raise the log only when the check got consumed!
# # Else the item information are not up-to-date :/
# if self.pushed_conf.log_active_checks and not chk.passive_check:
# item.raise_check_result()
#
for check in dep_checks:
logger.debug("-> raised a dependency check: %s", chk)
self.add(check)
# loop to resolve dependencies
have_resolved_checks = True
while have_resolved_checks:
have_resolved_checks = False
# All 'finished' checks (no more dep) raise checks they depend on
for chk in list(self.checks.values()):
if chk.status == ACT_STATUS_WAITING_ME:
for dependent_checks in chk.depend_on_me:
# Ok, now dependent will no more wait
dependent_checks.depend_on.remove(chk.uuid)
have_resolved_checks = True
# REMOVE OLD DEP CHECK -> zombie
chk.status = ACT_STATUS_ZOMBIE
# Now, reinteger dep checks
for chk in list(self.checks.values()):
if chk.status == ACT_STATUS_WAIT_DEPEND and not chk.depend_on:
item = self.find_item_by_id(chk.ref)
notification_period = None
if getattr(item, 'notification_period', None) is not None:
notification_period = self.timeperiods[item.notification_period]
dep_checks = item.consume_result(chk, notification_period, self.hosts,
self.services, self.timeperiods,
self.macromodulations, self.checkmodulations,
self.businessimpactmodulations,
self.resultmodulations, self.checks,
self.pushed_conf.log_active_checks and
not chk.passive_check)
for check in dep_checks:
self.add(check) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:send_broks_to_modules; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 20; 5, 24; 5, 67; 5, 72; 5, 83; 5, 145; 5, 146; 5, 188; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:t00; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:time; 14, identifier:time; 15, argument_list; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:nb_sent; 19, integer:0; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:broks; 23, list:[]; 24, for_statement; 24, 25; 24, 26; 24, 38; 25, identifier:broker_link; 26, call; 26, 27; 26, 28; 27, identifier:list; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 37; 30, attribute; 30, 31; 30, 36; 31, attribute; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:my_daemon; 35, identifier:brokers; 36, identifier:values; 37, argument_list; 38, block; 38, 39; 39, for_statement; 39, 40; 39, 41; 39, 44; 40, identifier:brok; 41, attribute; 41, 42; 41, 43; 42, identifier:broker_link; 43, identifier:broks; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 53; 46, not_operator; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:getattr; 49, argument_list; 49, 50; 49, 51; 49, 52; 50, identifier:brok; 51, string:'sent_to_externals'; 52, False; 53, block; 53, 54; 53, 60; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:brok; 58, identifier:to_send; 59, True; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:broks; 64, identifier:append; 65, argument_list; 65, 66; 66, identifier:brok; 67, if_statement; 67, 68; 67, 70; 68, not_operator; 68, 69; 69, identifier:broks; 70, block; 70, 71; 71, return_statement; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:logger; 76, identifier:debug; 77, argument_list; 77, 78; 77, 79; 78, string:"sending %d broks to modules..."; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, identifier:broks; 83, for_statement; 83, 84; 83, 85; 83, 94; 84, identifier:mod; 85, call; 85, 86; 85, 93; 86, attribute; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:my_daemon; 91, identifier:modules_manager; 92, identifier:get_external_instances; 93, argument_list; 94, block; 94, 95; 94, 107; 94, 113; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:logger; 99, identifier:debug; 100, argument_list; 100, 101; 100, 102; 101, string:"Look for sending to module %s"; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:mod; 105, identifier:get_name; 106, argument_list; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:module_queue; 110, attribute; 110, 111; 110, 112; 111, identifier:mod; 112, identifier:to_q; 113, if_statement; 113, 114; 113, 115; 114, identifier:module_queue; 115, block; 115, 116; 115, 131; 115, 138; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:to_send; 119, list_comprehension; 119, 120; 119, 121; 119, 124; 120, identifier:b; 121, for_in_clause; 121, 122; 121, 123; 122, identifier:b; 123, identifier:broks; 124, if_clause; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:mod; 128, identifier:want_brok; 129, argument_list; 129, 130; 130, identifier:b; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:module_queue; 135, identifier:put; 136, argument_list; 136, 137; 137, identifier:to_send; 138, expression_statement; 138, 139; 139, augmented_assignment:+=; 139, 140; 139, 141; 140, identifier:nb_sent; 141, call; 141, 142; 141, 143; 142, identifier:len; 143, argument_list; 143, 144; 144, identifier:to_send; 145, comment; 146, for_statement; 146, 147; 146, 148; 146, 160; 147, identifier:broker_link; 148, call; 148, 149; 148, 150; 149, identifier:list; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 159; 152, attribute; 152, 153; 152, 158; 153, attribute; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:my_daemon; 157, identifier:brokers; 158, identifier:values; 159, argument_list; 160, block; 160, 161; 161, for_statement; 161, 162; 161, 163; 161, 166; 162, identifier:brok; 163, attribute; 163, 164; 163, 165; 164, identifier:broker_link; 165, identifier:broks; 166, block; 166, 167; 167, if_statement; 167, 168; 167, 175; 168, not_operator; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:getattr; 171, argument_list; 171, 172; 171, 173; 171, 174; 172, identifier:brok; 173, string:'sent_to_externals'; 174, False; 175, block; 175, 176; 175, 182; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:brok; 180, identifier:to_send; 181, False; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:brok; 186, identifier:sent_to_externals; 187, True; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:logger; 192, identifier:debug; 193, argument_list; 193, 194; 193, 195; 193, 196; 194, string:"Time to send %d broks (after %d secs)"; 195, identifier:nb_sent; 196, binary_operator:-; 196, 197; 196, 202; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:time; 200, identifier:time; 201, argument_list; 202, identifier:t00 | def send_broks_to_modules(self):
"""Put broks into module queues
Only broks without sent_to_externals to True are sent
Only modules that ask for broks will get some
:return: None
"""
t00 = time.time()
nb_sent = 0
broks = []
for broker_link in list(self.my_daemon.brokers.values()):
for brok in broker_link.broks:
if not getattr(brok, 'sent_to_externals', False):
brok.to_send = True
broks.append(brok)
if not broks:
return
logger.debug("sending %d broks to modules...", len(broks))
for mod in self.my_daemon.modules_manager.get_external_instances():
logger.debug("Look for sending to module %s", mod.get_name())
module_queue = mod.to_q
if module_queue:
to_send = [b for b in broks if mod.want_brok(b)]
module_queue.put(to_send)
nb_sent += len(to_send)
# No more need to send them
for broker_link in list(self.my_daemon.brokers.values()):
for brok in broker_link.broks:
if not getattr(brok, 'sent_to_externals', False):
brok.to_send = False
brok.sent_to_externals = True
logger.debug("Time to send %d broks (after %d secs)", nb_sent, time.time() - t00) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:push_external_commands_to_schedulers; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 16; 5, 22; 5, 28; 5, 36; 5, 37; 5, 48; 5, 101; 5, 102; 5, 106; 5, 110; 5, 281; 5, 289; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 13; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:unprocessed_external_commands; 13, block; 13, 14; 14, return_statement; 15, comment; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:commands_to_process; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:unprocessed_external_commands; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:unprocessed_external_commands; 27, list:[]; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:logger; 32, identifier:debug; 33, argument_list; 33, 34; 33, 35; 34, string:"Commands: %s"; 35, identifier:commands_to_process; 36, comment; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:logger; 41, identifier:debug; 42, argument_list; 42, 43; 42, 44; 43, string:"Commands to process: %d commands"; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:commands_to_process; 48, for_statement; 48, 49; 48, 50; 48, 51; 49, identifier:ext_cmd; 50, identifier:commands_to_process; 51, block; 51, 52; 51, 63; 51, 74; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:cmd; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:external_commands_manager; 60, identifier:resolve_command; 61, argument_list; 61, 62; 62, identifier:ext_cmd; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:logger; 67, identifier:debug; 68, argument_list; 68, 69; 68, 70; 68, 73; 69, string:"Resolved command: %s, result: %s"; 70, attribute; 70, 71; 70, 72; 71, identifier:ext_cmd; 72, identifier:cmd_line; 73, identifier:cmd; 74, if_statement; 74, 75; 74, 80; 74, 81; 75, boolean_operator:and; 75, 76; 75, 77; 76, identifier:cmd; 77, subscript; 77, 78; 77, 79; 78, identifier:cmd; 79, string:'global'; 80, comment; 81, block; 81, 82; 82, for_statement; 82, 83; 82, 84; 82, 87; 83, identifier:scheduler_link_uuid; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:schedulers; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 99; 90, attribute; 90, 91; 90, 98; 91, attribute; 91, 92; 91, 97; 92, subscript; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:schedulers; 96, identifier:scheduler_link_uuid; 97, identifier:pushed_commands; 98, identifier:append; 99, argument_list; 99, 100; 100, identifier:ext_cmd; 101, comment; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:count_pushed_commands; 105, integer:0; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:count_failed_commands; 109, integer:0; 110, for_statement; 110, 111; 110, 112; 110, 115; 111, identifier:scheduler_link_uuid; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:schedulers; 115, block; 115, 116; 115, 124; 115, 143; 115, 144; 115, 156; 115, 171; 115, 185; 115, 189; 115, 210; 115, 211; 115, 217; 115, 218; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:link; 119, subscript; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:schedulers; 123, identifier:scheduler_link_uuid; 124, if_statement; 124, 125; 124, 129; 125, not_operator; 125, 126; 126, attribute; 126, 127; 126, 128; 127, identifier:link; 128, identifier:active; 129, block; 129, 130; 129, 142; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:logger; 134, identifier:debug; 135, argument_list; 135, 136; 135, 139; 136, concatenated_string; 136, 137; 136, 138; 137, string:"The scheduler '%s' is not active, it is not possible to push "; 138, string:"external commands to its connection!"; 139, attribute; 139, 140; 139, 141; 140, identifier:link; 141, identifier:name; 142, continue_statement; 143, comment; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:commands; 147, list_comprehension; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:ext_cmd; 150, identifier:cmd_line; 151, for_in_clause; 151, 152; 151, 153; 152, identifier:ext_cmd; 153, attribute; 153, 154; 153, 155; 154, identifier:link; 155, identifier:pushed_commands; 156, if_statement; 156, 157; 156, 159; 157, not_operator; 157, 158; 158, identifier:commands; 159, block; 159, 160; 159, 170; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:logger; 164, identifier:debug; 165, argument_list; 165, 166; 165, 167; 166, string:"The scheduler '%s' has no commands."; 167, attribute; 167, 168; 167, 169; 168, identifier:link; 169, identifier:name; 170, continue_statement; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:logger; 175, identifier:debug; 176, argument_list; 176, 177; 176, 178; 176, 182; 177, string:"Sending %d commands to scheduler %s"; 178, call; 178, 179; 178, 180; 179, identifier:len; 180, argument_list; 180, 181; 181, identifier:commands; 182, attribute; 182, 183; 182, 184; 183, identifier:link; 184, identifier:name; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:sent; 188, list:[]; 189, try_statement; 189, 190; 189, 200; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:sent; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:link; 197, identifier:push_external_commands; 198, argument_list; 198, 199; 199, identifier:commands; 200, except_clause; 200, 201; 200, 202; 201, identifier:LinkError; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:logger; 207, identifier:warning; 208, argument_list; 208, 209; 209, string:"Scheduler connection failed, I could not push external commands!"; 210, comment; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:link; 215, identifier:pushed_commands; 216, list:[]; 217, comment; 218, if_statement; 218, 219; 218, 220; 218, 245; 219, identifier:sent; 220, block; 220, 221; 220, 236; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:statsmgr; 225, identifier:gauge; 226, argument_list; 226, 227; 226, 232; 227, binary_operator:%; 227, 228; 227, 229; 228, string:'external-commands.pushed.%s'; 229, attribute; 229, 230; 229, 231; 230, identifier:link; 231, identifier:name; 232, call; 232, 233; 232, 234; 233, identifier:len; 234, argument_list; 234, 235; 235, identifier:commands; 236, expression_statement; 236, 237; 237, assignment; 237, 238; 237, 239; 238, identifier:count_pushed_commands; 239, binary_operator:+; 239, 240; 239, 241; 240, identifier:count_pushed_commands; 241, call; 241, 242; 241, 243; 242, identifier:len; 243, argument_list; 243, 244; 244, identifier:commands; 245, else_clause; 245, 246; 246, block; 246, 247; 246, 256; 246, 271; 246, 272; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:count_failed_commands; 250, binary_operator:+; 250, 251; 250, 252; 251, identifier:count_failed_commands; 252, call; 252, 253; 252, 254; 253, identifier:len; 254, argument_list; 254, 255; 255, identifier:commands; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:statsmgr; 260, identifier:gauge; 261, argument_list; 261, 262; 261, 267; 262, binary_operator:%; 262, 263; 262, 264; 263, string:'external-commands.failed.%s'; 264, attribute; 264, 265; 264, 266; 265, identifier:link; 266, identifier:name; 267, call; 267, 268; 267, 269; 268, identifier:len; 269, argument_list; 269, 270; 270, identifier:commands; 271, comment; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 279; 274, attribute; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:external_commands; 278, identifier:extend; 279, argument_list; 279, 280; 280, identifier:commands; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:statsmgr; 285, identifier:gauge; 286, argument_list; 286, 287; 286, 288; 287, string:'external-commands.pushed.all'; 288, identifier:count_pushed_commands; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:statsmgr; 293, identifier:gauge; 294, argument_list; 294, 295; 294, 296; 295, string:'external-commands.failed.all'; 296, identifier:count_failed_commands | def push_external_commands_to_schedulers(self):
"""Push received external commands to the schedulers
:return: None
"""
if not self.unprocessed_external_commands:
return
# Those are the global external commands
commands_to_process = self.unprocessed_external_commands
self.unprocessed_external_commands = []
logger.debug("Commands: %s", commands_to_process)
# Now get all external commands and put them into the good schedulers
logger.debug("Commands to process: %d commands", len(commands_to_process))
for ext_cmd in commands_to_process:
cmd = self.external_commands_manager.resolve_command(ext_cmd)
logger.debug("Resolved command: %s, result: %s", ext_cmd.cmd_line, cmd)
if cmd and cmd['global']:
# Send global command to all our schedulers
for scheduler_link_uuid in self.schedulers:
self.schedulers[scheduler_link_uuid].pushed_commands.append(ext_cmd)
# Now for all active schedulers, send the commands
count_pushed_commands = 0
count_failed_commands = 0
for scheduler_link_uuid in self.schedulers:
link = self.schedulers[scheduler_link_uuid]
if not link.active:
logger.debug("The scheduler '%s' is not active, it is not possible to push "
"external commands to its connection!", link.name)
continue
# If there are some commands for this scheduler...
commands = [ext_cmd.cmd_line for ext_cmd in link.pushed_commands]
if not commands:
logger.debug("The scheduler '%s' has no commands.", link.name)
continue
logger.debug("Sending %d commands to scheduler %s", len(commands), link.name)
sent = []
try:
sent = link.push_external_commands(commands)
except LinkError:
logger.warning("Scheduler connection failed, I could not push external commands!")
# Whether we sent the commands or not, clean the scheduler list
link.pushed_commands = []
# If we didn't sent them, add the commands to the arbiter list
if sent:
statsmgr.gauge('external-commands.pushed.%s' % link.name, len(commands))
count_pushed_commands = count_pushed_commands + len(commands)
else:
count_failed_commands = count_failed_commands + len(commands)
statsmgr.gauge('external-commands.failed.%s' % link.name, len(commands))
# Kepp the not sent commands... for a next try
self.external_commands.extend(commands)
statsmgr.gauge('external-commands.pushed.all', count_pushed_commands)
statsmgr.gauge('external-commands.failed.all', count_failed_commands) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_groupnames; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:hostgroups; 6, block; 6, 7; 6, 9; 6, 13; 6, 36; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:group_names; 12, list:[]; 13, for_statement; 13, 14; 13, 15; 13, 18; 14, identifier:hostgroup_id; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:hostgroups; 18, block; 18, 19; 18, 25; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:hostgroup; 22, subscript; 22, 23; 22, 24; 23, identifier:hostgroups; 24, identifier:hostgroup_id; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:group_names; 29, identifier:append; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:hostgroup; 34, identifier:get_name; 35, argument_list; 36, return_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, string:','; 40, identifier:join; 41, argument_list; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:sorted; 44, argument_list; 44, 45; 45, identifier:group_names | def get_groupnames(self, hostgroups):
"""Get names of the host's hostgroups
:return: comma separated names of hostgroups alphabetically sorted
:rtype: str
"""
group_names = []
for hostgroup_id in self.hostgroups:
hostgroup = hostgroups[hostgroup_id]
group_names.append(hostgroup.get_name())
return ','.join(sorted(group_names)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_groupaliases; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:hostgroups; 6, block; 6, 7; 6, 9; 6, 13; 6, 34; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:group_aliases; 12, list:[]; 13, for_statement; 13, 14; 13, 15; 13, 18; 14, identifier:hostgroup_id; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:hostgroups; 18, block; 18, 19; 18, 25; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:hostgroup; 22, subscript; 22, 23; 22, 24; 23, identifier:hostgroups; 24, identifier:hostgroup_id; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:group_aliases; 29, identifier:append; 30, argument_list; 30, 31; 31, attribute; 31, 32; 31, 33; 32, identifier:hostgroup; 33, identifier:alias; 34, return_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, string:','; 38, identifier:join; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:sorted; 42, argument_list; 42, 43; 43, identifier:group_aliases | def get_groupaliases(self, hostgroups):
"""Get aliases of the host's hostgroups
:return: comma separated aliases of hostgroups alphabetically sorted
:rtype: str
"""
group_aliases = []
for hostgroup_id in self.hostgroups:
hostgroup = hostgroups[hostgroup_id]
group_aliases.append(hostgroup.alias)
return ','.join(sorted(group_aliases)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_overall_state; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:services; 6, block; 6, 7; 6, 9; 6, 13; 6, 70; 6, 71; 6, 111; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:overall_state; 12, integer:0; 13, if_statement; 13, 14; 13, 18; 13, 23; 13, 32; 13, 41; 14, not_operator; 14, 15; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:monitored; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:overall_state; 22, integer:5; 23, elif_clause; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:acknowledged; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:overall_state; 31, integer:1; 32, elif_clause; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:downtimed; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:overall_state; 40, integer:2; 41, elif_clause; 41, 42; 41, 47; 42, comparison_operator:==; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:state_type; 46, string:'HARD'; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 54; 48, 59; 49, comparison_operator:==; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:state; 53, string:'UNREACHABLE'; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:overall_state; 58, integer:3; 59, elif_clause; 59, 60; 59, 65; 60, comparison_operator:==; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:state; 64, string:'DOWN'; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:overall_state; 69, integer:4; 70, comment; 71, if_statement; 71, 72; 71, 75; 72, comparison_operator:<=; 72, 73; 72, 74; 73, identifier:overall_state; 74, integer:2; 75, block; 75, 76; 76, for_statement; 76, 77; 76, 78; 76, 81; 77, identifier:service; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:services; 81, block; 81, 82; 82, if_statement; 82, 83; 82, 86; 83, comparison_operator:in; 83, 84; 83, 85; 84, identifier:service; 85, identifier:services; 86, block; 86, 87; 86, 93; 86, 94; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:service; 90, subscript; 90, 91; 90, 92; 91, identifier:services; 92, identifier:service; 93, comment; 94, if_statement; 94, 95; 94, 100; 95, comparison_operator:<; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:service; 98, identifier:overall_state_id; 99, integer:5; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:overall_state; 104, call; 104, 105; 104, 106; 105, identifier:max; 106, argument_list; 106, 107; 106, 108; 107, identifier:overall_state; 108, attribute; 108, 109; 108, 110; 109, identifier:service; 110, identifier:overall_state_id; 111, return_statement; 111, 112; 112, identifier:overall_state | def get_overall_state(self, services):
"""Get the host overall state including the host self status
and the status of its services
Compute the host overall state identifier, including:
- the acknowledged state
- the downtime state
The host overall state is (prioritized):
- an host not monitored (5)
- an host down (4)
- an host unreachable (3)
- an host downtimed (2)
- an host acknowledged (1)
- an host up (0)
If the host overall state is <= 2, then the host overall state is the maximum value
of the host overall state and all the host services overall states.
The overall state of an host is:
- 0 if the host is UP and all its services are OK
- 1 if the host is DOWN or UNREACHABLE and acknowledged or
at least one of its services is acknowledged and
no other services are WARNING or CRITICAL
- 2 if the host is DOWN or UNREACHABLE and in a scheduled downtime or
at least one of its services is in a scheduled downtime and no
other services are WARNING or CRITICAL
- 3 if the host is UNREACHABLE or
at least one of its services is WARNING
- 4 if the host is DOWN or
at least one of its services is CRITICAL
- 5 if the host is not monitored
:param services: a list of known services
:type services: alignak.objects.service.Services
:return: the host overall state
:rtype: int
"""
overall_state = 0
if not self.monitored:
overall_state = 5
elif self.acknowledged:
overall_state = 1
elif self.downtimed:
overall_state = 2
elif self.state_type == 'HARD':
if self.state == 'UNREACHABLE':
overall_state = 3
elif self.state == 'DOWN':
overall_state = 4
# Only consider the hosts services state if all is ok (or almost...)
if overall_state <= 2:
for service in self.services:
if service in services:
service = services[service]
# Only for monitored services
if service.overall_state_id < 5:
overall_state = max(overall_state, service.overall_state_id)
return overall_state |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:do_loop_turn; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 161; 5, 162; 5, 163; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 13; 8, 14; 9, not_operator; 9, 10; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:first_scheduling; 13, comment; 14, block; 14, 15; 14, 22; 14, 30; 14, 31; 14, 39; 14, 40; 14, 48; 14, 62; 14, 69; 14, 70; 14, 108; 14, 146; 14, 147; 14, 155; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logger; 19, identifier:info; 20, argument_list; 20, 21; 21, string:"First scheduling launched"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:_t0; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:time; 28, identifier:time; 29, argument_list; 30, comment; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:sched; 37, identifier:initial_program_status; 38, argument_list; 39, comment; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:sched; 46, identifier:schedule; 47, argument_list; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:statsmgr; 52, identifier:timer; 53, argument_list; 53, 54; 53, 55; 54, string:'first_scheduling'; 55, binary_operator:-; 55, 56; 55, 61; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:time; 59, identifier:time; 60, argument_list; 61, identifier:_t0; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:logger; 66, identifier:info; 67, argument_list; 67, 68; 68, string:"First scheduling done"; 69, comment; 70, for_statement; 70, 71; 70, 72; 70, 90; 71, identifier:satellite; 72, list_comprehension; 72, 73; 72, 74; 72, 86; 73, identifier:s; 74, for_in_clause; 74, 75; 74, 76; 75, identifier:s; 76, call; 76, 77; 76, 78; 77, identifier:list; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:pollers; 84, identifier:values; 85, argument_list; 86, if_clause; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:s; 89, identifier:passive; 90, block; 90, 91; 91, if_statement; 91, 92; 91, 99; 92, not_operator; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:daemon_connection_init; 97, argument_list; 97, 98; 98, identifier:satellite; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:logger; 104, identifier:error; 105, argument_list; 105, 106; 105, 107; 106, string:"Passive satellite connection failed: %s"; 107, identifier:satellite; 108, for_statement; 108, 109; 108, 110; 108, 128; 109, identifier:satellite; 110, list_comprehension; 110, 111; 110, 112; 110, 124; 111, identifier:s; 112, for_in_clause; 112, 113; 112, 114; 113, identifier:s; 114, call; 114, 115; 114, 116; 115, identifier:list; 116, argument_list; 116, 117; 117, call; 117, 118; 117, 123; 118, attribute; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:reactionners; 122, identifier:values; 123, argument_list; 124, if_clause; 124, 125; 125, attribute; 125, 126; 125, 127; 126, identifier:s; 127, identifier:passive; 128, block; 128, 129; 129, if_statement; 129, 130; 129, 137; 130, not_operator; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:daemon_connection_init; 135, argument_list; 135, 136; 136, identifier:satellite; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:logger; 142, identifier:error; 143, argument_list; 143, 144; 143, 145; 144, string:"Passive satellite connection failed: %s"; 145, identifier:satellite; 146, comment; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:sched; 153, identifier:ticks; 154, integer:0; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:first_scheduling; 160, True; 161, comment; 162, comment; 163, if_statement; 163, 164; 163, 169; 163, 170; 163, 203; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:sched; 168, identifier:pushed_conf; 169, comment; 170, block; 170, 171; 170, 195; 171, if_statement; 171, 172; 171, 178; 172, not_operator; 172, 173; 173, attribute; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:sched; 177, identifier:must_schedule; 178, block; 178, 179; 178, 187; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:sched; 185, identifier:start_scheduling; 186, argument_list; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 194; 189, attribute; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:self; 192, identifier:sched; 193, identifier:before_run; 194, argument_list; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:sched; 201, identifier:run; 202, argument_list; 203, else_clause; 203, 204; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:logger; 209, identifier:warning; 210, argument_list; 210, 211; 210, 212; 211, string:"#%d - No monitoring configuration to scheduler..."; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:loop_count | def do_loop_turn(self):
"""Scheduler loop turn
Simply run the Alignak scheduler loop
This is called when a configuration got received by the scheduler daemon. As of it,
check if the first scheduling has been done... and manage this.
:return: None
"""
if not self.first_scheduling:
# Ok, now all is initialized, we can make the initial broks
logger.info("First scheduling launched")
_t0 = time.time()
# Program start brok
self.sched.initial_program_status()
# First scheduling
self.sched.schedule()
statsmgr.timer('first_scheduling', time.time() - _t0)
logger.info("First scheduling done")
# Connect to our passive satellites if needed
for satellite in [s for s in list(self.pollers.values()) if s.passive]:
if not self.daemon_connection_init(satellite):
logger.error("Passive satellite connection failed: %s", satellite)
for satellite in [s for s in list(self.reactionners.values()) if s.passive]:
if not self.daemon_connection_init(satellite):
logger.error("Passive satellite connection failed: %s", satellite)
# Ticks are for recurrent function call like consume, del zombies etc
self.sched.ticks = 0
self.first_scheduling = True
# Each loop turn, execute the daemon specific treatment...
# only if the daemon has a configuration to manage
if self.sched.pushed_conf:
# If scheduling is not yet enabled, enable scheduling
if not self.sched.must_schedule:
self.sched.start_scheduling()
self.sched.before_run()
self.sched.run()
else:
logger.warning("#%d - No monitoring configuration to scheduler...",
self.loop_count) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:add_failed_check_attempt; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:reason; 7, string:''; 8, block; 8, 9; 8, 11; 8, 17; 8, 27; 8, 44; 8, 45; 8, 46; 8, 92; 8, 93; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:reachable; 16, False; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:attempt; 22, binary_operator:+; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:attempt; 26, integer:1; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:logger; 31, identifier:debug; 32, argument_list; 32, 33; 32, 34; 32, 37; 32, 40; 32, 43; 33, string:"Failed attempt for %s (%d/%d), reason: %s"; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:name; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:attempt; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:max_check_attempts; 43, identifier:reason; 44, comment; 45, comment; 46, if_statement; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:alive; 50, block; 50, 51; 51, if_statement; 51, 52; 51, 56; 51, 74; 52, not_operator; 52, 53; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:stopping; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:logger; 61, identifier:warning; 62, argument_list; 62, 63; 62, 64; 62, 67; 62, 70; 62, 73; 63, string:"Add failed attempt for %s (%d/%d) - %s"; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:name; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:attempt; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:max_check_attempts; 73, identifier:reason; 74, else_clause; 74, 75; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:logger; 80, identifier:info; 81, argument_list; 81, 82; 81, 83; 81, 86; 81, 89; 82, string:"Stopping... failed attempt for %s (%d/%d) - also probably stopping"; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:name; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:attempt; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:max_check_attempts; 92, comment; 93, if_statement; 93, 94; 93, 101; 94, comparison_operator:>=; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:attempt; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:max_check_attempts; 101, block; 101, 102; 101, 137; 102, if_statement; 102, 103; 102, 107; 102, 122; 103, not_operator; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:stopping; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:logger; 112, identifier:warning; 113, argument_list; 113, 114; 113, 115; 113, 118; 113, 121; 114, string:"Set %s as dead, too much failed attempts (%d), last problem is: %s"; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:name; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:max_check_attempts; 121, identifier:reason; 122, else_clause; 122, 123; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:logger; 128, identifier:info; 129, argument_list; 129, 130; 129, 131; 129, 134; 130, string:"Stopping... set %s as dead, too much failed attempts (%d)"; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:name; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:max_check_attempts; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:set_dead; 142, argument_list | def add_failed_check_attempt(self, reason=''):
"""Set the daemon as unreachable and add a failed attempt
if we reach the maximum attempts, set the daemon as dead
:param reason: the reason of adding an attempts (stack trace sometimes)
:type reason: str
:return: None
"""
self.reachable = False
self.attempt = self.attempt + 1
logger.debug("Failed attempt for %s (%d/%d), reason: %s",
self.name, self.attempt, self.max_check_attempts, reason)
# Don't need to warn again and again if the satellite is already dead
# Only warn when it is alive
if self.alive:
if not self.stopping:
logger.warning("Add failed attempt for %s (%d/%d) - %s",
self.name, self.attempt, self.max_check_attempts, reason)
else:
logger.info("Stopping... failed attempt for %s (%d/%d) - also probably stopping",
self.name, self.attempt, self.max_check_attempts)
# If we reached the maximum attempts, set the daemon as dead
if self.attempt >= self.max_check_attempts:
if not self.stopping:
logger.warning("Set %s as dead, too much failed attempts (%d), last problem is: %s",
self.name, self.max_check_attempts, reason)
else:
logger.info("Stopping... set %s as dead, too much failed attempts (%d)",
self.name, self.max_check_attempts)
self.set_dead() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:get_links_for_a_broker; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:pollers; 6, identifier:reactionners; 7, identifier:receivers; 8, identifier:realms; 9, default_parameter; 9, 10; 9, 11; 10, identifier:manage_sub_realms; 11, False; 12, block; 12, 13; 12, 15; 12, 16; 12, 29; 12, 30; 12, 56; 12, 82; 12, 108; 12, 109; 12, 205; 13, expression_statement; 13, 14; 14, comment; 15, comment; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:cfg; 19, dictionary; 19, 20; 19, 23; 19, 26; 20, pair; 20, 21; 20, 22; 21, string:'pollers'; 22, dictionary; 23, pair; 23, 24; 23, 25; 24, string:'reactionners'; 25, dictionary; 26, pair; 26, 27; 26, 28; 27, string:'receivers'; 28, dictionary; 29, comment; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:poller_id; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:pollers; 35, block; 35, 36; 35, 42; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:poller; 39, subscript; 39, 40; 39, 41; 40, identifier:pollers; 41, identifier:poller_id; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 51; 44, subscript; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:cfg; 47, string:'pollers'; 48, attribute; 48, 49; 48, 50; 49, identifier:poller; 50, identifier:uuid; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:poller; 54, identifier:give_satellite_cfg; 55, argument_list; 56, for_statement; 56, 57; 56, 58; 56, 61; 57, identifier:reactionner_id; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:reactionners; 61, block; 61, 62; 61, 68; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:reactionner; 65, subscript; 65, 66; 65, 67; 66, identifier:reactionners; 67, identifier:reactionner_id; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 77; 70, subscript; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:cfg; 73, string:'reactionners'; 74, attribute; 74, 75; 74, 76; 75, identifier:reactionner; 76, identifier:uuid; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:reactionner; 80, identifier:give_satellite_cfg; 81, argument_list; 82, for_statement; 82, 83; 82, 84; 82, 87; 83, identifier:receiver_id; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:receivers; 87, block; 87, 88; 87, 94; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:receiver; 91, subscript; 91, 92; 91, 93; 92, identifier:receivers; 93, identifier:receiver_id; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 103; 96, subscript; 96, 97; 96, 100; 97, subscript; 97, 98; 97, 99; 98, identifier:cfg; 99, string:'receivers'; 100, attribute; 100, 101; 100, 102; 101, identifier:receiver; 102, identifier:uuid; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:receiver; 106, identifier:give_satellite_cfg; 107, argument_list; 108, comment; 109, if_statement; 109, 110; 109, 111; 109, 112; 110, identifier:manage_sub_realms; 111, comment; 112, block; 112, 113; 112, 143; 112, 144; 112, 174; 112, 175; 113, for_statement; 113, 114; 113, 115; 113, 122; 114, identifier:poller_id; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:get_all_subs_satellites_by_type; 119, argument_list; 119, 120; 119, 121; 120, string:'pollers'; 121, identifier:realms; 122, block; 122, 123; 122, 129; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:poller; 126, subscript; 126, 127; 126, 128; 127, identifier:pollers; 128, identifier:poller_id; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 138; 131, subscript; 131, 132; 131, 135; 132, subscript; 132, 133; 132, 134; 133, identifier:cfg; 134, string:'pollers'; 135, attribute; 135, 136; 135, 137; 136, identifier:poller; 137, identifier:uuid; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:poller; 141, identifier:give_satellite_cfg; 142, argument_list; 143, comment; 144, for_statement; 144, 145; 144, 146; 144, 153; 145, identifier:reactionner_id; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:get_all_subs_satellites_by_type; 150, argument_list; 150, 151; 150, 152; 151, string:'reactionners'; 152, identifier:realms; 153, block; 153, 154; 153, 160; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:reactionner; 157, subscript; 157, 158; 157, 159; 158, identifier:reactionners; 159, identifier:reactionner_id; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 169; 162, subscript; 162, 163; 162, 166; 163, subscript; 163, 164; 163, 165; 164, identifier:cfg; 165, string:'reactionners'; 166, attribute; 166, 167; 166, 168; 167, identifier:reactionner; 168, identifier:uuid; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:reactionner; 172, identifier:give_satellite_cfg; 173, argument_list; 174, comment; 175, for_statement; 175, 176; 175, 177; 175, 184; 176, identifier:receiver_id; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:get_all_subs_satellites_by_type; 181, argument_list; 181, 182; 181, 183; 182, string:'receivers'; 183, identifier:realms; 184, block; 184, 185; 184, 191; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:receiver; 188, subscript; 188, 189; 188, 190; 189, identifier:receivers; 190, identifier:receiver_id; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 200; 193, subscript; 193, 194; 193, 197; 194, subscript; 194, 195; 194, 196; 195, identifier:cfg; 196, string:'receivers'; 197, attribute; 197, 198; 197, 199; 198, identifier:receiver; 199, identifier:uuid; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:receiver; 203, identifier:give_satellite_cfg; 204, argument_list; 205, return_statement; 205, 206; 206, identifier:cfg | def get_links_for_a_broker(self, pollers, reactionners, receivers, realms,
manage_sub_realms=False):
"""Get a configuration dictionary with pollers, reactionners and receivers links
for a broker
:param pollers: pollers
:type pollers:
:param reactionners: reactionners
:type reactionners:
:param receivers: receivers
:type receivers:
:param realms: realms
:type realms:
:param manage_sub_realms:
:type manage_sub_realms: True if the borker manages sub realms
:return: dict containing pollers, reactionners and receivers links (key is satellite id)
:rtype: dict
"""
# Create void satellite links
cfg = {
'pollers': {},
'reactionners': {},
'receivers': {},
}
# Our self.daemons are only identifiers... that we use to fill the satellite links
for poller_id in self.pollers:
poller = pollers[poller_id]
cfg['pollers'][poller.uuid] = poller.give_satellite_cfg()
for reactionner_id in self.reactionners:
reactionner = reactionners[reactionner_id]
cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg()
for receiver_id in self.receivers:
receiver = receivers[receiver_id]
cfg['receivers'][receiver.uuid] = receiver.give_satellite_cfg()
# If the broker manages sub realms, fill the satellite links...
if manage_sub_realms:
# Now pollers
for poller_id in self.get_all_subs_satellites_by_type('pollers', realms):
poller = pollers[poller_id]
cfg['pollers'][poller.uuid] = poller.give_satellite_cfg()
# Now reactionners
for reactionner_id in self.get_all_subs_satellites_by_type('reactionners', realms):
reactionner = reactionners[reactionner_id]
cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg()
# Now receivers
for receiver_id in self.get_all_subs_satellites_by_type('receivers', realms):
receiver = receivers[receiver_id]
cfg['receivers'][receiver.uuid] = receiver.give_satellite_cfg()
return cfg |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_links_for_a_scheduler; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:pollers; 6, identifier:reactionners; 7, identifier:brokers; 8, block; 8, 9; 8, 11; 8, 12; 8, 25; 8, 26; 8, 169; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:cfg; 15, dictionary; 15, 16; 15, 19; 15, 22; 16, pair; 16, 17; 16, 18; 17, string:'pollers'; 18, dictionary; 19, pair; 19, 20; 19, 21; 20, string:'reactionners'; 21, dictionary; 22, pair; 22, 23; 22, 24; 23, string:'brokers'; 24, dictionary; 25, comment; 26, try_statement; 26, 27; 26, 145; 27, block; 27, 28; 27, 67; 27, 106; 28, for_statement; 28, 29; 28, 30; 28, 41; 29, identifier:poller; 30, binary_operator:+; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:pollers; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:get_potential_satellites_by_type; 38, argument_list; 38, 39; 38, 40; 39, identifier:pollers; 40, string:"poller"; 41, block; 41, 42; 41, 53; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:in; 43, 44; 43, 45; 44, identifier:poller; 45, identifier:pollers; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:poller; 50, subscript; 50, 51; 50, 52; 51, identifier:pollers; 52, identifier:poller; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 62; 55, subscript; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:cfg; 58, string:'pollers'; 59, attribute; 59, 60; 59, 61; 60, identifier:poller; 61, identifier:uuid; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:poller; 65, identifier:give_satellite_cfg; 66, argument_list; 67, for_statement; 67, 68; 67, 69; 67, 80; 68, identifier:reactionner; 69, binary_operator:+; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:reactionners; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:get_potential_satellites_by_type; 77, argument_list; 77, 78; 77, 79; 78, identifier:reactionners; 79, string:"reactionner"; 80, block; 80, 81; 80, 92; 81, if_statement; 81, 82; 81, 85; 82, comparison_operator:in; 82, 83; 82, 84; 83, identifier:reactionner; 84, identifier:reactionners; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:reactionner; 89, subscript; 89, 90; 89, 91; 90, identifier:reactionners; 91, identifier:reactionner; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 101; 94, subscript; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:cfg; 97, string:'reactionners'; 98, attribute; 98, 99; 98, 100; 99, identifier:reactionner; 100, identifier:uuid; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:reactionner; 104, identifier:give_satellite_cfg; 105, argument_list; 106, for_statement; 106, 107; 106, 108; 106, 119; 107, identifier:broker; 108, binary_operator:+; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:brokers; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:get_potential_satellites_by_type; 116, argument_list; 116, 117; 116, 118; 117, identifier:brokers; 118, string:"broker"; 119, block; 119, 120; 119, 131; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:in; 121, 122; 121, 123; 122, identifier:broker; 123, identifier:brokers; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:broker; 128, subscript; 128, 129; 128, 130; 129, identifier:brokers; 130, identifier:broker; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 140; 133, subscript; 133, 134; 133, 137; 134, subscript; 134, 135; 134, 136; 135, identifier:cfg; 136, string:'brokers'; 137, attribute; 137, 138; 137, 139; 138, identifier:broker; 139, identifier:uuid; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:broker; 143, identifier:give_satellite_cfg; 144, argument_list; 145, except_clause; 145, 146; 145, 150; 145, 151; 146, as_pattern; 146, 147; 146, 148; 147, identifier:Exception; 148, as_pattern_target; 148, 149; 149, identifier:exp; 150, comment; 151, block; 151, 152; 151, 160; 151, 161; 151, 162; 151, 163; 151, 164; 151, 165; 151, 166; 151, 167; 151, 168; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:logger; 156, identifier:exception; 157, argument_list; 157, 158; 157, 159; 158, string:"realm.get_links_for_a_scheduler: %s"; 159, identifier:exp; 160, comment; 161, comment; 162, comment; 163, comment; 164, comment; 165, comment; 166, comment; 167, comment; 168, comment; 169, return_statement; 169, 170; 170, identifier:cfg | def get_links_for_a_scheduler(self, pollers, reactionners, brokers):
"""Get a configuration dictionary with pollers, reactionners and brokers links
for a scheduler
:return: dict containing pollers, reactionners and brokers links (key is satellite id)
:rtype: dict
"""
# Create void satellite links
cfg = {
'pollers': {},
'reactionners': {},
'brokers': {},
}
# Our self.daemons are only identifiers... that we use to fill the satellite links
try:
for poller in self.pollers + self.get_potential_satellites_by_type(pollers, "poller"):
if poller in pollers:
poller = pollers[poller]
cfg['pollers'][poller.uuid] = poller.give_satellite_cfg()
for reactionner in self.reactionners + self.get_potential_satellites_by_type(
reactionners, "reactionner"):
if reactionner in reactionners:
reactionner = reactionners[reactionner]
cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg()
for broker in self.brokers + self.get_potential_satellites_by_type(brokers, "broker"):
if broker in brokers:
broker = brokers[broker]
cfg['brokers'][broker.uuid] = broker.give_satellite_cfg()
except Exception as exp: # pylint: disable=broad-except
logger.exception("realm.get_links_for_a_scheduler: %s", exp)
# for poller in self.get_potential_satellites_by_type(pollers, "poller"):
# logger.info("Poller: %s", poller)
# cfg['pollers'][poller.uuid] = poller.give_satellite_cfg()
#
# for reactionner in self.get_potential_satellites_by_type(reactionners, "reactionner"):
# cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg()
#
# for broker in self.get_potential_satellites_by_type(brokers, "broker"):
# cfg['brokers'][broker.uuid] = broker.give_satellite_cfg()
return cfg |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_default; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:check; 7, False; 8, block; 8, 9; 8, 11; 8, 15; 8, 45; 8, 122; 8, 128; 8, 208; 8, 214; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:found; 14, list:[]; 15, for_statement; 15, 16; 15, 17; 15, 29; 16, identifier:realm; 17, call; 17, 18; 17, 19; 18, identifier:sorted; 19, argument_list; 19, 20; 19, 21; 20, identifier:self; 21, keyword_argument; 21, 22; 21, 23; 22, identifier:key; 23, lambda; 23, 24; 23, 26; 24, lambda_parameters; 24, 25; 25, identifier:r; 26, attribute; 26, 27; 26, 28; 27, identifier:r; 28, identifier:level; 29, block; 29, 30; 30, if_statement; 30, 31; 30, 37; 31, call; 31, 32; 31, 33; 32, identifier:getattr; 33, argument_list; 33, 34; 33, 35; 33, 36; 34, identifier:realm; 35, string:'default'; 36, False; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:found; 42, identifier:append; 43, argument_list; 43, 44; 44, identifier:realm; 45, if_statement; 45, 46; 45, 48; 45, 49; 46, not_operator; 46, 47; 47, identifier:found; 48, comment; 49, block; 49, 50; 49, 65; 49, 80; 49, 86; 49, 95; 49, 101; 49, 108; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:found_names; 53, call; 53, 54; 53, 55; 54, identifier:sorted; 55, argument_list; 55, 56; 56, list_comprehension; 56, 57; 56, 62; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:r; 60, identifier:get_name; 61, argument_list; 62, for_in_clause; 62, 63; 62, 64; 63, identifier:r; 64, identifier:self; 65, if_statement; 65, 66; 65, 68; 66, not_operator; 66, 67; 67, identifier:found_names; 68, block; 68, 69; 68, 78; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:add_error; 74, argument_list; 74, 75; 75, concatenated_string; 75, 76; 75, 77; 76, string:"No realm is defined in this configuration! "; 77, string:"This should not be possible!"; 78, return_statement; 78, 79; 79, None; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:default_realm_name; 83, subscript; 83, 84; 83, 85; 84, identifier:found_names; 85, integer:0; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:default_realm; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:find_by_name; 93, argument_list; 93, 94; 94, identifier:default_realm_name; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:default_realm; 99, identifier:default; 100, True; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:found; 105, identifier:append; 106, argument_list; 106, 107; 107, identifier:default_realm; 108, if_statement; 108, 109; 108, 110; 109, identifier:check; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:add_error; 116, argument_list; 116, 117; 117, binary_operator:%; 117, 118; 117, 121; 118, concatenated_string; 118, 119; 118, 120; 119, string:"No realm is defined as the default one! "; 120, string:"I set %s as the default realm"; 121, identifier:default_realm_name; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:default_realm; 125, subscript; 125, 126; 125, 127; 126, identifier:found; 127, integer:0; 128, if_statement; 128, 129; 128, 135; 128, 136; 129, comparison_operator:>; 129, 130; 129, 134; 130, call; 130, 131; 130, 132; 131, identifier:len; 132, argument_list; 132, 133; 133, identifier:found; 134, integer:1; 135, comment; 136, block; 136, 137; 136, 152; 136, 158; 136, 167; 136, 168; 136, 187; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:found_names; 140, call; 140, 141; 140, 142; 141, identifier:sorted; 142, argument_list; 142, 143; 143, list_comprehension; 143, 144; 143, 149; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:r; 147, identifier:get_name; 148, argument_list; 149, for_in_clause; 149, 150; 149, 151; 150, identifier:r; 151, identifier:found; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:default_realm_name; 155, subscript; 155, 156; 155, 157; 156, identifier:found_names; 157, integer:0; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:default_realm; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:find_by_name; 165, argument_list; 165, 166; 166, identifier:default_realm_name; 167, comment; 168, for_statement; 168, 169; 168, 170; 168, 171; 169, identifier:realm; 170, identifier:found; 171, block; 171, 172; 172, if_statement; 172, 173; 172, 180; 173, comparison_operator:!=; 173, 174; 173, 179; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:realm; 177, identifier:get_name; 178, argument_list; 179, identifier:default_realm_name; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:realm; 185, identifier:default; 186, False; 187, if_statement; 187, 188; 187, 189; 188, identifier:check; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:add_warning; 195, argument_list; 195, 196; 196, binary_operator:%; 196, 197; 196, 200; 197, concatenated_string; 197, 198; 197, 199; 198, string:"More than one realm is defined as the default one: %s. "; 199, string:"I set %s as the default realm."; 200, tuple; 200, 201; 200, 207; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, string:','; 204, identifier:join; 205, argument_list; 205, 206; 206, identifier:found_names; 207, identifier:default_realm_name; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:default; 213, identifier:default_realm; 214, return_statement; 214, 215; 215, identifier:default_realm | def get_default(self, check=False):
"""Get the default realm
:param check: check correctness if True
:type check: bool
:return: Default realm of Alignak configuration
:rtype: alignak.objects.realm.Realm | None
"""
found = []
for realm in sorted(self, key=lambda r: r.level):
if getattr(realm, 'default', False):
found.append(realm)
if not found:
# Retain as default realm the first realm in name alphabetical order
found_names = sorted([r.get_name() for r in self])
if not found_names:
self.add_error("No realm is defined in this configuration! "
"This should not be possible!")
return None
default_realm_name = found_names[0]
default_realm = self.find_by_name(default_realm_name)
default_realm.default = True
found.append(default_realm)
if check:
self.add_error("No realm is defined as the default one! "
"I set %s as the default realm" % default_realm_name)
default_realm = found[0]
if len(found) > 1:
# Retain as default realm the first so-called default realms in name alphabetical order
found_names = sorted([r.get_name() for r in found])
default_realm_name = found_names[0]
default_realm = self.find_by_name(default_realm_name)
# Set all found realms as non-default realms
for realm in found:
if realm.get_name() != default_realm_name:
realm.default = False
if check:
self.add_warning("More than one realm is defined as the default one: %s. "
"I set %s as the default realm."
% (','.join(found_names), default_realm_name))
self.default = default_realm
return default_realm |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 26; 1, 27; 2, function_name:command; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:command; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:timestamp; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:element; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:host; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:service; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:user; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:parameters; 25, None; 26, comment; 27, block; 27, 28; 27, 30; 27, 56; 27, 172; 27, 184; 27, 191; 27, 209; 27, 240; 27, 308; 27, 319; 27, 320; 27, 328; 27, 340; 28, expression_statement; 28, 29; 29, comment; 30, if_statement; 30, 31; 30, 39; 31, comparison_operator:in; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:cherrypy; 35, identifier:request; 36, identifier:method; 37, list:["POST"]; 37, 38; 38, string:"POST"; 39, block; 39, 40; 40, if_statement; 40, 41; 40, 47; 41, not_operator; 41, 42; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:cherrypy; 45, identifier:request; 46, identifier:json; 47, block; 47, 48; 48, return_statement; 48, 49; 49, dictionary; 49, 50; 49, 53; 50, pair; 50, 51; 50, 52; 51, string:'_status'; 52, string:u'ERR'; 53, pair; 53, 54; 53, 55; 54, string:'_message'; 55, string:u'You must POST parameters on this endpoint.'; 56, if_statement; 56, 57; 56, 60; 57, comparison_operator:is; 57, 58; 57, 59; 58, identifier:command; 59, None; 60, block; 60, 61; 61, try_statement; 61, 62; 61, 161; 62, block; 62, 63; 62, 77; 62, 91; 62, 105; 62, 119; 62, 133; 62, 147; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:command; 66, call; 66, 67; 66, 74; 67, attribute; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:cherrypy; 71, identifier:request; 72, identifier:json; 73, identifier:get; 74, argument_list; 74, 75; 74, 76; 75, string:'command'; 76, None; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:timestamp; 80, call; 80, 81; 80, 88; 81, attribute; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:cherrypy; 85, identifier:request; 86, identifier:json; 87, identifier:get; 88, argument_list; 88, 89; 88, 90; 89, string:'timestamp'; 90, None; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:element; 94, call; 94, 95; 94, 102; 95, attribute; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:cherrypy; 99, identifier:request; 100, identifier:json; 101, identifier:get; 102, argument_list; 102, 103; 102, 104; 103, string:'element'; 104, None; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:host; 108, call; 108, 109; 108, 116; 109, attribute; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:cherrypy; 113, identifier:request; 114, identifier:json; 115, identifier:get; 116, argument_list; 116, 117; 116, 118; 117, string:'host'; 118, None; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:service; 122, call; 122, 123; 122, 130; 123, attribute; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:cherrypy; 127, identifier:request; 128, identifier:json; 129, identifier:get; 130, argument_list; 130, 131; 130, 132; 131, string:'service'; 132, None; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:user; 136, call; 136, 137; 136, 144; 137, attribute; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:cherrypy; 141, identifier:request; 142, identifier:json; 143, identifier:get; 144, argument_list; 144, 145; 144, 146; 145, string:'user'; 146, None; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:parameters; 150, call; 150, 151; 150, 158; 151, attribute; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:cherrypy; 155, identifier:request; 156, identifier:json; 157, identifier:get; 158, argument_list; 158, 159; 158, 160; 159, string:'parameters'; 160, None; 161, except_clause; 161, 162; 161, 163; 162, identifier:AttributeError; 163, block; 163, 164; 164, return_statement; 164, 165; 165, dictionary; 165, 166; 165, 169; 166, pair; 166, 167; 166, 168; 167, string:'_status'; 168, string:u'ERR'; 169, pair; 169, 170; 169, 171; 170, string:'_message'; 171, string:u'Missing command parameters'; 172, if_statement; 172, 173; 172, 175; 173, not_operator; 173, 174; 174, identifier:command; 175, block; 175, 176; 176, return_statement; 176, 177; 177, dictionary; 177, 178; 177, 181; 178, pair; 178, 179; 178, 180; 179, string:'_status'; 180, string:u'ERR'; 181, pair; 181, 182; 181, 183; 182, string:'_message'; 183, string:u'Missing command parameter'; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:fields; 187, call; 187, 188; 187, 189; 188, identifier:split_semicolon; 189, argument_list; 189, 190; 190, identifier:command; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:command_line; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:command; 197, identifier:replace; 198, argument_list; 198, 199; 198, 202; 199, subscript; 199, 200; 199, 201; 200, identifier:fields; 201, integer:0; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:fields; 206, integer:0; 207, identifier:upper; 208, argument_list; 209, if_statement; 209, 210; 209, 211; 210, identifier:timestamp; 211, block; 211, 212; 211, 232; 212, try_statement; 212, 213; 212, 221; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:timestamp; 217, call; 217, 218; 217, 219; 218, identifier:int; 219, argument_list; 219, 220; 220, identifier:timestamp; 221, except_clause; 221, 222; 221, 223; 222, identifier:ValueError; 223, block; 223, 224; 224, return_statement; 224, 225; 225, dictionary; 225, 226; 225, 229; 226, pair; 226, 227; 226, 228; 227, string:'_status'; 228, string:u'ERR'; 229, pair; 229, 230; 229, 231; 230, string:'_message'; 231, string:u'Timestamp must be an integer value'; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:command_line; 235, binary_operator:%; 235, 236; 235, 237; 236, string:'[%d] %s'; 237, tuple; 237, 238; 237, 239; 238, identifier:timestamp; 239, identifier:command_line; 240, if_statement; 240, 241; 240, 246; 240, 280; 241, boolean_operator:or; 241, 242; 241, 245; 242, boolean_operator:or; 242, 243; 242, 244; 243, identifier:host; 244, identifier:service; 245, identifier:user; 246, block; 246, 247; 246, 258; 246, 269; 247, if_statement; 247, 248; 247, 249; 248, identifier:host; 249, block; 249, 250; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:command_line; 253, binary_operator:%; 253, 254; 253, 255; 254, string:'%s;%s'; 255, tuple; 255, 256; 255, 257; 256, identifier:command_line; 257, identifier:host; 258, if_statement; 258, 259; 258, 260; 259, identifier:service; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:command_line; 264, binary_operator:%; 264, 265; 264, 266; 265, string:'%s;%s'; 266, tuple; 266, 267; 266, 268; 267, identifier:command_line; 268, identifier:service; 269, if_statement; 269, 270; 269, 271; 270, identifier:user; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:command_line; 275, binary_operator:%; 275, 276; 275, 277; 276, string:'%s;%s'; 277, tuple; 277, 278; 277, 279; 278, identifier:command_line; 279, identifier:user; 280, elif_clause; 280, 281; 280, 282; 281, identifier:element; 282, block; 282, 283; 282, 300; 283, if_statement; 283, 284; 283, 287; 283, 288; 284, comparison_operator:in; 284, 285; 284, 286; 285, string:'/'; 286, identifier:element; 287, comment; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:element; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:element; 295, identifier:replace; 296, argument_list; 296, 297; 296, 298; 296, 299; 297, string:'/'; 298, string:';'; 299, integer:1; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:command_line; 303, binary_operator:%; 303, 304; 303, 305; 304, string:'%s;%s'; 305, tuple; 305, 306; 305, 307; 306, identifier:command_line; 307, identifier:element; 308, if_statement; 308, 309; 308, 310; 309, identifier:parameters; 310, block; 310, 311; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:command_line; 314, binary_operator:%; 314, 315; 314, 316; 315, string:'%s;%s'; 316, tuple; 316, 317; 316, 318; 317, identifier:command_line; 318, identifier:parameters; 319, comment; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:logger; 324, identifier:warning; 325, argument_list; 325, 326; 325, 327; 326, string:"Got an external command: %s"; 327, identifier:command_line; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 335; 330, attribute; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:app; 334, identifier:add; 335, argument_list; 335, 336; 336, call; 336, 337; 336, 338; 337, identifier:ExternalCommand; 338, argument_list; 338, 339; 339, identifier:command_line; 340, return_statement; 340, 341; 341, dictionary; 341, 342; 341, 345; 341, 350; 342, pair; 342, 343; 342, 344; 343, string:'_status'; 344, string:u'OK'; 345, pair; 345, 346; 345, 347; 346, string:'_message'; 347, binary_operator:%; 347, 348; 347, 349; 348, string:u"Got command: %s"; 349, identifier:command_line; 350, pair; 350, 351; 350, 352; 351, string:'command'; 352, identifier:command_line | def command(self, command=None,
timestamp=None, element=None, host=None, service=None, user=None, parameters=None):
# pylint: disable=too-many-branches
""" Request to execute an external command
Allowed parameters are:
`command`: mandatory parameter containing the whole command line or only the command name
`timestamp`: optional parameter containing the timestamp. If not present, the
current timestamp is added in the command line
`element`: the targeted element that will be appended after the command name (`command`).
If element contains a '/' character it is split to make an host and service.
`host`, `service` or `user`: the targeted host, service or user. Takes precedence over
the `element` to target a specific element
`parameters`: the parameter that will be appended after all the arguments
When using this endpoint with the HTTP GET method, the semi colons that are commonly used
to separate the parameters must be replace with %3B! This because the ; is an accepted
URL query parameters separator...
Indeed, the recommended way of using this endpoint is to use the HTTP POST method.
In case of any error, this function returns an object containing some properties:
'_status': 'ERR' because of the error
`_message`: some more explanations about the error
The `_status` field is 'OK' with an according `_message` to explain what the Arbiter
will do depending upon the notification. The `command` property contains the formatted
external command.
:return: dict
"""
if cherrypy.request.method in ["POST"]:
if not cherrypy.request.json:
return {'_status': u'ERR',
'_message': u'You must POST parameters on this endpoint.'}
if command is None:
try:
command = cherrypy.request.json.get('command', None)
timestamp = cherrypy.request.json.get('timestamp', None)
element = cherrypy.request.json.get('element', None)
host = cherrypy.request.json.get('host', None)
service = cherrypy.request.json.get('service', None)
user = cherrypy.request.json.get('user', None)
parameters = cherrypy.request.json.get('parameters', None)
except AttributeError:
return {'_status': u'ERR', '_message': u'Missing command parameters'}
if not command:
return {'_status': u'ERR', '_message': u'Missing command parameter'}
fields = split_semicolon(command)
command_line = command.replace(fields[0], fields[0].upper())
if timestamp:
try:
timestamp = int(timestamp)
except ValueError:
return {'_status': u'ERR', '_message': u'Timestamp must be an integer value'}
command_line = '[%d] %s' % (timestamp, command_line)
if host or service or user:
if host:
command_line = '%s;%s' % (command_line, host)
if service:
command_line = '%s;%s' % (command_line, service)
if user:
command_line = '%s;%s' % (command_line, user)
elif element:
if '/' in element:
# Replace only the first /
element = element.replace('/', ';', 1)
command_line = '%s;%s' % (command_line, element)
if parameters:
command_line = '%s;%s' % (command_line, parameters)
# Add a command to get managed
logger.warning("Got an external command: %s", command_line)
self.app.add(ExternalCommand(command_line))
return {'_status': u'OK',
'_message': u"Got command: %s" % command_line,
'command': command_line} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:satellites_list; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:daemon_type; 7, string:''; 8, block; 8, 9; 8, 11; 9, expression_statement; 9, 10; 10, comment; 11, with_statement; 11, 12; 11, 19; 12, with_clause; 12, 13; 13, with_item; 13, 14; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:app; 18, identifier:conf_lock; 19, block; 19, 20; 19, 24; 19, 76; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:res; 23, dictionary; 24, for_statement; 24, 25; 24, 26; 24, 33; 25, identifier:s_type; 26, list:['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']; 26, 27; 26, 28; 26, 29; 26, 30; 26, 31; 26, 32; 27, string:'arbiter'; 28, string:'scheduler'; 29, string:'poller'; 30, string:'reactionner'; 31, string:'receiver'; 32, string:'broker'; 33, block; 33, 34; 33, 42; 33, 46; 33, 52; 34, if_statement; 34, 35; 34, 40; 35, boolean_operator:and; 35, 36; 35, 37; 36, identifier:daemon_type; 37, comparison_operator:!=; 37, 38; 37, 39; 38, identifier:daemon_type; 39, identifier:s_type; 40, block; 40, 41; 41, continue_statement; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:satellite_list; 45, list:[]; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, subscript; 48, 49; 48, 50; 49, identifier:res; 50, identifier:s_type; 51, identifier:satellite_list; 52, for_statement; 52, 53; 52, 54; 52, 66; 53, identifier:daemon_link; 54, call; 54, 55; 54, 56; 55, identifier:getattr; 56, argument_list; 56, 57; 56, 62; 56, 65; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:app; 61, identifier:conf; 62, binary_operator:+; 62, 63; 62, 64; 63, identifier:s_type; 64, string:'s'; 65, list:[]; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:satellite_list; 71, identifier:append; 72, argument_list; 72, 73; 73, attribute; 73, 74; 73, 75; 74, identifier:daemon_link; 75, identifier:name; 76, return_statement; 76, 77; 77, identifier:res | def satellites_list(self, daemon_type=''):
"""Get the arbiter satellite names sorted by type
Returns a list of the satellites as in:
{
reactionner: [
"reactionner-master"
],
broker: [
"broker-master"
],
arbiter: [
"arbiter-master"
],
scheduler: [
"scheduler-master-3",
"scheduler-master",
"scheduler-master-2"
],
receiver: [
"receiver-nsca",
"receiver-master"
],
poller: [
"poller-master"
]
}
If a specific daemon type is requested, the list is reduced to this unique daemon type:
{
scheduler: [
"scheduler-master-3",
"scheduler-master",
"scheduler-master-2"
]
}
:param daemon_type: daemon type to filter
:type daemon_type: str
:return: dict with key *daemon_type* and value list of daemon name
:rtype: dict
"""
with self.app.conf_lock:
res = {}
for s_type in ['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']:
if daemon_type and daemon_type != s_type:
continue
satellite_list = []
res[s_type] = satellite_list
for daemon_link in getattr(self.app.conf, s_type + 's', []):
satellite_list.append(daemon_link.name)
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:fill_default_configuration; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 23; 5, 89; 5, 90; 5, 124; 5, 132; 5, 199; 5, 200; 5, 208; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logger; 12, identifier:debug; 13, argument_list; 13, 14; 14, string:"Filling the unset properties with their default value:"; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:types_creations; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:__class__; 22, identifier:types_creations; 23, for_statement; 23, 24; 23, 25; 23, 26; 24, identifier:o_type; 25, identifier:types_creations; 26, block; 26, 27; 26, 38; 26, 39; 26, 52; 26, 60; 26, 69; 26, 83; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 35; 29, tuple_pattern; 29, 30; 29, 31; 29, 32; 29, 33; 29, 34; 30, identifier:_; 31, identifier:_; 32, identifier:inner_property; 33, identifier:_; 34, identifier:_; 35, subscript; 35, 36; 35, 37; 36, identifier:types_creations; 37, identifier:o_type; 38, comment; 39, if_statement; 39, 40; 39, 50; 40, comparison_operator:in; 40, 41; 40, 42; 41, identifier:inner_property; 42, list:['realms', 'arbiters', 'schedulers', 'reactionners',
'pollers', 'brokers', 'receivers']; 42, 43; 42, 44; 42, 45; 42, 46; 42, 47; 42, 48; 42, 49; 43, string:'realms'; 44, string:'arbiters'; 45, string:'schedulers'; 46, string:'reactionners'; 47, string:'pollers'; 48, string:'brokers'; 49, string:'receivers'; 50, block; 50, 51; 51, continue_statement; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:logger; 56, identifier:debug; 57, argument_list; 57, 58; 57, 59; 58, string:" . for %s"; 59, identifier:inner_property; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:inner_object; 63, call; 63, 64; 63, 65; 64, identifier:getattr; 65, argument_list; 65, 66; 65, 67; 65, 68; 66, identifier:self; 67, identifier:inner_property; 68, None; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:is; 70, 71; 70, 72; 71, identifier:inner_object; 72, None; 73, block; 73, 74; 73, 82; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:logger; 78, identifier:debug; 79, argument_list; 79, 80; 79, 81; 80, string:"No %s to fill with default values"; 81, identifier:inner_property; 82, continue_statement; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:inner_object; 87, identifier:fill_default; 88, argument_list; 89, comment; 90, if_statement; 90, 91; 90, 99; 91, comparison_operator:is; 91, 92; 91, 98; 92, call; 92, 93; 92, 94; 93, identifier:getattr; 94, argument_list; 94, 95; 94, 96; 94, 97; 95, identifier:self; 96, string:'realms'; 97, None; 98, None; 99, block; 99, 100; 99, 106; 99, 114; 99, 115; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:fill_default_realm; 105, argument_list; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:realms; 112, identifier:fill_default; 113, argument_list; 114, comment; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:fill_default_satellites; 120, argument_list; 120, 121; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:launch_missing_daemons; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:types_creations; 127, attribute; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:__class__; 131, identifier:types_creations; 132, for_statement; 132, 133; 132, 134; 132, 135; 133, identifier:o_type; 134, identifier:types_creations; 135, block; 135, 136; 135, 147; 135, 166; 135, 167; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 144; 138, tuple_pattern; 138, 139; 138, 140; 138, 141; 138, 142; 138, 143; 139, identifier:_; 140, identifier:_; 141, identifier:inner_property; 142, identifier:_; 143, identifier:_; 144, subscript; 144, 145; 144, 146; 145, identifier:types_creations; 146, identifier:o_type; 147, if_statement; 147, 148; 147, 156; 148, comparison_operator:is; 148, 149; 148, 155; 149, call; 149, 150; 149, 151; 150, identifier:getattr; 151, argument_list; 151, 152; 151, 153; 151, 154; 152, identifier:self; 153, identifier:inner_property; 154, None; 155, None; 156, block; 156, 157; 156, 165; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:logger; 161, identifier:debug; 162, argument_list; 162, 163; 162, 164; 163, string:"No %s to fill with default values"; 164, identifier:inner_property; 165, continue_statement; 166, comment; 167, if_statement; 167, 168; 167, 176; 168, comparison_operator:in; 168, 169; 168, 170; 169, identifier:inner_property; 170, list:['schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']; 170, 171; 170, 172; 170, 173; 170, 174; 170, 175; 171, string:'schedulers'; 172, string:'reactionners'; 173, string:'pollers'; 174, string:'brokers'; 175, string:'receivers'; 176, block; 176, 177; 176, 185; 176, 193; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:logger; 181, identifier:debug; 182, argument_list; 182, 183; 182, 184; 183, string:" . for %s"; 184, identifier:inner_property; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:inner_object; 188, call; 188, 189; 188, 190; 189, identifier:getattr; 190, argument_list; 190, 191; 190, 192; 191, identifier:self; 192, identifier:inner_property; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:inner_object; 197, identifier:fill_default; 198, argument_list; 199, comment; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:hosts; 206, identifier:fill_predictive_missing_parameters; 207, argument_list; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 215; 210, attribute; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:services; 214, identifier:fill_predictive_missing_parameters; 215, argument_list | def fill_default_configuration(self):
"""Fill objects properties with default value if necessary
:return: None
"""
logger.debug("Filling the unset properties with their default value:")
types_creations = self.__class__.types_creations
for o_type in types_creations:
(_, _, inner_property, _, _) = types_creations[o_type]
# Not yet for the realms and daemons links
if inner_property in ['realms', 'arbiters', 'schedulers', 'reactionners',
'pollers', 'brokers', 'receivers']:
continue
logger.debug(" . for %s", inner_property,)
inner_object = getattr(self, inner_property, None)
if inner_object is None:
logger.debug("No %s to fill with default values", inner_property)
continue
inner_object.fill_default()
# We have all monitored elements, we can create a default realm if none is defined
if getattr(self, 'realms', None) is not None:
self.fill_default_realm()
self.realms.fill_default()
# Then we create missing satellites, so no other satellites will be created after
self.fill_default_satellites(self.launch_missing_daemons)
types_creations = self.__class__.types_creations
for o_type in types_creations:
(_, _, inner_property, _, _) = types_creations[o_type]
if getattr(self, inner_property, None) is None:
logger.debug("No %s to fill with default values", inner_property)
continue
# Only for the daemons links
if inner_property in ['schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']:
logger.debug(" . for %s", inner_property,)
inner_object = getattr(self, inner_property)
inner_object.fill_default()
# Now fill some fields we can predict (like address for hosts)
self.hosts.fill_predictive_missing_parameters()
self.services.fill_predictive_missing_parameters() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:got_arbiter_module_type_defined; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:module_type; 6, block; 6, 7; 6, 9; 6, 77; 7, expression_statement; 7, 8; 8, comment; 9, for_statement; 9, 10; 9, 11; 9, 14; 9, 15; 10, identifier:arbiter; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:arbiters; 14, comment; 15, block; 15, 16; 16, for_statement; 16, 17; 16, 18; 16, 24; 16, 25; 17, identifier:module; 18, call; 18, 19; 18, 20; 19, identifier:getattr; 20, argument_list; 20, 21; 20, 22; 20, 23; 21, identifier:arbiter; 22, string:'modules'; 23, list:[]; 24, comment; 25, block; 25, 26; 25, 34; 25, 35; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:module_name; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:module; 32, identifier:get_name; 33, argument_list; 34, comment; 35, for_statement; 35, 36; 35, 37; 35, 40; 35, 41; 36, identifier:mod; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:modules; 40, comment; 41, block; 41, 42; 42, if_statement; 42, 43; 42, 59; 42, 60; 43, comparison_operator:==; 43, 44; 43, 54; 44, call; 44, 45; 44, 53; 45, attribute; 45, 46; 45, 52; 46, call; 46, 47; 46, 48; 47, identifier:getattr; 48, argument_list; 48, 49; 48, 50; 48, 51; 49, identifier:mod; 50, string:'python_name'; 51, string:''; 52, identifier:strip; 53, argument_list; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:module_type; 57, identifier:strip; 58, argument_list; 59, comment; 60, block; 60, 61; 61, if_statement; 61, 62; 61, 74; 62, comparison_operator:==; 62, 63; 62, 73; 63, call; 63, 64; 63, 72; 64, attribute; 64, 65; 64, 71; 65, call; 65, 66; 65, 67; 66, identifier:getattr; 67, argument_list; 67, 68; 67, 69; 67, 70; 68, identifier:mod; 69, string:'name'; 70, string:''; 71, identifier:strip; 72, argument_list; 73, identifier:module_name; 74, block; 74, 75; 75, return_statement; 75, 76; 76, True; 77, return_statement; 77, 78; 78, False | def got_arbiter_module_type_defined(self, module_type):
"""Check if a module type is defined in one of the arbiters
Also check the module name
:param module_type: module type to search for
:type module_type: str
:return: True if mod_type is found else False
:rtype: bool
TODO: Factorize it with got_broker_module_type_defined:
"""
for arbiter in self.arbiters:
# Do like the linkify will do after....
for module in getattr(arbiter, 'modules', []):
# So look at what the arbiter try to call as module
module_name = module.get_name()
# Ok, now look in modules...
for mod in self.modules:
# try to see if this module is the good type
if getattr(mod, 'python_name', '').strip() == module_type.strip():
# if so, the good name?
if getattr(mod, 'name', '').strip() == module_name:
return True
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 1, 8; 2, function_name:load_modules_configuration_objects; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:raw_objects; 6, comment; 7, comment; 8, block; 8, 9; 8, 11; 8, 12; 8, 13; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, comment; 13, for_statement; 13, 14; 13, 15; 13, 20; 14, identifier:instance; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:modules_manager; 19, identifier:instances; 20, block; 20, 21; 20, 31; 20, 50; 20, 91; 20, 106; 20, 114; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:logger; 25, identifier:debug; 26, argument_list; 26, 27; 26, 28; 27, string:"Getting objects from the module: %s"; 28, attribute; 28, 29; 28, 30; 29, identifier:instance; 30, identifier:name; 31, if_statement; 31, 32; 31, 38; 32, not_operator; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:hasattr; 35, argument_list; 35, 36; 35, 37; 36, identifier:instance; 37, string:'get_objects'; 38, block; 38, 39; 38, 49; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:logger; 43, identifier:debug; 44, argument_list; 44, 45; 44, 46; 45, string:"The module '%s' do not provide any objects."; 46, attribute; 46, 47; 46, 48; 47, identifier:instance; 48, identifier:name; 49, return_statement; 50, try_statement; 50, 51; 50, 70; 51, block; 51, 52; 51, 62; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:logger; 56, identifier:info; 57, argument_list; 57, 58; 57, 59; 58, string:"Getting Alignak monitored configuration objects from module '%s'"; 59, attribute; 59, 60; 59, 61; 60, identifier:instance; 61, identifier:name; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:got_objects; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:instance; 68, identifier:get_objects; 69, argument_list; 70, except_clause; 70, 71; 70, 75; 70, 76; 71, as_pattern; 71, 72; 71, 73; 72, identifier:Exception; 73, as_pattern_target; 73, 74; 74, identifier:exp; 75, comment; 76, block; 76, 77; 76, 90; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:logger; 81, identifier:exception; 82, argument_list; 82, 83; 82, 86; 82, 89; 83, concatenated_string; 83, 84; 83, 85; 84, string:"Module %s get_objects raised an exception %s. "; 85, string:"Log and continue to run."; 86, attribute; 86, 87; 86, 88; 87, identifier:instance; 88, identifier:name; 89, identifier:exp; 90, continue_statement; 91, if_statement; 91, 92; 91, 94; 92, not_operator; 92, 93; 93, identifier:got_objects; 94, block; 94, 95; 94, 105; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:logger; 99, identifier:warning; 100, argument_list; 100, 101; 100, 102; 101, string:"The module '%s' did not provided any objects."; 102, attribute; 102, 103; 102, 104; 103, identifier:instance; 104, identifier:name; 105, return_statement; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:types_creations; 109, attribute; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:conf; 113, identifier:types_creations; 114, for_statement; 114, 115; 114, 116; 114, 117; 115, identifier:o_type; 116, identifier:types_creations; 117, block; 117, 118; 117, 129; 117, 142; 117, 159; 117, 203; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 126; 120, tuple_pattern; 120, 121; 120, 122; 120, 123; 120, 124; 120, 125; 121, identifier:_; 122, identifier:_; 123, identifier:prop; 124, identifier:_; 125, identifier:_; 126, subscript; 126, 127; 126, 128; 127, identifier:types_creations; 128, identifier:o_type; 129, if_statement; 129, 130; 129, 140; 130, comparison_operator:in; 130, 131; 130, 132; 131, identifier:prop; 132, list:['arbiters', 'brokers', 'schedulers',
'pollers', 'reactionners', 'receivers', 'modules']; 132, 133; 132, 134; 132, 135; 132, 136; 132, 137; 132, 138; 132, 139; 133, string:'arbiters'; 134, string:'brokers'; 135, string:'schedulers'; 136, string:'pollers'; 137, string:'reactionners'; 138, string:'receivers'; 139, string:'modules'; 140, block; 140, 141; 141, continue_statement; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:not; 143, 144; 143, 145; 144, identifier:prop; 145, identifier:got_objects; 146, block; 146, 147; 146, 158; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:logger; 151, identifier:warning; 152, argument_list; 152, 153; 152, 154; 152, 155; 153, string:"Did not get any '%s' objects from %s"; 154, identifier:prop; 155, attribute; 155, 156; 155, 157; 156, identifier:instance; 157, identifier:name; 158, continue_statement; 159, for_statement; 159, 160; 159, 161; 159, 164; 159, 165; 160, identifier:obj; 161, subscript; 161, 162; 161, 163; 162, identifier:got_objects; 163, identifier:prop; 164, comment; 165, block; 165, 166; 165, 177; 165, 178; 165, 193; 165, 194; 166, if_statement; 166, 167; 166, 170; 167, comparison_operator:not; 167, 168; 167, 169; 168, identifier:o_type; 169, identifier:raw_objects; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, subscript; 173, 174; 173, 175; 174, identifier:raw_objects; 175, identifier:o_type; 176, list:[]; 177, comment; 178, if_statement; 178, 179; 178, 182; 179, comparison_operator:not; 179, 180; 179, 181; 180, string:'imported_from'; 181, identifier:obj; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:obj; 187, string:'imported_from'; 188, binary_operator:%; 188, 189; 188, 190; 189, string:'module:%s'; 190, attribute; 190, 191; 190, 192; 191, identifier:instance; 192, identifier:name; 193, comment; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:raw_objects; 199, identifier:o_type; 200, identifier:append; 201, argument_list; 201, 202; 202, identifier:obj; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:logger; 207, identifier:debug; 208, argument_list; 208, 209; 208, 210; 208, 216; 208, 217; 209, string:"Added %i %s objects from %s"; 210, call; 210, 211; 210, 212; 211, identifier:len; 212, argument_list; 212, 213; 213, subscript; 213, 214; 213, 215; 214, identifier:got_objects; 215, identifier:prop; 216, identifier:o_type; 217, attribute; 217, 218; 217, 219; 218, identifier:instance; 219, identifier:name | def load_modules_configuration_objects(self, raw_objects): # pragma: no cover,
# not yet with unit tests.
"""Load configuration objects from arbiter modules
If module implements get_objects arbiter will call it and add create
objects
:param raw_objects: raw objects we got from reading config files
:type raw_objects: dict
:return: None
"""
# Now we ask for configuration modules if they
# got items for us
for instance in self.modules_manager.instances:
logger.debug("Getting objects from the module: %s", instance.name)
if not hasattr(instance, 'get_objects'):
logger.debug("The module '%s' do not provide any objects.", instance.name)
return
try:
logger.info("Getting Alignak monitored configuration objects from module '%s'",
instance.name)
got_objects = instance.get_objects()
except Exception as exp: # pylint: disable=broad-except
logger.exception("Module %s get_objects raised an exception %s. "
"Log and continue to run.", instance.name, exp)
continue
if not got_objects:
logger.warning("The module '%s' did not provided any objects.", instance.name)
return
types_creations = self.conf.types_creations
for o_type in types_creations:
(_, _, prop, _, _) = types_creations[o_type]
if prop in ['arbiters', 'brokers', 'schedulers',
'pollers', 'reactionners', 'receivers', 'modules']:
continue
if prop not in got_objects:
logger.warning("Did not get any '%s' objects from %s", prop, instance.name)
continue
for obj in got_objects[prop]:
# test if raw_objects[k] are already set - if not, add empty array
if o_type not in raw_objects:
raw_objects[o_type] = []
# Update the imported_from property if the module did not set
if 'imported_from' not in obj:
obj['imported_from'] = 'module:%s' % instance.name
# Append to the raw objects
raw_objects[o_type].append(obj)
logger.debug("Added %i %s objects from %s",
len(got_objects[prop]), o_type, instance.name) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 2, function_name:load_modules_alignak_configuration; 3, parameters; 3, 4; 4, identifier:self; 5, comment; 6, block; 6, 7; 6, 9; 6, 13; 6, 14; 6, 117; 6, 121; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:alignak_cfg; 12, dictionary; 13, comment; 14, for_statement; 14, 15; 14, 16; 14, 21; 15, identifier:instance; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:modules_manager; 20, identifier:instances; 21, block; 21, 22; 21, 31; 22, if_statement; 22, 23; 22, 29; 23, not_operator; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:hasattr; 26, argument_list; 26, 27; 26, 28; 27, identifier:instance; 28, string:'get_alignak_configuration'; 29, block; 29, 30; 30, return_statement; 31, try_statement; 31, 32; 31, 58; 32, block; 32, 33; 32, 43; 32, 51; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:logger; 37, identifier:info; 38, argument_list; 38, 39; 38, 40; 39, string:"Getting Alignak global configuration from module '%s'"; 40, attribute; 40, 41; 40, 42; 41, identifier:instance; 42, identifier:name; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:cfg; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:instance; 49, identifier:get_alignak_configuration; 50, argument_list; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:alignak_cfg; 55, identifier:update; 56, argument_list; 56, 57; 57, identifier:cfg; 58, except_clause; 58, 59; 58, 63; 58, 64; 59, as_pattern; 59, 60; 59, 61; 60, identifier:Exception; 61, as_pattern_target; 61, 62; 62, identifier:exp; 63, comment; 64, block; 64, 65; 64, 81; 64, 89; 64, 98; 64, 110; 64, 116; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:logger; 69, identifier:error; 70, argument_list; 70, 71; 70, 74; 70, 77; 71, concatenated_string; 71, 72; 71, 73; 72, string:"Module %s get_alignak_configuration raised an exception %s. "; 73, string:"Log and continue to run"; 74, attribute; 74, 75; 74, 76; 75, identifier:instance; 76, identifier:name; 77, call; 77, 78; 77, 79; 78, identifier:str; 79, argument_list; 79, 80; 80, identifier:exp; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:output; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:io; 87, identifier:StringIO; 88, argument_list; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:traceback; 93, identifier:print_exc; 94, argument_list; 94, 95; 95, keyword_argument; 95, 96; 95, 97; 96, identifier:file; 97, identifier:output; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:logger; 102, identifier:error; 103, argument_list; 103, 104; 103, 105; 104, string:"Back trace of this remove: %s"; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:output; 108, identifier:getvalue; 109, argument_list; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:output; 114, identifier:close; 115, argument_list; 116, continue_statement; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:params; 120, list:[]; 121, if_statement; 121, 122; 121, 123; 122, identifier:alignak_cfg; 123, block; 123, 124; 123, 131; 123, 211; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:logger; 128, identifier:info; 129, argument_list; 129, 130; 130, string:"Got Alignak global configuration:"; 131, for_statement; 131, 132; 131, 135; 131, 143; 132, pattern_list; 132, 133; 132, 134; 133, identifier:key; 134, identifier:value; 135, call; 135, 136; 135, 137; 136, identifier:sorted; 137, argument_list; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:alignak_cfg; 141, identifier:items; 142, argument_list; 143, block; 143, 144; 143, 153; 143, 154; 143, 178; 143, 179; 143, 185; 143, 186; 143, 192; 143, 193; 143, 199; 143, 200; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:logger; 148, identifier:info; 149, argument_list; 149, 150; 149, 151; 149, 152; 150, string:"- %s = %s"; 151, identifier:key; 152, identifier:value; 153, comment; 154, if_statement; 154, 155; 154, 161; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:key; 158, identifier:startswith; 159, argument_list; 159, 160; 160, string:'_'; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:key; 165, binary_operator:+; 165, 166; 165, 177; 166, binary_operator:+; 166, 167; 166, 168; 167, string:'$'; 168, call; 168, 169; 168, 176; 169, attribute; 169, 170; 169, 175; 170, subscript; 170, 171; 170, 172; 171, identifier:key; 172, slice; 172, 173; 172, 174; 173, integer:1; 174, colon; 175, identifier:upper; 176, argument_list; 177, string:'$'; 178, comment; 179, if_statement; 179, 180; 179, 183; 180, comparison_operator:is; 180, 181; 180, 182; 181, identifier:value; 182, None; 183, block; 183, 184; 184, continue_statement; 185, comment; 186, if_statement; 186, 187; 186, 190; 187, comparison_operator:==; 187, 188; 187, 189; 188, identifier:value; 189, string:'None'; 190, block; 190, 191; 191, continue_statement; 192, comment; 193, if_statement; 193, 194; 193, 197; 194, comparison_operator:==; 194, 195; 194, 196; 195, identifier:value; 196, string:''; 197, block; 197, 198; 198, continue_statement; 199, comment; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:params; 204, identifier:append; 205, argument_list; 205, 206; 206, binary_operator:%; 206, 207; 206, 208; 207, string:"%s=%s"; 208, tuple; 208, 209; 208, 210; 209, identifier:key; 210, identifier:value; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:conf; 217, identifier:load_params; 218, argument_list; 218, 219; 219, identifier:params | def load_modules_alignak_configuration(self): # pragma: no cover, not yet with unit tests.
"""Load Alignak configuration from the arbiter modules
If module implements get_alignak_configuration, call this function
:param raw_objects: raw objects we got from reading config files
:type raw_objects: dict
:return: None
"""
alignak_cfg = {}
# Ask configured modules if they got configuration for us
for instance in self.modules_manager.instances:
if not hasattr(instance, 'get_alignak_configuration'):
return
try:
logger.info("Getting Alignak global configuration from module '%s'", instance.name)
cfg = instance.get_alignak_configuration()
alignak_cfg.update(cfg)
except Exception as exp: # pylint: disable=broad-except
logger.error("Module %s get_alignak_configuration raised an exception %s. "
"Log and continue to run", instance.name, str(exp))
output = io.StringIO()
traceback.print_exc(file=output)
logger.error("Back trace of this remove: %s", output.getvalue())
output.close()
continue
params = []
if alignak_cfg:
logger.info("Got Alignak global configuration:")
for key, value in sorted(alignak_cfg.items()):
logger.info("- %s = %s", key, value)
# properties starting with an _ character are "transformed" to macro variables
if key.startswith('_'):
key = '$' + key[1:].upper() + '$'
# properties valued as None are filtered
if value is None:
continue
# properties valued as None string are filtered
if value == 'None':
continue
# properties valued as empty strings are filtered
if value == '':
continue
# set properties as legacy Shinken configuration files
params.append("%s=%s" % (key, value))
self.conf.load_params(params) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:daemons_start; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:run_daemons; 7, True; 8, block; 8, 9; 8, 11; 8, 15; 8, 34; 8, 35; 8, 209; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:result; 14, True; 15, if_statement; 15, 16; 15, 17; 15, 25; 16, identifier:run_daemons; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:logger; 22, identifier:info; 23, argument_list; 23, 24; 24, string:"Alignak configured daemons start:"; 25, else_clause; 25, 26; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:logger; 31, identifier:info; 32, argument_list; 32, 33; 33, string:"Alignak configured daemons check:"; 34, comment; 35, for_statement; 35, 36; 35, 37; 35, 68; 36, identifier:satellites_list; 37, list:[self.conf.arbiters, self.conf.receivers, self.conf.reactionners,
self.conf.pollers, self.conf.brokers, self.conf.schedulers]; 37, 38; 37, 43; 37, 48; 37, 53; 37, 58; 37, 63; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:conf; 42, identifier:arbiters; 43, attribute; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:conf; 47, identifier:receivers; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:conf; 52, identifier:reactionners; 53, attribute; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:conf; 57, identifier:pollers; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:conf; 62, identifier:brokers; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:conf; 67, identifier:schedulers; 68, block; 68, 69; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:satellite; 71, identifier:satellites_list; 72, block; 72, 73; 72, 89; 72, 98; 72, 135; 72, 141; 72, 155; 72, 174; 72, 194; 72, 203; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:logger; 77, identifier:info; 78, argument_list; 78, 79; 78, 80; 78, 83; 78, 86; 79, string:"- found %s, to be launched: %s, address: %s"; 80, attribute; 80, 81; 80, 82; 81, identifier:satellite; 82, identifier:name; 83, attribute; 83, 84; 83, 85; 84, identifier:satellite; 85, identifier:alignak_launched; 86, attribute; 86, 87; 86, 88; 87, identifier:satellite; 88, identifier:uri; 89, if_statement; 89, 90; 89, 95; 89, 96; 90, comparison_operator:==; 90, 91; 90, 92; 91, identifier:satellite; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:link_to_myself; 95, comment; 96, block; 96, 97; 97, continue_statement; 98, if_statement; 98, 99; 98, 111; 99, boolean_operator:and; 99, 100; 99, 103; 99, 104; 100, attribute; 100, 101; 100, 102; 101, identifier:satellite; 102, identifier:alignak_launched; 103, line_continuation:\; 104, comparison_operator:not; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:satellite; 107, identifier:address; 108, list:['127.0.0.1', 'localhost']; 108, 109; 108, 110; 109, string:'127.0.0.1'; 110, string:'localhost'; 111, block; 111, 112; 111, 130; 111, 134; 112, expression_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:logger; 116, identifier:error; 117, argument_list; 117, 118; 117, 121; 117, 124; 117, 127; 118, concatenated_string; 118, 119; 118, 120; 119, string:"Alignak is required to launch a daemon for %s %s "; 120, string:"but the satelitte is defined on an external address: %s"; 121, attribute; 121, 122; 121, 123; 122, identifier:satellite; 123, identifier:type; 124, attribute; 124, 125; 124, 126; 125, identifier:satellite; 126, identifier:name; 127, attribute; 127, 128; 127, 129; 128, identifier:satellite; 129, identifier:address; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:result; 133, False; 134, continue_statement; 135, if_statement; 135, 136; 135, 138; 135, 139; 136, not_operator; 136, 137; 137, identifier:run_daemons; 138, comment; 139, block; 139, 140; 140, continue_statement; 141, if_statement; 141, 142; 141, 146; 142, not_operator; 142, 143; 143, attribute; 143, 144; 143, 145; 144, identifier:satellite; 145, identifier:alignak_launched; 146, block; 146, 147; 146, 154; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:logger; 151, identifier:debug; 152, argument_list; 152, 153; 153, string:"Alignak will not launch '%s'"; 154, continue_statement; 155, if_statement; 155, 156; 155, 160; 156, not_operator; 156, 157; 157, attribute; 157, 158; 157, 159; 158, identifier:satellite; 159, identifier:active; 160, block; 160, 161; 160, 173; 161, expression_statement; 161, 162; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:logger; 165, identifier:warning; 166, argument_list; 166, 167; 166, 170; 167, concatenated_string; 167, 168; 167, 169; 168, string:"- daemon '%s' is declared but not set as active, "; 169, string:"do not start..."; 170, attribute; 170, 171; 170, 172; 171, identifier:satellite; 172, identifier:name; 173, continue_statement; 174, if_statement; 174, 175; 174, 182; 175, comparison_operator:in; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:satellite; 178, identifier:name; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:my_daemons; 182, block; 182, 183; 182, 193; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:logger; 187, identifier:warning; 188, argument_list; 188, 189; 188, 190; 189, string:"- daemon '%s' is already running"; 190, attribute; 190, 191; 190, 192; 191, identifier:satellite; 192, identifier:name; 193, continue_statement; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:started; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:start_daemon; 201, argument_list; 201, 202; 202, identifier:satellite; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:result; 206, boolean_operator:and; 206, 207; 206, 208; 207, identifier:result; 208, identifier:started; 209, return_statement; 209, 210; 210, identifier:result | def daemons_start(self, run_daemons=True):
"""Manage the list of the daemons in the configuration
Check if the daemon needs to be started by the Arbiter.
If so, starts the daemon if `run_daemons` is True
:param run_daemons: run the daemons or make a simple check
:type run_daemons: bool
:return: True if all daemons are running, else False. always True for a simple check
"""
result = True
if run_daemons:
logger.info("Alignak configured daemons start:")
else:
logger.info("Alignak configured daemons check:")
# Parse the list of the missing daemons and try to run the corresponding processes
for satellites_list in [self.conf.arbiters, self.conf.receivers, self.conf.reactionners,
self.conf.pollers, self.conf.brokers, self.conf.schedulers]:
for satellite in satellites_list:
logger.info("- found %s, to be launched: %s, address: %s",
satellite.name, satellite.alignak_launched, satellite.uri)
if satellite == self.link_to_myself:
# Ignore myself ;)
continue
if satellite.alignak_launched and \
satellite.address not in ['127.0.0.1', 'localhost']:
logger.error("Alignak is required to launch a daemon for %s %s "
"but the satelitte is defined on an external address: %s",
satellite.type, satellite.name, satellite.address)
result = False
continue
if not run_daemons:
# When checking, ignore the daemon launch part...
continue
if not satellite.alignak_launched:
logger.debug("Alignak will not launch '%s'")
continue
if not satellite.active:
logger.warning("- daemon '%s' is declared but not set as active, "
"do not start...", satellite.name)
continue
if satellite.name in self.my_daemons:
logger.warning("- daemon '%s' is already running", satellite.name)
continue
started = self.start_daemon(satellite)
result = result and started
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:daemons_stop; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:timeout; 7, integer:30; 8, default_parameter; 8, 9; 8, 10; 9, identifier:kill_children; 10, False; 11, block; 11, 12; 11, 14; 11, 34; 11, 38; 11, 282; 12, expression_statement; 12, 13; 13, comment; 14, function_definition; 14, 15; 14, 16; 14, 18; 15, function_name:on_terminate; 16, parameters; 16, 17; 17, identifier:proc; 18, block; 18, 19; 18, 21; 19, expression_statement; 19, 20; 20, comment; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:logger; 25, identifier:debug; 26, argument_list; 26, 27; 26, 28; 26, 31; 27, string:"process %s terminated with exit code %s"; 28, attribute; 28, 29; 28, 30; 29, identifier:proc; 30, identifier:pid; 31, attribute; 31, 32; 31, 33; 32, identifier:proc; 33, identifier:returncode; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:result; 37, True; 38, if_statement; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:my_daemons; 42, block; 42, 43; 42, 50; 42, 58; 42, 144; 42, 148; 42, 184; 42, 201; 42, 268; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:logger; 47, identifier:info; 48, argument_list; 48, 49; 49, string:"Alignak self-launched daemons stop:"; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:start; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:time; 56, identifier:time; 57, argument_list; 58, for_statement; 58, 59; 58, 60; 58, 70; 58, 71; 59, identifier:daemon; 60, call; 60, 61; 60, 62; 61, identifier:list; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:my_daemons; 68, identifier:values; 69, argument_list; 70, comment; 71, block; 71, 72; 71, 76; 71, 89; 71, 98; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:procs; 75, list:[]; 76, if_statement; 76, 77; 76, 78; 77, identifier:kill_children; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:procs; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, subscript; 84, 85; 84, 86; 85, identifier:daemon; 86, string:'process'; 87, identifier:children; 88, argument_list; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:procs; 93, identifier:append; 94, argument_list; 94, 95; 95, subscript; 95, 96; 95, 97; 96, identifier:daemon; 97, string:'process'; 98, for_statement; 98, 99; 98, 100; 98, 101; 99, identifier:process; 100, identifier:procs; 101, block; 101, 102; 102, try_statement; 102, 103; 102, 122; 103, block; 103, 104; 103, 116; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:logger; 108, identifier:info; 109, argument_list; 109, 110; 109, 111; 110, string:"- terminating process %s"; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:process; 114, identifier:name; 115, argument_list; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:process; 120, identifier:terminate; 121, argument_list; 122, except_clause; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:psutil; 125, identifier:AccessDenied; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:logger; 131, identifier:warning; 132, argument_list; 132, 133; 132, 134; 132, 139; 133, string:"Process %s is %s"; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:process; 137, identifier:name; 138, argument_list; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:process; 142, identifier:status; 143, argument_list; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:procs; 147, list:[]; 148, for_statement; 148, 149; 148, 150; 148, 160; 148, 161; 149, identifier:daemon; 150, call; 150, 151; 150, 152; 151, identifier:list; 152, argument_list; 152, 153; 153, call; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:my_daemons; 158, identifier:values; 159, argument_list; 160, comment; 161, block; 161, 162; 161, 175; 162, if_statement; 162, 163; 162, 164; 163, identifier:kill_children; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:procs; 168, call; 168, 169; 168, 174; 169, attribute; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:daemon; 172, string:'process'; 173, identifier:children; 174, argument_list; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:procs; 179, identifier:append; 180, argument_list; 180, 181; 181, subscript; 181, 182; 181, 183; 182, identifier:daemon; 183, string:'process'; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 189; 186, pattern_list; 186, 187; 186, 188; 187, identifier:_; 188, identifier:alive; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:psutil; 192, identifier:wait_procs; 193, argument_list; 193, 194; 193, 195; 193, 198; 194, identifier:procs; 195, keyword_argument; 195, 196; 195, 197; 196, identifier:timeout; 197, identifier:timeout; 198, keyword_argument; 198, 199; 198, 200; 199, identifier:callback; 200, identifier:on_terminate; 201, if_statement; 201, 202; 201, 203; 201, 204; 202, identifier:alive; 203, comment; 204, block; 204, 205; 204, 227; 204, 244; 205, for_statement; 205, 206; 205, 207; 205, 208; 206, identifier:process; 207, identifier:alive; 208, block; 208, 209; 208, 221; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:logger; 213, identifier:warning; 214, argument_list; 214, 215; 214, 216; 215, string:"Process %s did not stopped, trying to kill"; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:process; 219, identifier:name; 220, argument_list; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:process; 225, identifier:kill; 226, argument_list; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 232; 229, pattern_list; 229, 230; 229, 231; 230, identifier:_; 231, identifier:alive; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:psutil; 235, identifier:wait_procs; 236, argument_list; 236, 237; 236, 238; 236, 241; 237, identifier:alive; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:timeout; 240, identifier:timeout; 241, keyword_argument; 241, 242; 241, 243; 242, identifier:callback; 243, identifier:on_terminate; 244, if_statement; 244, 245; 244, 246; 244, 247; 245, identifier:alive; 246, comment; 247, block; 247, 248; 248, for_statement; 248, 249; 248, 250; 248, 251; 249, identifier:process; 250, identifier:alive; 251, block; 251, 252; 251, 264; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:logger; 256, identifier:warning; 257, argument_list; 257, 258; 257, 259; 258, string:"process %s survived SIGKILL; giving up"; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:process; 262, identifier:name; 263, argument_list; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:result; 267, False; 268, expression_statement; 268, 269; 269, call; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:logger; 272, identifier:debug; 273, argument_list; 273, 274; 273, 275; 274, string:"Stopping daemons duration: %.2f seconds"; 275, binary_operator:-; 275, 276; 275, 281; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:time; 279, identifier:time; 280, argument_list; 281, identifier:start; 282, return_statement; 282, 283; 283, identifier:result | def daemons_stop(self, timeout=30, kill_children=False):
"""Stop the Alignak daemons
Iterate over the self-launched daemons and their children list to send a TERM
Wait for daemons to terminate and then send a KILL for those that are not yet stopped
As a default behavior, only the launched daemons are killed, not their children.
Each daemon will manage its children killing
:param timeout: delay to wait before killing a daemon
:type timeout: int
:param kill_children: also kill the children (defaults to False)
:type kill_children: bool
:return: True if all daemons stopped
"""
def on_terminate(proc):
"""Process termination callback function"""
logger.debug("process %s terminated with exit code %s", proc.pid, proc.returncode)
result = True
if self.my_daemons:
logger.info("Alignak self-launched daemons stop:")
start = time.time()
for daemon in list(self.my_daemons.values()):
# Terminate the daemon and its children process
procs = []
if kill_children:
procs = daemon['process'].children()
procs.append(daemon['process'])
for process in procs:
try:
logger.info("- terminating process %s", process.name())
process.terminate()
except psutil.AccessDenied:
logger.warning("Process %s is %s", process.name(), process.status())
procs = []
for daemon in list(self.my_daemons.values()):
# Stop the daemon and its children process
if kill_children:
procs = daemon['process'].children()
procs.append(daemon['process'])
_, alive = psutil.wait_procs(procs, timeout=timeout, callback=on_terminate)
if alive:
# Kill processes
for process in alive:
logger.warning("Process %s did not stopped, trying to kill", process.name())
process.kill()
_, alive = psutil.wait_procs(alive, timeout=timeout, callback=on_terminate)
if alive:
# give up
for process in alive:
logger.warning("process %s survived SIGKILL; giving up", process.name())
result = False
logger.debug("Stopping daemons duration: %.2f seconds", time.time() - start)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 1, 6; 2, function_name:setup_new_conf; 3, parameters; 3, 4; 4, identifier:self; 5, comment; 6, block; 6, 7; 6, 9; 6, 10; 6, 20; 6, 456; 6, 457; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 19; 12, attribute; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:super; 15, argument_list; 15, 16; 15, 17; 16, identifier:Arbiter; 17, identifier:self; 18, identifier:setup_new_conf; 19, argument_list; 20, with_statement; 20, 21; 20, 26; 21, with_clause; 21, 22; 22, with_item; 22, 23; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:conf_lock; 26, block; 26, 27; 26, 34; 26, 35; 26, 43; 26, 44; 26, 45; 26, 46; 26, 58; 26, 68; 26, 69; 26, 77; 26, 84; 26, 103; 26, 111; 26, 112; 26, 122; 26, 132; 26, 133; 26, 139; 26, 140; 26, 148; 26, 245; 26, 261; 26, 262; 26, 271; 26, 279; 26, 441; 26, 442; 26, 443; 26, 444; 26, 445; 26, 446; 26, 447; 26, 448; 26, 449; 26, 450; 26, 451; 26, 452; 26, 453; 26, 454; 26, 455; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:logger; 31, identifier:info; 32, argument_list; 32, 33; 33, string:"I received a new configuration from my master"; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:cur_conf; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:new_conf; 43, comment; 44, comment; 45, comment; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:self_conf; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:cur_conf; 54, identifier:get; 55, argument_list; 55, 56; 55, 57; 56, string:'self_conf'; 57, None; 58, if_statement; 58, 59; 58, 61; 59, not_operator; 59, 60; 60, identifier:self_conf; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:self_conf; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:conf; 68, comment; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:whole_conf; 72, subscript; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:cur_conf; 76, string:'whole_conf'; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:logger; 81, identifier:debug; 82, argument_list; 82, 83; 83, string:"Received a new configuration, containing:"; 84, for_statement; 84, 85; 84, 86; 84, 89; 85, identifier:key; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:cur_conf; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:logger; 94, identifier:debug; 95, argument_list; 95, 96; 95, 97; 95, 98; 96, string:"- %s: %s"; 97, identifier:key; 98, subscript; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:cur_conf; 102, identifier:key; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:logger; 107, identifier:debug; 108, argument_list; 108, 109; 108, 110; 109, string:"satellite self configuration part: %s"; 110, identifier:self_conf; 111, comment; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:alignak_name; 117, subscript; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:cur_conf; 121, string:'alignak_name'; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:logger; 126, identifier:info; 127, argument_list; 127, 128; 127, 129; 128, string:"My Alignak instance: %s"; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:alignak_name; 132, comment; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:new_conf; 138, dictionary; 139, comment; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:t00; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:time; 146, identifier:time; 147, argument_list; 148, try_statement; 148, 149; 148, 157; 148, 198; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:received_conf_part; 153, call; 153, 154; 153, 155; 154, identifier:unserialize; 155, argument_list; 155, 156; 156, identifier:whole_conf; 157, except_clause; 157, 158; 157, 162; 157, 163; 157, 164; 158, as_pattern; 158, 159; 158, 160; 159, identifier:AlignakClassLookupException; 160, as_pattern_target; 160, 161; 161, identifier:exp; 162, comment; 163, comment; 164, block; 164, 165; 164, 174; 164, 185; 164, 197; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:new_conf; 170, dictionary; 170, 171; 171, pair; 171, 172; 171, 173; 172, string:"_status"; 173, string:"Cannot un-serialize configuration received from arbiter"; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:logger; 178, identifier:error; 179, argument_list; 179, 180; 180, subscript; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:new_conf; 184, string:'_status'; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:logger; 189, identifier:error; 190, argument_list; 190, 191; 190, 192; 191, string:"Back trace of the error:\n%s"; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:traceback; 195, identifier:format_exc; 196, argument_list; 197, return_statement; 198, except_clause; 198, 199; 198, 203; 198, 204; 198, 205; 199, as_pattern; 199, 200; 199, 201; 200, identifier:Exception; 201, as_pattern_target; 201, 202; 202, identifier:exp; 203, comment; 204, comment; 205, block; 205, 206; 205, 215; 205, 226; 205, 235; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:self; 210, identifier:new_conf; 211, dictionary; 211, 212; 212, pair; 212, 213; 212, 214; 213, string:"_status"; 214, string:"Cannot un-serialize configuration received from arbiter"; 215, expression_statement; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:logger; 219, identifier:error; 220, argument_list; 220, 221; 221, subscript; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:new_conf; 225, string:'_status'; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:logger; 230, identifier:error; 231, argument_list; 231, 232; 232, attribute; 232, 233; 232, 234; 233, identifier:self; 234, identifier:new_conf; 235, expression_statement; 235, 236; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:exit_on_exception; 240, argument_list; 240, 241; 240, 242; 241, identifier:exp; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:new_conf; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:logger; 249, identifier:info; 250, argument_list; 250, 251; 250, 252; 250, 253; 250, 254; 251, string:"Monitored configuration %s received at %d. Un-serialized in %d secs"; 252, identifier:received_conf_part; 253, identifier:t00; 254, binary_operator:-; 254, 255; 254, 260; 255, call; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:time; 258, identifier:time; 259, argument_list; 260, identifier:t00; 261, comment; 262, expression_statement; 262, 263; 263, assignment; 263, 264; 263, 265; 264, identifier:my_satellites; 265, call; 265, 266; 265, 267; 266, identifier:getattr; 267, argument_list; 267, 268; 267, 269; 267, 270; 268, identifier:self; 269, string:'arbiters'; 270, dictionary; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:received_satellites; 274, subscript; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:cur_conf; 278, string:'arbiters'; 279, for_statement; 279, 280; 279, 281; 279, 282; 280, identifier:link_uuid; 281, identifier:received_satellites; 282, block; 282, 283; 282, 289; 282, 305; 282, 306; 282, 314; 282, 318; 282, 322; 282, 326; 282, 330; 282, 334; 282, 376; 282, 377; 282, 387; 282, 395; 282, 403; 282, 409; 282, 415; 282, 421; 282, 427; 282, 433; 282, 434; 282, 435; 282, 436; 282, 437; 282, 438; 282, 439; 282, 440; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:rs_conf; 286, subscript; 286, 287; 286, 288; 287, identifier:received_satellites; 288, identifier:link_uuid; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:logger; 293, identifier:debug; 294, argument_list; 294, 295; 294, 296; 294, 299; 294, 302; 295, string:"- received %s - %s: %s"; 296, subscript; 296, 297; 296, 298; 297, identifier:rs_conf; 298, string:'instance_id'; 299, subscript; 299, 300; 299, 301; 300, identifier:rs_conf; 301, string:'type'; 302, subscript; 302, 303; 302, 304; 303, identifier:rs_conf; 304, string:'name'; 305, comment; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:already_got; 309, comparison_operator:in; 309, 310; 309, 313; 310, subscript; 310, 311; 310, 312; 311, identifier:rs_conf; 312, string:'instance_id'; 313, identifier:my_satellites; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:broks; 317, list:[]; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:actions; 321, dictionary; 322, expression_statement; 322, 323; 323, assignment; 323, 324; 323, 325; 324, identifier:wait_homerun; 325, dictionary; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 329; 328, identifier:external_commands; 329, dictionary; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 333; 332, identifier:running_id; 333, integer:0; 334, if_statement; 334, 335; 334, 336; 335, identifier:already_got; 336, block; 336, 337; 336, 347; 336, 348; 336, 356; 336, 371; 336, 372; 337, expression_statement; 337, 338; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:logger; 341, identifier:warning; 342, argument_list; 342, 343; 342, 344; 343, string:"I already got: %s"; 344, subscript; 344, 345; 344, 346; 345, identifier:rs_conf; 346, string:'instance_id'; 347, comment; 348, expression_statement; 348, 349; 349, assignment; 349, 350; 349, 351; 350, identifier:running_id; 351, attribute; 351, 352; 351, 355; 352, subscript; 352, 353; 352, 354; 353, identifier:my_satellites; 354, identifier:link_uuid; 355, identifier:running_id; 356, expression_statement; 356, 357; 357, assignment; 357, 358; 357, 363; 357, 364; 358, tuple_pattern; 358, 359; 358, 360; 358, 361; 358, 362; 359, identifier:broks; 360, identifier:actions; 361, identifier:wait_homerun; 362, identifier:external_commands; 363, line_continuation:\; 364, call; 364, 365; 364, 370; 365, attribute; 365, 366; 365, 369; 366, subscript; 366, 367; 366, 368; 367, identifier:my_satellites; 368, identifier:link_uuid; 369, identifier:get_and_clear_context; 370, argument_list; 371, comment; 372, delete_statement; 372, 373; 373, subscript; 373, 374; 373, 375; 374, identifier:my_satellites; 375, identifier:link_uuid; 376, comment; 377, expression_statement; 377, 378; 378, assignment; 378, 379; 378, 380; 379, identifier:new_link; 380, call; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:SatelliteLink; 383, identifier:get_a_satellite_link; 384, argument_list; 384, 385; 384, 386; 385, string:'arbiter'; 386, identifier:rs_conf; 387, expression_statement; 387, 388; 388, assignment; 388, 389; 388, 394; 389, subscript; 389, 390; 389, 391; 390, identifier:my_satellites; 391, attribute; 391, 392; 391, 393; 392, identifier:new_link; 393, identifier:uuid; 394, identifier:new_link; 395, expression_statement; 395, 396; 396, call; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:logger; 399, identifier:info; 400, argument_list; 400, 401; 400, 402; 401, string:"I got a new arbiter satellite: %s"; 402, identifier:new_link; 403, expression_statement; 403, 404; 404, assignment; 404, 405; 404, 408; 405, attribute; 405, 406; 405, 407; 406, identifier:new_link; 407, identifier:running_id; 408, identifier:running_id; 409, expression_statement; 409, 410; 410, assignment; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:new_link; 413, identifier:external_commands; 414, identifier:external_commands; 415, expression_statement; 415, 416; 416, assignment; 416, 417; 416, 420; 417, attribute; 417, 418; 417, 419; 418, identifier:new_link; 419, identifier:broks; 420, identifier:broks; 421, expression_statement; 421, 422; 422, assignment; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:new_link; 425, identifier:wait_homerun; 426, identifier:wait_homerun; 427, expression_statement; 427, 428; 428, assignment; 428, 429; 428, 432; 429, attribute; 429, 430; 429, 431; 430, identifier:new_link; 431, identifier:actions; 432, identifier:actions; 433, comment; 434, comment; 435, comment; 436, comment; 437, comment; 438, comment; 439, comment; 440, comment; 441, comment; 442, comment; 443, comment; 444, comment; 445, comment; 446, comment; 447, comment; 448, comment; 449, comment; 450, comment; 451, comment; 452, comment; 453, comment; 454, comment; 455, comment; 456, comment; 457, expression_statement; 457, 458; 458, assignment; 458, 459; 458, 462; 459, attribute; 459, 460; 459, 461; 460, identifier:self; 461, identifier:have_conf; 462, True | def setup_new_conf(self):
# pylint: disable=too-many-locals
""" Setup a new configuration received from a Master arbiter.
TODO: perharps we should not accept the configuration or raise an error if we do not
find our own configuration data in the data. Thus this should never happen...
:return: None
"""
# Execute the base class treatment...
super(Arbiter, self).setup_new_conf()
with self.conf_lock:
logger.info("I received a new configuration from my master")
# Get the new configuration
self.cur_conf = self.new_conf
# self_conf is our own configuration from the alignak environment
# Arbiters do not have this property in the received configuration because
# they already loaded a configuration on daemon load
self_conf = self.cur_conf.get('self_conf', None)
if not self_conf:
self_conf = self.conf
# whole_conf contains the full configuration load by my master
whole_conf = self.cur_conf['whole_conf']
logger.debug("Received a new configuration, containing:")
for key in self.cur_conf:
logger.debug("- %s: %s", key, self.cur_conf[key])
logger.debug("satellite self configuration part: %s", self_conf)
# Update Alignak name
self.alignak_name = self.cur_conf['alignak_name']
logger.info("My Alignak instance: %s", self.alignak_name)
# This to indicate that the new configuration got managed...
self.new_conf = {}
# Get the whole monitored objects configuration
t00 = time.time()
try:
received_conf_part = unserialize(whole_conf)
except AlignakClassLookupException as exp: # pragma: no cover, simple protection
# This to indicate that the new configuration is not managed...
self.new_conf = {
"_status": "Cannot un-serialize configuration received from arbiter"
}
logger.error(self.new_conf['_status'])
logger.error("Back trace of the error:\n%s", traceback.format_exc())
return
except Exception as exp: # pylint: disable=broad-except
# This to indicate that the new configuration is not managed...
self.new_conf = {
"_status": "Cannot un-serialize configuration received from arbiter"
}
logger.error(self.new_conf['_status'])
logger.error(self.new_conf)
self.exit_on_exception(exp, self.new_conf)
logger.info("Monitored configuration %s received at %d. Un-serialized in %d secs",
received_conf_part, t00, time.time() - t00)
# Now we create our arbiters and schedulers links
my_satellites = getattr(self, 'arbiters', {})
received_satellites = self.cur_conf['arbiters']
for link_uuid in received_satellites:
rs_conf = received_satellites[link_uuid]
logger.debug("- received %s - %s: %s", rs_conf['instance_id'],
rs_conf['type'], rs_conf['name'])
# Must look if we already had a configuration and save our broks
already_got = rs_conf['instance_id'] in my_satellites
broks = []
actions = {}
wait_homerun = {}
external_commands = {}
running_id = 0
if already_got:
logger.warning("I already got: %s", rs_conf['instance_id'])
# Save some information
running_id = my_satellites[link_uuid].running_id
(broks, actions,
wait_homerun, external_commands) = \
my_satellites[link_uuid].get_and_clear_context()
# Delete the former link
del my_satellites[link_uuid]
# My new satellite link...
new_link = SatelliteLink.get_a_satellite_link('arbiter', rs_conf)
my_satellites[new_link.uuid] = new_link
logger.info("I got a new arbiter satellite: %s", new_link)
new_link.running_id = running_id
new_link.external_commands = external_commands
new_link.broks = broks
new_link.wait_homerun = wait_homerun
new_link.actions = actions
# # replacing satellite address and port by those defined in satellite_map
# if new_link.name in self_conf.satellite_map:
# overriding = self_conf.satellite_map[new_link.name]
# # satellite = dict(satellite) # make a copy
# # new_link.update(self_conf.get('satellite_map', {})[new_link.name])
# logger.warning("Do not override the configuration for: %s, with: %s. "
# "Please check whether this is necessary!",
# new_link.name, overriding)
# for arbiter_link in received_conf_part.arbiters:
# logger.info("I have arbiter links in my configuration: %s", arbiter_link.name)
# if arbiter_link.name != self.name and not arbiter_link.spare:
# # Arbiter is not me!
# logger.info("I found my master arbiter in the configuration: %s",
# arbiter_link.name)
# continue
#
# logger.info("I found myself in the received configuration: %s", arbiter_link.name)
# self.link_to_myself = arbiter_link
# # We received a configuration s we are not a master !
# self.is_master = False
# self.link_to_myself.spare = True
# # Set myself as alive ;)
# self.link_to_myself.set_alive()
# Now I have a configuration!
self.have_conf = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:wait_for_master_death; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 15; 5, 19; 5, 29; 5, 33; 5, 58; 5, 66; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:logger; 12, identifier:info; 13, argument_list; 13, 14; 14, string:"Waiting for master death"; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:timeout; 18, float:1.0; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:last_master_ping; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:time; 27, identifier:time; 28, argument_list; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:master_timeout; 32, integer:300; 33, for_statement; 33, 34; 33, 35; 33, 40; 34, identifier:arbiter_link; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:conf; 39, identifier:arbiters; 40, block; 40, 41; 41, if_statement; 41, 42; 41, 46; 42, not_operator; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:arbiter_link; 45, identifier:spare; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 48, 51; 49, identifier:master_timeout; 50, line_continuation:\; 51, binary_operator:*; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:arbiter_link; 54, identifier:spare_check_interval; 55, attribute; 55, 56; 55, 57; 56, identifier:arbiter_link; 57, identifier:spare_max_check_attempts; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:logger; 62, identifier:info; 63, argument_list; 63, 64; 63, 65; 64, string:"I'll wait master death for %d seconds"; 65, identifier:master_timeout; 66, while_statement; 66, 67; 66, 71; 66, 72; 67, not_operator; 67, 68; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:interrupted; 71, comment; 72, block; 72, 73; 72, 84; 72, 85; 72, 94; 72, 105; 72, 114; 72, 122; 72, 123; 72, 131; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, pattern_list; 75, 76; 75, 77; 76, identifier:_; 77, identifier:tcdiff; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:make_a_pause; 82, argument_list; 82, 83; 83, identifier:timeout; 84, comment; 85, if_statement; 85, 86; 85, 87; 86, identifier:tcdiff; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, augmented_assignment:+=; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:last_master_ping; 93, identifier:tcdiff; 94, if_statement; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:new_conf; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:setup_new_conf; 104, argument_list; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:sys; 110, identifier:stdout; 111, identifier:write; 112, argument_list; 112, 113; 113, string:"."; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:sys; 119, identifier:stdout; 120, identifier:flush; 121, argument_list; 122, comment; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:now; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:time; 129, identifier:time; 130, argument_list; 131, if_statement; 131, 132; 131, 139; 132, comparison_operator:>; 132, 133; 132, 138; 133, binary_operator:-; 133, 134; 133, 135; 134, identifier:now; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:last_master_ping; 138, identifier:master_timeout; 139, block; 139, 140; 139, 152; 139, 172; 139, 178; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:logger; 144, identifier:info; 145, argument_list; 145, 146; 145, 147; 146, string:"Arbiter Master is dead. The arbiter %s takes the lead!"; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:link_to_myself; 151, identifier:name; 152, for_statement; 152, 153; 152, 154; 152, 159; 153, identifier:arbiter_link; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:conf; 158, identifier:arbiters; 159, block; 159, 160; 160, if_statement; 160, 161; 160, 165; 161, not_operator; 161, 162; 162, attribute; 162, 163; 162, 164; 163, identifier:arbiter_link; 164, identifier:spare; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:arbiter_link; 170, identifier:alive; 171, False; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:must_run; 177, True; 178, break_statement | def wait_for_master_death(self):
"""Wait for a master timeout and take the lead if necessary
:return: None
"""
logger.info("Waiting for master death")
timeout = 1.0
self.last_master_ping = time.time()
master_timeout = 300
for arbiter_link in self.conf.arbiters:
if not arbiter_link.spare:
master_timeout = \
arbiter_link.spare_check_interval * arbiter_link.spare_max_check_attempts
logger.info("I'll wait master death for %d seconds", master_timeout)
while not self.interrupted:
# Make a pause and check if the system time changed
_, tcdiff = self.make_a_pause(timeout)
# If there was a system time change then we have to adapt last_master_ping:
if tcdiff:
self.last_master_ping += tcdiff
if self.new_conf:
self.setup_new_conf()
sys.stdout.write(".")
sys.stdout.flush()
# Now check if master is dead or not
now = time.time()
if now - self.last_master_ping > master_timeout:
logger.info("Arbiter Master is dead. The arbiter %s takes the lead!",
self.link_to_myself.name)
for arbiter_link in self.conf.arbiters:
if not arbiter_link.spare:
arbiter_link.alive = False
self.must_run = True
break |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:configuration_dispatch; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:not_configured; 7, None; 8, block; 8, 9; 8, 11; 8, 263; 8, 264; 8, 265; 8, 269; 8, 276; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 14; 12, not_operator; 12, 13; 13, identifier:not_configured; 14, block; 14, 15; 14, 29; 14, 30; 14, 31; 14, 39; 14, 40; 14, 41; 14, 45; 14, 52; 14, 182; 14, 183; 14, 184; 14, 192; 14, 204; 14, 218; 14, 226; 14, 227; 14, 234; 14, 242; 14, 256; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:dispatcher; 20, call; 20, 21; 20, 22; 21, identifier:Dispatcher; 22, argument_list; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:conf; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:link_to_myself; 29, comment; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:cur_conf; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:conf; 39, comment; 40, comment; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:first_connection_try_count; 44, integer:0; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:logger; 49, identifier:info; 50, argument_list; 50, 51; 51, string:"Connecting to my satellites..."; 52, while_statement; 52, 53; 52, 54; 53, True; 54, block; 54, 55; 54, 59; 54, 60; 54, 66; 54, 120; 55, expression_statement; 55, 56; 56, augmented_assignment:+=; 56, 57; 56, 58; 57, identifier:first_connection_try_count; 58, integer:1; 59, comment; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:all_connected; 65, True; 66, for_statement; 66, 67; 66, 68; 66, 73; 67, identifier:satellite; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:dispatcher; 72, identifier:all_daemons_links; 73, block; 73, 74; 73, 82; 73, 89; 73, 101; 73, 110; 74, if_statement; 74, 75; 74, 80; 75, comparison_operator:==; 75, 76; 75, 77; 76, identifier:satellite; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:link_to_myself; 80, block; 80, 81; 81, continue_statement; 82, if_statement; 82, 83; 82, 87; 83, not_operator; 83, 84; 84, attribute; 84, 85; 84, 86; 85, identifier:satellite; 86, identifier:active; 87, block; 87, 88; 88, continue_statement; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:connected; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:daemon_connection_init; 96, argument_list; 96, 97; 96, 98; 97, identifier:satellite; 98, keyword_argument; 98, 99; 98, 100; 99, identifier:set_wait_new_conf; 100, True; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:logger; 105, identifier:debug; 106, argument_list; 106, 107; 106, 108; 106, 109; 107, string:" %s is %s"; 108, identifier:satellite; 109, identifier:connected; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:all_connected; 115, boolean_operator:and; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:all_connected; 119, identifier:connected; 120, if_statement; 120, 121; 120, 124; 120, 134; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:all_connected; 124, block; 124, 125; 124, 133; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:logger; 129, identifier:info; 130, argument_list; 130, 131; 130, 132; 131, string:"- satellites connection #%s is ok"; 132, identifier:first_connection_try_count; 133, break_statement; 134, else_clause; 134, 135; 135, block; 135, 136; 135, 151; 135, 171; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:logger; 140, identifier:warning; 141, argument_list; 141, 142; 141, 145; 141, 146; 142, concatenated_string; 142, 143; 142, 144; 143, string:"- satellites connection #%s is not correct; "; 144, string:"let's give another chance after %d seconds..."; 145, identifier:first_connection_try_count; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:link_to_myself; 150, identifier:polling_interval; 151, if_statement; 151, 152; 151, 155; 152, comparison_operator:>=; 152, 153; 152, 154; 153, identifier:first_connection_try_count; 154, integer:3; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:request_stop; 161, argument_list; 161, 162; 161, 168; 162, binary_operator:%; 162, 163; 162, 167; 163, concatenated_string; 163, 164; 163, 165; 163, 166; 164, string:"All the daemons connections could not be established "; 165, string:"despite %d tries! "; 166, string:"Sorry, I bail out!"; 167, identifier:first_connection_try_count; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:exit_code; 170, integer:4; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:time; 175, identifier:sleep; 176, argument_list; 176, 177; 177, attribute; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:link_to_myself; 181, identifier:polling_interval; 182, comment; 183, comment; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:_t0; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:time; 190, identifier:time; 191, argument_list; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:all_connected; 197, call; 197, 198; 197, 203; 198, attribute; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:dispatcher; 202, identifier:check_reachable; 203, argument_list; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:statsmgr; 208, identifier:timer; 209, argument_list; 209, 210; 209, 211; 210, string:'dispatcher.check-alive'; 211, binary_operator:-; 211, 212; 211, 217; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:time; 215, identifier:time; 216, argument_list; 217, identifier:_t0; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:_t0; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:time; 224, identifier:time; 225, argument_list; 226, comment; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:logger; 231, identifier:info; 232, argument_list; 232, 233; 233, string:"Preparing the configuration for dispatching..."; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:dispatcher; 240, identifier:prepare_dispatch; 241, argument_list; 242, expression_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:statsmgr; 246, identifier:timer; 247, argument_list; 247, 248; 247, 249; 248, string:'dispatcher.prepare-dispatch'; 249, binary_operator:-; 249, 250; 249, 255; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:time; 253, identifier:time; 254, argument_list; 255, identifier:_t0; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:logger; 260, identifier:info; 261, argument_list; 261, 262; 262, string:"- configuration is ready to dispatch"; 263, comment; 264, comment; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:first_dispatch_try_count; 268, integer:0; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:logger; 273, identifier:info; 274, argument_list; 274, 275; 275, string:"Dispatching the configuration to my satellites..."; 276, while_statement; 276, 277; 276, 278; 277, True; 278, block; 278, 279; 278, 283; 278, 284; 278, 285; 278, 293; 278, 301; 278, 312; 278, 326; 278, 327; 278, 350; 278, 351; 278, 359; 278, 366; 278, 374; 278, 381; 278, 382; 278, 390; 278, 404; 279, expression_statement; 279, 280; 280, augmented_assignment:+=; 280, 281; 280, 282; 281, identifier:first_dispatch_try_count; 282, integer:1; 283, comment; 284, comment; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:_t0; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:time; 291, identifier:time; 292, argument_list; 293, expression_statement; 293, 294; 294, call; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:logger; 297, identifier:info; 298, argument_list; 298, 299; 298, 300; 299, string:"- configuration dispatching #%s..."; 300, identifier:first_dispatch_try_count; 301, expression_statement; 301, 302; 302, call; 302, 303; 302, 308; 303, attribute; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:dispatcher; 307, identifier:check_reachable; 308, argument_list; 308, 309; 309, keyword_argument; 309, 310; 309, 311; 310, identifier:forced; 311, True; 312, expression_statement; 312, 313; 313, call; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:statsmgr; 316, identifier:timer; 317, argument_list; 317, 318; 317, 319; 318, string:'dispatcher.dispatch'; 319, binary_operator:-; 319, 320; 319, 325; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:time; 323, identifier:time; 324, argument_list; 325, identifier:_t0; 326, comment; 327, expression_statement; 327, 328; 328, assignment; 328, 329; 328, 330; 329, identifier:pause; 330, call; 330, 331; 330, 332; 331, identifier:max; 332, argument_list; 332, 333; 332, 334; 333, integer:1; 334, call; 334, 335; 334, 336; 335, identifier:max; 336, argument_list; 336, 337; 336, 342; 337, attribute; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:conf; 341, identifier:daemons_dispatch_timeout; 342, binary_operator:*; 342, 343; 342, 349; 343, call; 343, 344; 343, 345; 344, identifier:len; 345, argument_list; 345, 346; 346, attribute; 346, 347; 346, 348; 347, identifier:self; 348, identifier:my_daemons; 349, float:0.5; 350, comment; 351, expression_statement; 351, 352; 352, call; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:logger; 355, identifier:info; 356, argument_list; 356, 357; 356, 358; 357, string:"- pausing %d seconds..."; 358, identifier:pause; 359, expression_statement; 359, 360; 360, call; 360, 361; 360, 364; 361, attribute; 361, 362; 361, 363; 362, identifier:time; 363, identifier:sleep; 364, argument_list; 364, 365; 365, identifier:pause; 366, expression_statement; 366, 367; 367, assignment; 367, 368; 367, 369; 368, identifier:_t0; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:time; 372, identifier:time; 373, argument_list; 374, expression_statement; 374, 375; 375, call; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:logger; 378, identifier:info; 379, argument_list; 379, 380; 380, string:"- checking configuration dispatch..."; 381, comment; 382, expression_statement; 382, 383; 383, call; 383, 384; 383, 389; 384, attribute; 384, 385; 384, 388; 385, attribute; 385, 386; 385, 387; 386, identifier:self; 387, identifier:dispatcher; 388, identifier:check_dispatch; 389, argument_list; 390, expression_statement; 390, 391; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:statsmgr; 394, identifier:timer; 395, argument_list; 395, 396; 395, 397; 396, string:'dispatcher.check-dispatch'; 397, binary_operator:-; 397, 398; 397, 403; 398, call; 398, 399; 398, 402; 399, attribute; 399, 400; 399, 401; 400, identifier:time; 401, identifier:time; 402, argument_list; 403, identifier:_t0; 404, if_statement; 404, 405; 404, 410; 404, 420; 405, attribute; 405, 406; 405, 409; 406, attribute; 406, 407; 406, 408; 407, identifier:self; 408, identifier:dispatcher; 409, identifier:dispatch_ok; 410, block; 410, 411; 410, 419; 411, expression_statement; 411, 412; 412, call; 412, 413; 412, 416; 413, attribute; 413, 414; 413, 415; 414, identifier:logger; 415, identifier:info; 416, argument_list; 416, 417; 416, 418; 417, string:"- configuration dispatching #%s is ok"; 418, identifier:first_dispatch_try_count; 419, break_statement; 420, else_clause; 420, 421; 421, block; 421, 422; 421, 432; 422, expression_statement; 422, 423; 423, call; 423, 424; 423, 427; 424, attribute; 424, 425; 424, 426; 425, identifier:logger; 426, identifier:warning; 427, argument_list; 427, 428; 427, 431; 428, concatenated_string; 428, 429; 428, 430; 429, string:"- configuration dispatching #%s is not correct; "; 430, string:"let's give another chance..."; 431, identifier:first_dispatch_try_count; 432, if_statement; 432, 433; 432, 436; 433, comparison_operator:>=; 433, 434; 433, 435; 434, identifier:first_dispatch_try_count; 435, integer:3; 436, block; 436, 437; 437, expression_statement; 437, 438; 438, call; 438, 439; 438, 442; 439, attribute; 439, 440; 439, 441; 440, identifier:self; 441, identifier:request_stop; 442, argument_list; 442, 443; 442, 448; 443, binary_operator:%; 443, 444; 443, 447; 444, concatenated_string; 444, 445; 444, 446; 445, string:"The configuration could not be dispatched despite %d tries! "; 446, string:"Sorry, I bail out!"; 447, identifier:first_connection_try_count; 448, keyword_argument; 448, 449; 448, 450; 449, identifier:exit_code; 450, integer:4 | def configuration_dispatch(self, not_configured=None):
"""Monitored configuration preparation and dispatch
:return: None
"""
if not not_configured:
self.dispatcher = Dispatcher(self.conf, self.link_to_myself)
# I set my own dispatched configuration as the provided one...
# because I will not push a configuration to myself :)
self.cur_conf = self.conf
# Loop for the first configuration dispatching, if the first dispatch fails, bail out!
# Without a correct configuration, Alignak daemons will not run correctly
first_connection_try_count = 0
logger.info("Connecting to my satellites...")
while True:
first_connection_try_count += 1
# Initialize connection with all our satellites
self.all_connected = True
for satellite in self.dispatcher.all_daemons_links:
if satellite == self.link_to_myself:
continue
if not satellite.active:
continue
connected = self.daemon_connection_init(satellite, set_wait_new_conf=True)
logger.debug(" %s is %s", satellite, connected)
self.all_connected = self.all_connected and connected
if self.all_connected:
logger.info("- satellites connection #%s is ok", first_connection_try_count)
break
else:
logger.warning("- satellites connection #%s is not correct; "
"let's give another chance after %d seconds...",
first_connection_try_count,
self.link_to_myself.polling_interval)
if first_connection_try_count >= 3:
self.request_stop("All the daemons connections could not be established "
"despite %d tries! "
"Sorry, I bail out!" % first_connection_try_count,
exit_code=4)
time.sleep(self.link_to_myself.polling_interval)
# Now I have a connection with all the daemons I need to contact them,
# check they are alive and ready to run
_t0 = time.time()
self.all_connected = self.dispatcher.check_reachable()
statsmgr.timer('dispatcher.check-alive', time.time() - _t0)
_t0 = time.time()
# Preparing the configuration for dispatching
logger.info("Preparing the configuration for dispatching...")
self.dispatcher.prepare_dispatch()
statsmgr.timer('dispatcher.prepare-dispatch', time.time() - _t0)
logger.info("- configuration is ready to dispatch")
# Loop for the first configuration dispatching, if the first dispatch fails, bail out!
# Without a correct configuration, Alignak daemons will not run correctly
first_dispatch_try_count = 0
logger.info("Dispatching the configuration to my satellites...")
while True:
first_dispatch_try_count += 1
# Check reachable - if a configuration is prepared, this will force the
# daemons communication, and the dispatching will be launched
_t0 = time.time()
logger.info("- configuration dispatching #%s...", first_dispatch_try_count)
self.dispatcher.check_reachable(forced=True)
statsmgr.timer('dispatcher.dispatch', time.time() - _t0)
# Make a pause to let our satellites get ready...
pause = max(1, max(self.conf.daemons_dispatch_timeout, len(self.my_daemons) * 0.5))
# pause = len(self.my_daemons) * 0.2
logger.info("- pausing %d seconds...", pause)
time.sleep(pause)
_t0 = time.time()
logger.info("- checking configuration dispatch...")
# Checking the dispatch is accepted
self.dispatcher.check_dispatch()
statsmgr.timer('dispatcher.check-dispatch', time.time() - _t0)
if self.dispatcher.dispatch_ok:
logger.info("- configuration dispatching #%s is ok", first_dispatch_try_count)
break
else:
logger.warning("- configuration dispatching #%s is not correct; "
"let's give another chance...", first_dispatch_try_count)
if first_dispatch_try_count >= 3:
self.request_stop("The configuration could not be dispatched despite %d tries! "
"Sorry, I bail out!" % first_connection_try_count,
exit_code=4) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:duplicate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:host; 6, comment; 7, block; 7, 8; 7, 10; 7, 14; 7, 15; 7, 29; 7, 39; 7, 40; 7, 48; 7, 49; 7, 50; 7, 75; 7, 82; 7, 91; 7, 92; 7, 93; 7, 165; 7, 357; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:duplicates; 13, list:[]; 14, comment; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:prop; 18, call; 18, 19; 18, 28; 19, attribute; 19, 20; 19, 27; 20, call; 20, 21; 20, 26; 21, attribute; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:duplicate_foreach; 25, identifier:strip; 26, argument_list; 27, identifier:upper; 28, argument_list; 29, if_statement; 29, 30; 29, 35; 29, 36; 30, comparison_operator:not; 30, 31; 30, 32; 31, identifier:prop; 32, attribute; 32, 33; 32, 34; 33, identifier:host; 34, identifier:customs; 35, comment; 36, block; 36, 37; 37, return_statement; 37, 38; 38, identifier:duplicates; 39, comment; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:entry; 43, subscript; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:host; 46, identifier:customs; 47, identifier:prop; 48, comment; 49, comment; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:not_entry; 53, call; 53, 54; 53, 73; 54, attribute; 54, 55; 54, 72; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:host; 59, identifier:customs; 60, identifier:get; 61, argument_list; 61, 62; 61, 71; 62, binary_operator:+; 62, 63; 62, 66; 63, binary_operator:+; 63, 64; 63, 65; 64, string:'_'; 65, string:'!'; 66, subscript; 66, 67; 66, 68; 67, identifier:prop; 68, slice; 68, 69; 68, 70; 69, integer:1; 70, colon; 71, string:''; 72, identifier:split; 73, argument_list; 73, 74; 74, string:','; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:not_keys; 78, call; 78, 79; 78, 80; 79, identifier:strip_and_uniq; 80, argument_list; 80, 81; 81, identifier:not_entry; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:default_value; 85, call; 85, 86; 85, 87; 86, identifier:getattr; 87, argument_list; 87, 88; 87, 89; 87, 90; 88, identifier:self; 89, string:'default_value'; 90, string:''; 91, comment; 92, comment; 93, try_statement; 93, 94; 93, 106; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:key_values; 98, call; 98, 99; 98, 100; 99, identifier:tuple; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:generate_key_value_sequences; 103, argument_list; 103, 104; 103, 105; 104, identifier:entry; 105, identifier:default_value; 106, except_clause; 106, 107; 106, 111; 107, as_pattern; 107, 108; 107, 109; 108, identifier:KeyValueSyntaxError; 109, as_pattern_target; 109, 110; 110, identifier:exc; 111, block; 111, 112; 111, 139; 111, 149; 111, 156; 111, 163; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:fmt_dict; 115, dictionary; 115, 116; 115, 121; 115, 128; 115, 133; 115, 136; 116, pair; 116, 117; 116, 118; 117, string:'prop'; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:duplicate_foreach; 121, pair; 121, 122; 121, 123; 122, string:'host'; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:host; 126, identifier:get_name; 127, argument_list; 128, pair; 128, 129; 128, 130; 129, string:'svc'; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:service_description; 133, pair; 133, 134; 133, 135; 134, string:'entry'; 135, identifier:entry; 136, pair; 136, 137; 136, 138; 137, string:'exc'; 138, identifier:exc; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:err; 142, binary_operator:%; 142, 143; 142, 148; 143, parenthesized_expression; 143, 144; 144, concatenated_string; 144, 145; 144, 146; 144, 147; 145, string:"The custom property %(prop)r of the "; 146, string:"host %(host)r is not a valid entry for a service generator: %(exc)s, "; 147, string:"with entry=%(entry)r"; 148, identifier:fmt_dict; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:logger; 153, identifier:warning; 154, argument_list; 154, 155; 155, identifier:err; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:host; 160, identifier:add_error; 161, argument_list; 161, 162; 162, identifier:err; 163, return_statement; 163, 164; 164, identifier:duplicates; 165, for_statement; 165, 166; 165, 167; 165, 168; 166, identifier:key_value; 167, identifier:key_values; 168, block; 168, 169; 168, 175; 168, 176; 168, 182; 168, 190; 168, 200; 168, 214; 168, 349; 168, 350; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:key; 172, subscript; 172, 173; 172, 174; 173, identifier:key_value; 174, string:'KEY'; 175, comment; 176, if_statement; 176, 177; 176, 180; 177, comparison_operator:in; 177, 178; 177, 179; 178, identifier:key; 179, identifier:not_keys; 180, block; 180, 181; 181, continue_statement; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:new_s; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:copy; 189, argument_list; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:new_s; 194, identifier:host_name; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:host; 198, identifier:get_name; 199, argument_list; 200, if_statement; 200, 201; 200, 206; 200, 207; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:is_tpl; 205, argument_list; 206, comment; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:new_s; 212, identifier:register; 213, integer:1; 214, for_statement; 214, 215; 214, 216; 214, 217; 215, identifier:key; 216, identifier:key_value; 217, block; 217, 218; 217, 268; 217, 269; 217, 276; 217, 311; 218, if_statement; 218, 219; 218, 222; 219, comparison_operator:==; 219, 220; 219, 221; 220, identifier:key; 221, string:'KEY'; 222, block; 222, 223; 223, if_statement; 223, 224; 223, 229; 223, 230; 223, 231; 223, 232; 224, call; 224, 225; 224, 226; 225, identifier:hasattr; 226, argument_list; 226, 227; 226, 228; 227, identifier:self; 228, string:'service_description'; 229, comment; 230, comment; 231, comment; 232, block; 232, 233; 232, 250; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:safe_key_value; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:re; 239, identifier:sub; 240, argument_list; 240, 241; 240, 246; 240, 247; 241, binary_operator:+; 241, 242; 241, 245; 242, binary_operator:+; 242, 243; 242, 244; 243, string:r'['; 244, string:"`~!$%^&*\"|'<>?,()="; 245, string:']+'; 246, string:'_'; 247, subscript; 247, 248; 247, 249; 248, identifier:key_value; 249, identifier:key; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:new_s; 254, identifier:service_description; 255, call; 255, 256; 255, 261; 256, attribute; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:service_description; 260, identifier:replace; 261, argument_list; 261, 262; 261, 267; 262, binary_operator:+; 262, 263; 262, 266; 263, binary_operator:+; 263, 264; 263, 265; 264, string:'$'; 265, identifier:key; 266, string:'$'; 267, identifier:safe_key_value; 268, comment; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:_the_expandables; 272, list:['check_command', 'aggregation', 'event_handler']; 272, 273; 272, 274; 272, 275; 273, string:'check_command'; 274, string:'aggregation'; 275, string:'event_handler'; 276, for_statement; 276, 277; 276, 278; 276, 279; 277, identifier:prop; 278, identifier:_the_expandables; 279, block; 279, 280; 280, if_statement; 280, 281; 280, 286; 280, 287; 281, call; 281, 282; 281, 283; 282, identifier:hasattr; 283, argument_list; 283, 284; 283, 285; 284, identifier:self; 285, identifier:prop; 286, comment; 287, block; 287, 288; 288, expression_statement; 288, 289; 289, call; 289, 290; 289, 291; 290, identifier:setattr; 291, argument_list; 291, 292; 291, 293; 291, 294; 292, identifier:new_s; 293, identifier:prop; 294, call; 294, 295; 294, 302; 295, attribute; 295, 296; 295, 301; 296, call; 296, 297; 296, 298; 297, identifier:getattr; 298, argument_list; 298, 299; 298, 300; 299, identifier:new_s; 300, identifier:prop; 301, identifier:replace; 302, argument_list; 302, 303; 302, 308; 303, binary_operator:+; 303, 304; 303, 307; 304, binary_operator:+; 304, 305; 304, 306; 305, string:'$'; 306, identifier:key; 307, string:'$'; 308, subscript; 308, 309; 308, 310; 309, identifier:key_value; 310, identifier:key; 311, if_statement; 311, 312; 311, 317; 312, call; 312, 313; 312, 314; 313, identifier:hasattr; 314, argument_list; 314, 315; 314, 316; 315, identifier:self; 316, string:'service_dependencies'; 317, block; 317, 318; 318, for_statement; 318, 319; 318, 322; 318, 328; 319, pattern_list; 319, 320; 319, 321; 320, identifier:i; 321, identifier:servicedep; 322, call; 322, 323; 322, 324; 323, identifier:enumerate; 324, argument_list; 324, 325; 325, attribute; 325, 326; 325, 327; 326, identifier:new_s; 327, identifier:service_dependencies; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 336; 331, subscript; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:new_s; 334, identifier:service_dependencies; 335, identifier:i; 336, call; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:servicedep; 339, identifier:replace; 340, argument_list; 340, 341; 340, 346; 341, binary_operator:+; 341, 342; 341, 345; 342, binary_operator:+; 342, 343; 342, 344; 343, string:'$'; 344, identifier:key; 345, string:'$'; 346, subscript; 346, 347; 346, 348; 347, identifier:key_value; 348, identifier:key; 349, comment; 350, expression_statement; 350, 351; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:duplicates; 354, identifier:append; 355, argument_list; 355, 356; 356, identifier:new_s; 357, return_statement; 357, 358; 358, identifier:duplicates | def duplicate(self, host):
# pylint: disable=too-many-locals
"""For a given host, look for all copy we must create for for_each property
:param host: alignak host object
:type host: alignak.objects.host.Host
:return: list
:rtype: list
"""
duplicates = []
# In macro, it's all in UPPER case
prop = self.duplicate_foreach.strip().upper()
if prop not in host.customs: # If I do not have the property, we bail out
return duplicates
# Get the list entry, and the not one if there is one
entry = host.customs[prop]
# Look at the list of the key we do NOT want maybe,
# for _disks it will be _!disks
not_entry = host.customs.get('_' + '!' + prop[1:], '').split(',')
not_keys = strip_and_uniq(not_entry)
default_value = getattr(self, 'default_value', '')
# Transform the generator string to a list
# Missing values are filled with the default value
try:
key_values = tuple(generate_key_value_sequences(entry, default_value))
except KeyValueSyntaxError as exc:
fmt_dict = {
'prop': self.duplicate_foreach,
'host': host.get_name(),
'svc': self.service_description,
'entry': entry,
'exc': exc,
}
err = (
"The custom property %(prop)r of the "
"host %(host)r is not a valid entry for a service generator: %(exc)s, "
"with entry=%(entry)r") % fmt_dict
logger.warning(err)
host.add_error(err)
return duplicates
for key_value in key_values:
key = key_value['KEY']
# Maybe this key is in the NOT list, if so, skip it
if key in not_keys:
continue
new_s = self.copy()
new_s.host_name = host.get_name()
if self.is_tpl(): # if template, the new one is not
new_s.register = 1
for key in key_value:
if key == 'KEY':
if hasattr(self, 'service_description'):
# We want to change all illegal chars to a _ sign.
# We can't use class.illegal_obj_char
# because in the "explode" phase, we do not have access to this data! :(
safe_key_value = re.sub(r'[' + "`~!$%^&*\"|'<>?,()=" + ']+', '_',
key_value[key])
new_s.service_description = self.service_description.replace(
'$' + key + '$', safe_key_value
)
# Here is a list of property where we will expand the $KEY$ by the value
_the_expandables = ['check_command', 'aggregation', 'event_handler']
for prop in _the_expandables:
if hasattr(self, prop):
# here we can replace VALUE, VALUE1, VALUE2,...
setattr(new_s, prop, getattr(new_s, prop).replace('$' + key + '$',
key_value[key]))
if hasattr(self, 'service_dependencies'):
for i, servicedep in enumerate(new_s.service_dependencies):
new_s.service_dependencies[i] = servicedep.replace(
'$' + key + '$', key_value[key]
)
# And then add in our list this new service
duplicates.append(new_s)
return duplicates |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:explode_services_from_hosts; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:hosts; 6, identifier:service; 7, identifier:hnames; 8, block; 8, 9; 8, 11; 8, 15; 8, 16; 8, 20; 8, 21; 8, 64; 8, 65; 8, 75; 8, 76; 8, 77; 8, 94; 8, 95; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:duplicate_for_hosts; 14, list:[]; 15, comment; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:not_hosts; 19, list:[]; 20, comment; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:hname; 23, identifier:hnames; 24, block; 24, 25; 24, 33; 24, 34; 24, 35; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:hname; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:hname; 31, identifier:strip; 32, argument_list; 33, comment; 34, comment; 35, if_statement; 35, 36; 35, 42; 35, 54; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:hname; 39, identifier:startswith; 40, argument_list; 40, 41; 41, string:'!'; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:not_hosts; 47, identifier:append; 48, argument_list; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:hname; 51, slice; 51, 52; 51, 53; 52, integer:1; 53, colon; 54, else_clause; 54, 55; 54, 56; 55, comment; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:duplicate_for_hosts; 61, identifier:append; 62, argument_list; 62, 63; 63, identifier:hname; 64, comment; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:duplicate_for_hosts; 68, call; 68, 69; 68, 70; 69, identifier:list; 70, argument_list; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:set; 73, argument_list; 73, 74; 74, identifier:duplicate_for_hosts; 75, comment; 76, comment; 77, for_statement; 77, 78; 77, 79; 77, 80; 78, identifier:hname; 79, identifier:not_hosts; 80, block; 80, 81; 81, try_statement; 81, 82; 81, 90; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:duplicate_for_hosts; 87, identifier:remove; 88, argument_list; 88, 89; 89, identifier:hname; 90, except_clause; 90, 91; 90, 92; 91, identifier:IndexError; 92, block; 92, 93; 93, pass_statement; 94, comment; 95, for_statement; 95, 96; 95, 97; 95, 98; 96, identifier:hname; 97, identifier:duplicate_for_hosts; 98, block; 98, 99; 98, 108; 98, 129; 98, 138; 98, 146; 98, 152; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:host; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:hosts; 105, identifier:find_by_name; 106, argument_list; 106, 107; 107, identifier:hname; 108, if_statement; 108, 109; 108, 112; 109, comparison_operator:is; 109, 110; 109, 111; 110, identifier:host; 111, None; 112, block; 112, 113; 112, 128; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:service; 117, identifier:add_error; 118, argument_list; 118, 119; 119, binary_operator:%; 119, 120; 119, 121; 120, string:"Error: The hostname %s is unknown for the service %s!"; 121, tuple; 121, 122; 121, 123; 122, identifier:hname; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:service; 126, identifier:get_name; 127, argument_list; 128, continue_statement; 129, if_statement; 129, 130; 129, 136; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:host; 133, identifier:is_excluded_for; 134, argument_list; 134, 135; 135, identifier:service; 136, block; 136, 137; 137, continue_statement; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:new_s; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:service; 144, identifier:copy; 145, argument_list; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:new_s; 150, identifier:host_name; 151, identifier:hname; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:add_item; 157, argument_list; 157, 158; 158, identifier:new_s | def explode_services_from_hosts(self, hosts, service, hnames):
"""
Explodes a service based on a list of hosts.
:param hosts: The hosts container
:type hosts:
:param service: The base service to explode
:type service:
:param hnames: The host_name list to explode service on
:type hnames: str
:return: None
"""
duplicate_for_hosts = [] # get the list of our host_names if more than 1
not_hosts = [] # the list of !host_name so we remove them after
for hname in hnames:
hname = hname.strip()
# If the name begin with a !, we put it in
# the not list
if hname.startswith('!'):
not_hosts.append(hname[1:])
else: # the standard list
duplicate_for_hosts.append(hname)
# remove duplicate items from duplicate_for_hosts:
duplicate_for_hosts = list(set(duplicate_for_hosts))
# Ok now we clean the duplicate_for_hosts with all hosts
# of the not
for hname in not_hosts:
try:
duplicate_for_hosts.remove(hname)
except IndexError:
pass
# Now we duplicate the service for all host_names
for hname in duplicate_for_hosts:
host = hosts.find_by_name(hname)
if host is None:
service.add_error("Error: The hostname %s is unknown for the service %s!"
% (hname, service.get_name()))
continue
if host.is_excluded_for(service):
continue
new_s = service.copy()
new_s.host_name = hname
self.add_item(new_s) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 1, 11; 2, function_name:explode; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:hosts; 6, identifier:hostgroups; 7, identifier:contactgroups; 8, identifier:servicegroups; 9, identifier:servicedependencies; 10, comment; 11, block; 11, 12; 11, 14; 11, 15; 11, 16; 11, 29; 11, 145; 11, 175; 11, 176; 11, 193; 11, 226; 11, 230; 11, 262; 11, 273; 11, 274; 11, 275; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, comment; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:itemkeys; 19, call; 19, 20; 19, 21; 20, identifier:list; 21, argument_list; 21, 22; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:items; 27, identifier:keys; 28, argument_list; 29, for_statement; 29, 30; 29, 31; 29, 32; 30, identifier:s_id; 31, identifier:itemkeys; 32, block; 32, 33; 32, 41; 32, 42; 32, 43; 32, 52; 32, 53; 32, 54; 32, 62; 32, 71; 32, 100; 32, 101; 32, 102; 32, 103; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:serv; 36, subscript; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:items; 40, identifier:s_id; 41, comment; 42, comment; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:explode_host_groups_into_hosts; 48, argument_list; 48, 49; 48, 50; 48, 51; 49, identifier:serv; 50, identifier:hosts; 51, identifier:hostgroups; 52, comment; 53, comment; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:explode_contact_groups_into_contacts; 59, argument_list; 59, 60; 59, 61; 60, identifier:serv; 61, identifier:contactgroups; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:hnames; 65, call; 65, 66; 65, 67; 66, identifier:getattr; 67, argument_list; 67, 68; 67, 69; 67, 70; 68, identifier:serv; 69, string:"host_name"; 70, string:''; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:hnames; 74, call; 74, 75; 74, 76; 75, identifier:list; 76, argument_list; 76, 77; 77, call; 77, 78; 77, 79; 78, identifier:set; 79, argument_list; 79, 80; 80, list_comprehension; 80, 81; 80, 86; 80, 94; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:n; 84, identifier:strip; 85, argument_list; 86, for_in_clause; 86, 87; 86, 88; 87, identifier:n; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:hnames; 91, identifier:split; 92, argument_list; 92, 93; 93, string:','; 94, if_clause; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:n; 98, identifier:strip; 99, argument_list; 100, comment; 101, comment; 102, comment; 103, if_statement; 103, 104; 103, 110; 103, 118; 104, comparison_operator:==; 104, 105; 104, 109; 105, call; 105, 106; 105, 107; 106, identifier:len; 107, argument_list; 107, 108; 108, identifier:hnames; 109, integer:1; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:index_item; 116, argument_list; 116, 117; 117, identifier:serv; 118, else_clause; 118, 119; 119, block; 119, 120; 119, 137; 119, 138; 120, if_statement; 120, 121; 120, 127; 121, comparison_operator:>=; 121, 122; 121, 126; 122, call; 122, 123; 122, 124; 123, identifier:len; 124, argument_list; 124, 125; 125, identifier:hnames; 126, integer:2; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:explode_services_from_hosts; 133, argument_list; 133, 134; 133, 135; 133, 136; 134, identifier:hosts; 135, identifier:serv; 136, identifier:hnames; 137, comment; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:remove_item; 143, argument_list; 143, 144; 144, identifier:serv; 145, for_statement; 145, 146; 145, 147; 145, 150; 146, identifier:s_id; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:templates; 150, block; 150, 151; 150, 159; 150, 167; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:template; 154, subscript; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:templates; 158, identifier:s_id; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:explode_contact_groups_into_contacts; 164, argument_list; 164, 165; 164, 166; 165, identifier:template; 166, identifier:contactgroups; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:explode_services_from_templates; 172, argument_list; 172, 173; 172, 174; 173, identifier:hosts; 174, identifier:template; 175, comment; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:duplicates; 179, list_comprehension; 179, 180; 179, 183; 179, 186; 180, attribute; 180, 181; 180, 182; 181, identifier:serv; 182, identifier:uuid; 183, for_in_clause; 183, 184; 183, 185; 184, identifier:serv; 185, identifier:self; 186, if_clause; 186, 187; 187, call; 187, 188; 187, 189; 188, identifier:getattr; 189, argument_list; 189, 190; 189, 191; 189, 192; 190, identifier:serv; 191, string:'duplicate_foreach'; 192, string:''; 193, for_statement; 193, 194; 193, 195; 193, 196; 194, identifier:s_id; 195, identifier:duplicates; 196, block; 196, 197; 196, 205; 196, 213; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:serv; 200, subscript; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:items; 204, identifier:s_id; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:explode_services_duplicates; 210, argument_list; 210, 211; 210, 212; 211, identifier:hosts; 212, identifier:serv; 213, if_statement; 213, 214; 213, 218; 214, not_operator; 214, 215; 215, attribute; 215, 216; 215, 217; 216, identifier:serv; 217, identifier:configuration_errors; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:remove_item; 224, argument_list; 224, 225; 225, identifier:serv; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:to_remove; 229, list:[]; 230, for_statement; 230, 231; 230, 232; 230, 233; 231, identifier:service; 232, identifier:self; 233, block; 233, 234; 233, 245; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:host; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:hosts; 240, identifier:find_by_name; 241, argument_list; 241, 242; 242, attribute; 242, 243; 242, 244; 243, identifier:service; 244, identifier:host_name; 245, if_statement; 245, 246; 245, 254; 246, boolean_operator:and; 246, 247; 246, 248; 247, identifier:host; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:host; 251, identifier:is_excluded_for; 252, argument_list; 252, 253; 253, identifier:service; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:to_remove; 259, identifier:append; 260, argument_list; 260, 261; 261, identifier:service; 262, for_statement; 262, 263; 262, 264; 262, 265; 263, identifier:service; 264, identifier:to_remove; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:self; 270, identifier:remove_item; 271, argument_list; 271, 272; 272, identifier:service; 273, comment; 274, comment; 275, for_statement; 275, 276; 275, 277; 275, 278; 276, identifier:serv; 277, identifier:self; 278, block; 278, 279; 278, 287; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:self; 283, identifier:register_service_into_servicegroups; 284, argument_list; 284, 285; 284, 286; 285, identifier:serv; 286, identifier:servicegroups; 287, expression_statement; 287, 288; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:register_service_dependencies; 292, argument_list; 292, 293; 292, 294; 293, identifier:serv; 294, identifier:servicedependencies | def explode(self, hosts, hostgroups, contactgroups, servicegroups, servicedependencies):
# pylint: disable=too-many-locals
"""
Explodes services, from host, hostgroups, contactgroups, servicegroups and dependencies.
:param hosts: The hosts container
:type hosts: [alignak.object.host.Host]
:param hostgroups: The hosts goups container
:type hostgroups: [alignak.object.hostgroup.Hostgroup]
:param contactgroups: The contacts goups container
:type contactgroups: [alignak.object.contactgroup.Contactgroup]
:param servicegroups: The services goups container
:type servicegroups: [alignak.object.servicegroup.Servicegroup]
:param servicedependencies: The services dependencies container
:type servicedependencies: [alignak.object.servicedependency.Servicedependency]
:return: None
"""
# Then for every service create a copy of the service with just the host
# because we are adding services, we can't just loop in it
itemkeys = list(self.items.keys())
for s_id in itemkeys:
serv = self.items[s_id]
# items::explode_host_groups_into_hosts
# take all hosts from our hostgroup_name into our host_name property
self.explode_host_groups_into_hosts(serv, hosts, hostgroups)
# items::explode_contact_groups_into_contacts
# take all contacts from our contact_groups into our contact property
self.explode_contact_groups_into_contacts(serv, contactgroups)
hnames = getattr(serv, "host_name", '')
hnames = list(set([n.strip() for n in hnames.split(',') if n.strip()]))
# hnames = strip_and_uniq(hnames)
# We will duplicate if we have multiple host_name
# or if we are a template (so a clean service)
if len(hnames) == 1:
self.index_item(serv)
else:
if len(hnames) >= 2:
self.explode_services_from_hosts(hosts, serv, hnames)
# Delete expanded source service, even if some errors exist
self.remove_item(serv)
for s_id in self.templates:
template = self.templates[s_id]
self.explode_contact_groups_into_contacts(template, contactgroups)
self.explode_services_from_templates(hosts, template)
# Explode services that have a duplicate_foreach clause
duplicates = [serv.uuid for serv in self if getattr(serv, 'duplicate_foreach', '')]
for s_id in duplicates:
serv = self.items[s_id]
self.explode_services_duplicates(hosts, serv)
if not serv.configuration_errors:
self.remove_item(serv)
to_remove = []
for service in self:
host = hosts.find_by_name(service.host_name)
if host and host.is_excluded_for(service):
to_remove.append(service)
for service in to_remove:
self.remove_item(service)
# Servicegroups property need to be fulfill for got the information
# And then just register to this service_group
for serv in self:
self.register_service_into_servicegroups(serv, servicegroups)
self.register_service_dependencies(serv, servicedependencies) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_next_notif_time; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:t_wished; 6, identifier:status; 7, identifier:creation_time; 8, identifier:interval; 9, identifier:escal_period; 10, block; 10, 11; 10, 13; 10, 47; 10, 48; 10, 56; 10, 57; 10, 72; 10, 73; 10, 83; 10, 84; 10, 91; 10, 92; 10, 107; 10, 108; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:short_states; 16, dictionary; 16, 17; 16, 20; 16, 23; 16, 26; 16, 29; 16, 32; 16, 35; 16, 38; 16, 41; 16, 44; 17, pair; 17, 18; 17, 19; 18, string:u'WARNING'; 19, string:'w'; 20, pair; 20, 21; 20, 22; 21, string:u'UNKNOWN'; 22, string:'u'; 23, pair; 23, 24; 23, 25; 24, string:u'CRITICAL'; 25, string:'c'; 26, pair; 26, 27; 26, 28; 27, string:u'RECOVERY'; 28, string:'r'; 29, pair; 29, 30; 29, 31; 30, string:u'FLAPPING'; 31, string:'f'; 32, pair; 32, 33; 32, 34; 33, string:u'DOWNTIME'; 34, string:'s'; 35, pair; 35, 36; 35, 37; 36, string:u'DOWN'; 37, string:'d'; 38, pair; 38, 39; 38, 40; 39, string:u'UNREACHABLE'; 40, string:'u'; 41, pair; 41, 42; 41, 43; 42, string:u'OK'; 43, string:'o'; 44, pair; 44, 45; 44, 46; 45, string:u'UP'; 46, string:'o'; 47, comment; 48, if_statement; 48, 49; 48, 53; 49, not_operator; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:time_based; 53, block; 53, 54; 54, return_statement; 54, 55; 55, None; 56, comment; 57, if_statement; 57, 58; 57, 69; 58, boolean_operator:and; 58, 59; 58, 62; 59, comparison_operator:in; 59, 60; 59, 61; 60, identifier:status; 61, identifier:short_states; 62, comparison_operator:not; 62, 63; 62, 66; 63, subscript; 63, 64; 63, 65; 64, identifier:short_states; 65, identifier:status; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:escalation_options; 69, block; 69, 70; 70, return_statement; 70, 71; 71, None; 72, comment; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:start; 76, binary_operator:+; 76, 77; 76, 82; 77, binary_operator:*; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:first_notification_time; 81, identifier:interval; 82, identifier:creation_time; 83, comment; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:>; 85, 86; 85, 87; 86, identifier:start; 87, identifier:t_wished; 88, block; 88, 89; 89, return_statement; 89, 90; 90, None; 91, comment; 92, if_statement; 92, 93; 92, 104; 93, boolean_operator:and; 93, 94; 93, 97; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:escal_period; 96, None; 97, not_operator; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:escal_period; 101, identifier:is_time_valid; 102, argument_list; 102, 103; 103, identifier:start; 104, block; 104, 105; 105, return_statement; 105, 106; 106, None; 107, comment; 108, return_statement; 108, 109; 109, identifier:start | def get_next_notif_time(self, t_wished, status, creation_time, interval, escal_period):
"""Get the next notification time for the escalation
Only legit for time based escalation
:param t_wished: time we would like to send a new notification (usually now)
:type t_wished:
:param status: status of the host or service
:type status:
:param creation_time: time the notification was created
:type creation_time:
:param interval: time interval length
:type interval: int
:return: timestamp for next notification or None
:rtype: int | None
"""
short_states = {u'WARNING': 'w', u'UNKNOWN': 'u', u'CRITICAL': 'c',
u'RECOVERY': 'r', u'FLAPPING': 'f', u'DOWNTIME': 's',
u'DOWN': 'd', u'UNREACHABLE': 'u', u'OK': 'o', u'UP': 'o'}
# If we are not time based, we bail out!
if not self.time_based:
return None
# Check if we are valid
if status in short_states and short_states[status] not in self.escalation_options:
return None
# Look for the min of our future validity
start = self.first_notification_time * interval + creation_time
# If we are after the classic next time, we are not asking for a smaller interval
if start > t_wished:
return None
# Maybe the time we found is not a valid one....
if escal_period is not None and not escal_period.is_time_valid(start):
return None
# Ok so I ask for my start as a possibility for the next notification time
return start |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:linkify_es_by_s; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:services; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, comment; 9, for_statement; 9, 10; 9, 11; 9, 12; 9, 13; 10, identifier:escalation; 11, identifier:self; 12, comment; 13, block; 13, 14; 13, 23; 13, 35; 13, 51; 14, if_statement; 14, 15; 14, 21; 15, not_operator; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:hasattr; 18, argument_list; 18, 19; 18, 20; 19, identifier:escalation; 20, string:'host_name'; 21, block; 21, 22; 22, continue_statement; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, pattern_list; 25, 26; 25, 27; 26, identifier:es_hname; 27, identifier:sdesc; 28, expression_list; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:escalation; 31, identifier:host_name; 32, attribute; 32, 33; 32, 34; 33, identifier:escalation; 34, identifier:service_description; 35, if_statement; 35, 36; 35, 49; 36, boolean_operator:or; 36, 37; 36, 43; 37, not_operator; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:es_hname; 41, identifier:strip; 42, argument_list; 43, not_operator; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:sdesc; 47, identifier:strip; 48, argument_list; 49, block; 49, 50; 50, continue_statement; 51, for_statement; 51, 52; 51, 53; 51, 62; 52, identifier:hname; 53, call; 53, 54; 53, 55; 54, identifier:strip_and_uniq; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:es_hname; 59, identifier:split; 60, argument_list; 60, 61; 61, string:','; 62, block; 62, 63; 63, if_statement; 63, 64; 63, 71; 63, 111; 64, comparison_operator:==; 64, 65; 64, 70; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:sdesc; 68, identifier:strip; 69, argument_list; 70, string:'*'; 71, block; 71, 72; 71, 81; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:slist; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:services; 78, identifier:find_srvs_by_hostname; 79, argument_list; 79, 80; 80, identifier:hname; 81, if_statement; 81, 82; 81, 85; 82, comparison_operator:is; 82, 83; 82, 84; 83, identifier:slist; 84, None; 85, block; 85, 86; 85, 96; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:slist; 89, list_comprehension; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:services; 92, identifier:serv; 93, for_in_clause; 93, 94; 93, 95; 94, identifier:serv; 95, identifier:slist; 96, for_statement; 96, 97; 96, 98; 96, 99; 97, identifier:serv; 98, identifier:slist; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:serv; 105, identifier:escalations; 106, identifier:append; 107, argument_list; 107, 108; 108, attribute; 108, 109; 108, 110; 109, identifier:escalation; 110, identifier:uuid; 111, else_clause; 111, 112; 112, block; 112, 113; 113, for_statement; 113, 114; 113, 115; 113, 124; 114, identifier:sname; 115, call; 115, 116; 115, 117; 116, identifier:strip_and_uniq; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:sdesc; 121, identifier:split; 122, argument_list; 122, 123; 123, string:','; 124, block; 124, 125; 124, 135; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:serv; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:services; 131, identifier:find_srv_by_name_and_hostname; 132, argument_list; 132, 133; 132, 134; 133, identifier:hname; 134, identifier:sname; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:is; 136, 137; 136, 138; 137, identifier:serv; 138, None; 139, block; 139, 140; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:serv; 145, identifier:escalations; 146, identifier:append; 147, argument_list; 147, 148; 148, attribute; 148, 149; 148, 150; 149, identifier:escalation; 150, identifier:uuid | def linkify_es_by_s(self, services):
"""Add each escalation object into service.escalation attribute
:param services: service list, used to look for a specific service
:type services: alignak.objects.service.Services
:return: None
"""
for escalation in self:
# If no host, no hope of having a service
if not hasattr(escalation, 'host_name'):
continue
es_hname, sdesc = escalation.host_name, escalation.service_description
if not es_hname.strip() or not sdesc.strip():
continue
for hname in strip_and_uniq(es_hname.split(',')):
if sdesc.strip() == '*':
slist = services.find_srvs_by_hostname(hname)
if slist is not None:
slist = [services[serv] for serv in slist]
for serv in slist:
serv.escalations.append(escalation.uuid)
else:
for sname in strip_and_uniq(sdesc.split(',')):
serv = services.find_srv_by_name_and_hostname(hname, sname)
if serv is not None:
serv.escalations.append(escalation.uuid) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 1, 7; 2, function_name:get_contacts_by_explosion; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:contactgroups; 6, comment; 7, block; 7, 8; 7, 10; 7, 11; 7, 12; 7, 18; 7, 19; 7, 20; 7, 21; 7, 22; 7, 52; 7, 53; 7, 59; 7, 67; 7, 110; 7, 121; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:already_exploded; 17, True; 18, comment; 19, comment; 20, comment; 21, comment; 22, if_statement; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:rec_tag; 26, block; 26, 27; 26, 39; 26, 50; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:logger; 31, identifier:error; 32, argument_list; 32, 33; 32, 34; 33, string:"[contactgroup::%s] got a loop in contactgroup definition"; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:get_name; 38, argument_list; 39, if_statement; 39, 40; 39, 45; 40, call; 40, 41; 40, 42; 41, identifier:hasattr; 42, argument_list; 42, 43; 42, 44; 43, identifier:self; 44, string:'members'; 45, block; 45, 46; 46, return_statement; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:members; 50, return_statement; 50, 51; 51, string:''; 52, comment; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:rec_tag; 58, True; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:cg_mbrs; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:get_contactgroup_members; 66, argument_list; 67, for_statement; 67, 68; 67, 69; 67, 70; 68, identifier:cg_mbr; 69, identifier:cg_mbrs; 70, block; 70, 71; 70, 84; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:contactgroup; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:contactgroups; 77, identifier:find_by_name; 78, argument_list; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:cg_mbr; 82, identifier:strip; 83, argument_list; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:is; 85, 86; 85, 87; 86, identifier:contactgroup; 87, None; 88, block; 88, 89; 88, 98; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:value; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:contactgroup; 95, identifier:get_contacts_by_explosion; 96, argument_list; 96, 97; 97, identifier:contactgroups; 98, if_statement; 98, 99; 98, 102; 99, comparison_operator:is; 99, 100; 99, 101; 100, identifier:value; 101, None; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:add_members; 108, argument_list; 108, 109; 109, identifier:value; 110, if_statement; 110, 111; 110, 116; 111, call; 111, 112; 111, 113; 112, identifier:hasattr; 113, argument_list; 113, 114; 113, 115; 114, identifier:self; 115, string:'members'; 116, block; 116, 117; 117, return_statement; 117, 118; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:members; 121, return_statement; 121, 122; 122, string:'' | def get_contacts_by_explosion(self, contactgroups):
# pylint: disable=access-member-before-definition
"""
Get contacts of this group
:param contactgroups: Contactgroups object, use to look for a specific one
:type contactgroups: alignak.objects.contactgroup.Contactgroups
:return: list of contact of this group
:rtype: list[alignak.objects.contact.Contact]
"""
# First we tag the hg so it will not be explode
# if a son of it already call it
self.already_exploded = True
# Now the recursive part
# rec_tag is set to False every CG we explode
# so if True here, it must be a loop in HG
# calls... not GOOD!
if self.rec_tag:
logger.error("[contactgroup::%s] got a loop in contactgroup definition",
self.get_name())
if hasattr(self, 'members'):
return self.members
return ''
# Ok, not a loop, we tag it and continue
self.rec_tag = True
cg_mbrs = self.get_contactgroup_members()
for cg_mbr in cg_mbrs:
contactgroup = contactgroups.find_by_name(cg_mbr.strip())
if contactgroup is not None:
value = contactgroup.get_contacts_by_explosion(contactgroups)
if value is not None:
self.add_members(value)
if hasattr(self, 'members'):
return self.members
return '' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 1, 13; 2, function_name:do_check_freshness; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:hosts; 6, identifier:services; 7, identifier:timeperiods; 8, identifier:macromodulations; 9, identifier:checkmodulations; 10, identifier:checks; 11, identifier:when; 12, comment; 13, block; 13, 14; 13, 16; 13, 20; 13, 21; 13, 22; 13, 28; 13, 338; 14, expression_statement; 14, 15; 15, comment; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:now; 19, identifier:when; 20, comment; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:cls; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:__class__; 28, if_statement; 28, 29; 28, 42; 28, 43; 28, 44; 29, boolean_operator:and; 29, 30; 29, 38; 30, boolean_operator:and; 30, 31; 30, 35; 31, not_operator; 31, 32; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:in_checking; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:freshness_threshold; 38, not_operator; 38, 39; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:freshness_expired; 42, comment; 43, comment; 44, block; 44, 45; 44, 66; 44, 67; 44, 82; 45, if_statement; 45, 46; 45, 53; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:os; 49, identifier:getenv; 50, argument_list; 50, 51; 50, 52; 51, string:'ALIGNAK_LOG_CHECKS'; 52, None; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:logger; 58, identifier:info; 59, argument_list; 59, 60; 59, 61; 60, string:"--ALC-- -> checking freshness for: %s"; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:get_full_name; 65, argument_list; 66, comment; 67, if_statement; 67, 68; 67, 72; 68, not_operator; 68, 69; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:last_state_update; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:last_state_update; 78, call; 78, 79; 78, 80; 79, identifier:int; 80, argument_list; 80, 81; 81, identifier:now; 82, if_statement; 82, 83; 82, 98; 83, comparison_operator:<; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:last_state_update; 87, binary_operator:-; 87, 88; 87, 89; 87, 90; 88, identifier:now; 89, line_continuation:\; 90, parenthesized_expression; 90, 91; 91, binary_operator:+; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:freshness_threshold; 95, attribute; 95, 96; 95, 97; 96, identifier:cls; 97, identifier:additional_freshness_latency; 98, block; 98, 99; 98, 107; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:timeperiod; 102, subscript; 102, 103; 102, 104; 103, identifier:timeperiods; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:check_period; 107, if_statement; 107, 108; 107, 118; 107, 119; 107, 322; 108, boolean_operator:or; 108, 109; 108, 112; 109, comparison_operator:is; 109, 110; 109, 111; 110, identifier:timeperiod; 111, None; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:timeperiod; 115, identifier:is_time_valid; 116, argument_list; 116, 117; 117, identifier:now; 118, comment; 119, block; 119, 120; 119, 135; 119, 149; 119, 155; 119, 165; 119, 189; 119, 320; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:chk; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:launch_check; 127, argument_list; 127, 128; 127, 129; 127, 130; 127, 131; 127, 132; 127, 133; 127, 134; 128, identifier:now; 129, identifier:hosts; 130, identifier:services; 131, identifier:timeperiods; 132, identifier:macromodulations; 133, identifier:checkmodulations; 134, identifier:checks; 135, if_statement; 135, 136; 135, 138; 136, not_operator; 136, 137; 137, identifier:chk; 138, block; 138, 139; 138, 147; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:logger; 143, identifier:warning; 144, argument_list; 144, 145; 144, 146; 145, string:"No raised freshness check for: %s"; 146, identifier:self; 147, return_statement; 147, 148; 148, None; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:chk; 153, identifier:freshness_expiry_check; 154, True; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:chk; 159, identifier:check_time; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:time; 163, identifier:time; 164, argument_list; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:chk; 169, identifier:output; 170, binary_operator:%; 170, 171; 170, 172; 171, string:"Freshness period expired: %s"; 172, parenthesized_expression; 172, 173; 173, call; 173, 174; 173, 187; 174, attribute; 174, 175; 174, 186; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:datetime; 178, identifier:utcfromtimestamp; 179, argument_list; 179, 180; 180, call; 180, 181; 180, 182; 181, identifier:int; 182, argument_list; 182, 183; 183, attribute; 183, 184; 183, 185; 184, identifier:chk; 185, identifier:check_time; 186, identifier:strftime; 187, argument_list; 187, 188; 188, string:"%Y-%m-%d %H:%M:%S %Z"; 189, if_statement; 189, 190; 189, 195; 189, 245; 190, comparison_operator:==; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:my_type; 194, string:'host'; 195, block; 195, 196; 196, if_statement; 196, 197; 196, 202; 196, 209; 196, 222; 196, 237; 197, comparison_operator:==; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:freshness_state; 201, string:'o'; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:chk; 207, identifier:exit_status; 208, integer:0; 209, elif_clause; 209, 210; 209, 215; 210, comparison_operator:==; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:self; 213, identifier:freshness_state; 214, string:'d'; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:chk; 220, identifier:exit_status; 221, integer:2; 222, elif_clause; 222, 223; 222, 230; 223, comparison_operator:in; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:freshness_state; 227, list:['u', 'x']; 227, 228; 227, 229; 228, string:'u'; 229, string:'x'; 230, block; 230, 231; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:chk; 235, identifier:exit_status; 236, integer:4; 237, else_clause; 237, 238; 238, block; 238, 239; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:chk; 243, identifier:exit_status; 244, integer:3; 245, else_clause; 245, 246; 246, block; 246, 247; 247, if_statement; 247, 248; 247, 253; 247, 260; 247, 273; 247, 286; 247, 299; 247, 312; 248, comparison_operator:==; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:freshness_state; 252, string:'o'; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:chk; 258, identifier:exit_status; 259, integer:0; 260, elif_clause; 260, 261; 260, 266; 261, comparison_operator:==; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:freshness_state; 265, string:'w'; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:chk; 271, identifier:exit_status; 272, integer:1; 273, elif_clause; 273, 274; 273, 279; 274, comparison_operator:==; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:freshness_state; 278, string:'c'; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:chk; 284, identifier:exit_status; 285, integer:2; 286, elif_clause; 286, 287; 286, 292; 287, comparison_operator:==; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:freshness_state; 291, string:'u'; 292, block; 292, 293; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:chk; 297, identifier:exit_status; 298, integer:3; 299, elif_clause; 299, 300; 299, 305; 300, comparison_operator:==; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:self; 303, identifier:freshness_state; 304, string:'x'; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:chk; 310, identifier:exit_status; 311, integer:4; 312, else_clause; 312, 313; 313, block; 313, 314; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:chk; 318, identifier:exit_status; 319, integer:3; 320, return_statement; 320, 321; 321, identifier:chk; 322, else_clause; 322, 323; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:logger; 328, identifier:debug; 329, argument_list; 329, 330; 329, 333; 330, concatenated_string; 330, 331; 330, 332; 331, string:"Ignored freshness check for %s, because "; 332, string:"we are not in the check period."; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:self; 336, identifier:get_full_name; 337, argument_list; 338, return_statement; 338, 339; 339, None | def do_check_freshness(self, hosts, services, timeperiods, macromodulations, checkmodulations,
checks, when):
# pylint: disable=too-many-nested-blocks, too-many-branches
"""Check freshness and schedule a check now if necessary.
This function is called by the scheduler if Alignak is configured to check the freshness.
It is called for hosts that have the freshness check enabled if they are only
passively checked.
It is called for services that have the freshness check enabled if they are only
passively checked and if their depending host is not in a freshness expired state
(freshness_expiry = True).
A log is raised when the freshess expiry is detected and the item is set as
freshness_expiry.
:param hosts: hosts objects, used to launch checks
:type hosts: alignak.objects.host.Hosts
:param services: services objects, used launch checks
:type services: alignak.objects.service.Services
:param timeperiods: Timeperiods objects, used to get check_period
:type timeperiods: alignak.objects.timeperiod.Timeperiods
:param macromodulations: Macro modulations objects, used in commands (notif, check)
:type macromodulations: alignak.objects.macromodulation.Macromodulations
:param checkmodulations: Checkmodulations objects, used to change check command if necessary
:type checkmodulations: alignak.objects.checkmodulation.Checkmodulations
:param checks: checks dict, used to get checks_in_progress for the object
:type checks: dict
:return: A check or None
:rtype: None | object
"""
now = when
# Before, check if class (host or service) have check_freshness OK
# Then check if item want freshness, then check freshness
cls = self.__class__
if not self.in_checking and self.freshness_threshold and not self.freshness_expired:
# logger.debug("Checking freshness for %s, last state update: %s, now: %s.",
# self.get_full_name(), self.last_state_update, now)
if os.getenv('ALIGNAK_LOG_CHECKS', None):
logger.info("--ALC-- -> checking freshness for: %s", self.get_full_name())
# If we never checked this item, we begin the freshness period
if not self.last_state_update:
self.last_state_update = int(now)
if self.last_state_update < now - \
(self.freshness_threshold + cls.additional_freshness_latency):
timeperiod = timeperiods[self.check_period]
if timeperiod is None or timeperiod.is_time_valid(now):
# Create a new check for the scheduler
chk = self.launch_check(now, hosts, services, timeperiods,
macromodulations, checkmodulations, checks)
if not chk:
logger.warning("No raised freshness check for: %s", self)
return None
chk.freshness_expiry_check = True
chk.check_time = time.time()
chk.output = "Freshness period expired: %s" % (
datetime.utcfromtimestamp(int(chk.check_time)).strftime(
"%Y-%m-%d %H:%M:%S %Z"))
if self.my_type == 'host':
if self.freshness_state == 'o':
chk.exit_status = 0
elif self.freshness_state == 'd':
chk.exit_status = 2
elif self.freshness_state in ['u', 'x']:
chk.exit_status = 4
else:
chk.exit_status = 3
else:
if self.freshness_state == 'o':
chk.exit_status = 0
elif self.freshness_state == 'w':
chk.exit_status = 1
elif self.freshness_state == 'c':
chk.exit_status = 2
elif self.freshness_state == 'u':
chk.exit_status = 3
elif self.freshness_state == 'x':
chk.exit_status = 4
else:
chk.exit_status = 3
return chk
else:
logger.debug("Ignored freshness check for %s, because "
"we are not in the check period.", self.get_full_name())
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:update_business_impact_value; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:hosts; 6, identifier:services; 7, identifier:timeperiods; 8, identifier:bi_modulations; 9, block; 9, 10; 9, 12; 9, 13; 9, 29; 9, 30; 9, 31; 9, 35; 9, 89; 9, 90; 9, 91; 9, 151; 9, 152; 9, 153; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, if_statement; 13, 14; 13, 20; 14, comparison_operator:==; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:my_own_business_impact; 18, unary_operator:-; 18, 19; 19, integer:1; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:my_own_business_impact; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:business_impact; 29, comment; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:in_modulation; 34, False; 35, for_statement; 35, 36; 35, 37; 35, 40; 36, identifier:bi_modulation_id; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:business_impact_modulations; 40, block; 40, 41; 40, 47; 40, 55; 40, 63; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:bi_modulation; 44, subscript; 44, 45; 44, 46; 45, identifier:bi_modulations; 46, identifier:bi_modulation_id; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:now; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:time; 53, identifier:time; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:period; 58, subscript; 58, 59; 58, 60; 59, identifier:timeperiods; 60, attribute; 60, 61; 60, 62; 61, identifier:bi_modulation; 62, identifier:modulation_period; 63, if_statement; 63, 64; 63, 74; 64, boolean_operator:or; 64, 65; 64, 68; 65, comparison_operator:is; 65, 66; 65, 67; 66, identifier:period; 67, None; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:period; 71, identifier:is_time_valid; 72, argument_list; 72, 73; 73, identifier:now; 74, block; 74, 75; 74, 83; 74, 87; 74, 88; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:business_impact; 80, attribute; 80, 81; 80, 82; 81, identifier:bi_modulation; 82, identifier:business_impact; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:in_modulation; 86, True; 87, comment; 88, break_statement; 89, comment; 90, comment; 91, if_statement; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:impacts; 95, block; 95, 96; 95, 114; 95, 135; 95, 150; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:bp_impacts; 99, list_comprehension; 99, 100; 99, 105; 99, 110; 100, attribute; 100, 101; 100, 104; 101, subscript; 101, 102; 101, 103; 102, identifier:hosts; 103, identifier:elem; 104, identifier:business_impact; 105, for_in_clause; 105, 106; 105, 107; 106, identifier:elem; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:impacts; 110, if_clause; 110, 111; 111, comparison_operator:in; 111, 112; 111, 113; 112, identifier:elem; 113, identifier:hosts; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:bp_impacts; 118, identifier:extend; 119, argument_list; 119, 120; 120, list_comprehension; 120, 121; 120, 126; 120, 131; 121, attribute; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:services; 124, identifier:elem; 125, identifier:business_impact; 126, for_in_clause; 126, 127; 126, 128; 127, identifier:elem; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:impacts; 131, if_clause; 131, 132; 132, comparison_operator:in; 132, 133; 132, 134; 133, identifier:elem; 134, identifier:services; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:business_impact; 140, call; 140, 141; 140, 142; 141, identifier:max; 142, argument_list; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:business_impact; 146, call; 146, 147; 146, 148; 147, identifier:max; 148, argument_list; 148, 149; 149, identifier:bp_impacts; 150, return_statement; 151, comment; 152, comment; 153, if_statement; 153, 154; 153, 163; 154, boolean_operator:and; 154, 155; 154, 161; 155, comparison_operator:!=; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:my_own_business_impact; 159, unary_operator:-; 159, 160; 160, integer:1; 161, not_operator; 161, 162; 162, identifier:in_modulation; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:business_impact; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:my_own_business_impact | def update_business_impact_value(self, hosts, services, timeperiods, bi_modulations):
"""We update our 'business_impact' value with the max of
the impacts business_impact if we got impacts. And save our 'configuration'
business_impact if we do not have do it before
If we do not have impacts, we revert our value
:param hosts: hosts objects, used to get impacts
:type hosts: alignak.objects.host.Hosts
:param services: services objects, used to get impacts
:type services: alignak.objects.service.Services
:param timeperiods: Timeperiods objects, used to get modulation_period
:type timeperiods: alignak.objects.timeperiod.Timeperiods
:param bi_modulations: business impact modulations objects
:type bi_modulations: alignak.object.businessimpactmodulation.Businessimpactmodulations
:return: None
TODO: SchedulingItem object should not handle other schedulingitem obj.
We should call obj.register* on both obj.
This is 'Java' style
"""
# First save our business_impact if not already do
if self.my_own_business_impact == -1:
self.my_own_business_impact = self.business_impact
# We look at our crit modulations. If one apply, we take apply it
# and it's done
in_modulation = False
for bi_modulation_id in self.business_impact_modulations:
bi_modulation = bi_modulations[bi_modulation_id]
now = time.time()
period = timeperiods[bi_modulation.modulation_period]
if period is None or period.is_time_valid(now):
self.business_impact = bi_modulation.business_impact
in_modulation = True
# We apply the first available, that's all
break
# If we truly have impacts, we get the max business_impact
# if it's huge than ourselves
if self.impacts:
bp_impacts = [hosts[elem].business_impact for elem in self.impacts if elem in hosts]
bp_impacts.extend([services[elem].business_impact for elem in self.impacts
if elem in services])
self.business_impact = max(self.business_impact, max(bp_impacts))
return
# If we are not a problem, we setup our own_crit if we are not in a
# modulation period
if self.my_own_business_impact != -1 and not in_modulation:
self.business_impact = self.my_own_business_impact |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 1, 11; 2, function_name:register_a_problem; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:prob; 6, identifier:hosts; 7, identifier:services; 8, identifier:timeperiods; 9, identifier:bi_modulations; 10, comment; 11, block; 11, 12; 11, 14; 11, 15; 11, 26; 11, 34; 11, 40; 11, 41; 11, 42; 11, 48; 11, 52; 11, 53; 11, 54; 11, 55; 11, 224; 11, 225; 12, expression_statement; 12, 13; 13, comment; 14, comment; 15, if_statement; 15, 16; 15, 23; 16, comparison_operator:in; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:prob; 19, identifier:uuid; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:source_problems; 23, block; 23, 24; 24, return_statement; 24, 25; 25, list:[]; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:now; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:time; 32, identifier:time; 33, argument_list; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:was_an_impact; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:is_impact; 40, comment; 41, comment; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:is_impact; 47, True; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:impacts; 51, list:[]; 52, comment; 53, comment; 54, comment; 55, if_statement; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:is_impact; 59, block; 59, 60; 59, 68; 59, 69; 59, 84; 59, 85; 59, 86; 59, 96; 59, 97; 59, 106; 59, 126; 59, 127; 59, 128; 59, 210; 59, 211; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:logger; 64, identifier:debug; 65, argument_list; 65, 66; 65, 67; 66, string:"I am impacted: %s"; 67, identifier:self; 68, comment; 69, if_statement; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:is_problem; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:no_more_a_problem; 79, argument_list; 79, 80; 79, 81; 79, 82; 79, 83; 80, identifier:hosts; 81, identifier:services; 82, identifier:timeperiods; 83, identifier:bi_modulations; 84, comment; 85, comment; 86, if_statement; 86, 87; 86, 89; 87, not_operator; 87, 88; 88, identifier:was_an_impact; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:set_impact_state; 95, argument_list; 96, comment; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:impacts; 101, identifier:append; 102, argument_list; 102, 103; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:uuid; 106, if_statement; 106, 107; 106, 114; 107, comparison_operator:not; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:prob; 110, identifier:uuid; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:source_problems; 114, block; 114, 115; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:source_problems; 121, identifier:append; 122, argument_list; 122, 123; 123, attribute; 123, 124; 123, 125; 124, identifier:prob; 125, identifier:uuid; 126, comment; 127, comment; 128, for_statement; 128, 129; 128, 134; 128, 137; 128, 138; 129, tuple_pattern; 129, 130; 129, 131; 129, 132; 129, 133; 130, identifier:impacted_item_id; 131, identifier:status; 132, identifier:timeperiod_id; 133, identifier:_; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:act_depend_of_me; 137, comment; 138, block; 138, 139; 138, 158; 138, 164; 139, if_statement; 139, 140; 139, 143; 139, 150; 140, comparison_operator:in; 140, 141; 140, 142; 141, identifier:impacted_item_id; 142, identifier:hosts; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:impact; 147, subscript; 147, 148; 147, 149; 148, identifier:hosts; 149, identifier:impacted_item_id; 150, else_clause; 150, 151; 151, block; 151, 152; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:impact; 155, subscript; 155, 156; 155, 157; 156, identifier:services; 157, identifier:impacted_item_id; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:timeperiod; 161, subscript; 161, 162; 161, 163; 162, identifier:timeperiods; 163, identifier:timeperiod_id; 164, for_statement; 164, 165; 164, 166; 164, 167; 165, identifier:stat; 166, identifier:status; 167, block; 167, 168; 168, if_statement; 168, 169; 168, 175; 168, 176; 168, 177; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:is_state; 173, argument_list; 173, 174; 174, identifier:stat; 175, comment; 176, comment; 177, block; 177, 178; 178, if_statement; 178, 179; 178, 189; 179, boolean_operator:or; 179, 180; 179, 183; 180, comparison_operator:is; 180, 181; 180, 182; 181, identifier:timeperiod; 182, None; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:timeperiod; 186, identifier:is_time_valid; 187, argument_list; 187, 188; 188, identifier:now; 189, block; 189, 190; 189, 203; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:new_impacts; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:impact; 196, identifier:register_a_problem; 197, argument_list; 197, 198; 197, 199; 197, 200; 197, 201; 197, 202; 198, identifier:prob; 199, identifier:hosts; 200, identifier:services; 201, identifier:timeperiods; 202, identifier:bi_modulations; 203, expression_statement; 203, 204; 204, call; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:impacts; 207, identifier:extend; 208, argument_list; 208, 209; 209, identifier:new_impacts; 210, comment; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 218; 213, attribute; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:broks; 217, identifier:append; 218, argument_list; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:get_update_status_brok; 223, argument_list; 224, comment; 225, return_statement; 225, 226; 226, identifier:impacts | def register_a_problem(self, prob, hosts, services, timeperiods, bi_modulations):
# pylint: disable=too-many-locals
"""Call recursively by potentials impacts so they
update their source_problems list. But do not
go below if the problem is not a real one for me
like If I've got multiple parents for examples
:param prob: problem to register
:type prob: alignak.objects.schedulingitem.SchedulingItem
:param hosts: hosts objects, used to get object in act_depend_of_me
:type hosts: alignak.objects.host.Hosts
:param services: services objects, used to get object in act_depend_of_me
:type services: alignak.objects.service.Services
:param timeperiods: Timeperiods objects, used for all kind of timeperiod (notif, check)
:type timeperiods: alignak.objects.timeperiod.Timeperiods
:param bi_modulations: business impact modulation are used when setting myself as problem
:type bi_modulations: alignak.object.businessimpactmodulation.Businessimpactmodulations
:return: list of host/service that are impacts
:rtype: list[alignak.objects.schedulingitem.SchedulingItem]
TODO: SchedulingItem object should not handle other schedulingitem obj.
We should call obj.register* on both obj.
This is 'Java' style
"""
# Maybe we already have this problem? If so, bailout too
if prob.uuid in self.source_problems:
return []
now = time.time()
was_an_impact = self.is_impact
# Our father already look if he impacts us. So if we are here,
# it's that we really are impacted
self.is_impact = True
impacts = []
# Ok, if we are impacted, we can add it in our
# problem list
# TODO: remove this unused check
if self.is_impact:
logger.debug("I am impacted: %s", self)
# Maybe I was a problem myself, now I can say: not my fault!
if self.is_problem:
self.no_more_a_problem(hosts, services, timeperiods, bi_modulations)
# Ok, we are now impacted, we should take the good state
# but only when we just go to the impacted state
if not was_an_impact:
self.set_impact_state()
# Ok now we can be a simple impact
impacts.append(self.uuid)
if prob.uuid not in self.source_problems:
self.source_problems.append(prob.uuid)
# we should send this problem to all potential impacted that
# depend on us
for (impacted_item_id, status, timeperiod_id, _) in self.act_depend_of_me:
# Check if the status is ok for impact
if impacted_item_id in hosts:
impact = hosts[impacted_item_id]
else:
impact = services[impacted_item_id]
timeperiod = timeperiods[timeperiod_id]
for stat in status:
if self.is_state(stat):
# now check if we should bailout because of a
# not good timeperiod for dep
if timeperiod is None or timeperiod.is_time_valid(now):
new_impacts = impact.register_a_problem(prob, hosts,
services, timeperiods,
bi_modulations)
impacts.extend(new_impacts)
# And we register a new broks for update status
self.broks.append(self.get_update_status_brok())
# now we return all impacts (can be void of course)
return impacts |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:is_enable_action_dependent; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:hosts; 6, identifier:services; 7, block; 7, 8; 7, 10; 7, 11; 7, 15; 7, 90; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:enable_action; 14, False; 15, for_statement; 15, 16; 15, 21; 15, 24; 16, tuple_pattern; 16, 17; 16, 18; 16, 19; 16, 20; 17, identifier:dep_id; 18, identifier:status; 19, identifier:_; 20, identifier:_; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:act_depend_of; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 29; 25, 34; 26, comparison_operator:in; 26, 27; 26, 28; 27, string:'n'; 28, identifier:status; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:enable_action; 33, True; 34, else_clause; 34, 35; 35, block; 35, 36; 35, 55; 35, 59; 35, 72; 35, 73; 35, 82; 36, if_statement; 36, 37; 36, 40; 36, 47; 37, comparison_operator:in; 37, 38; 37, 39; 38, identifier:dep_id; 39, identifier:hosts; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:dep; 44, subscript; 44, 45; 44, 46; 45, identifier:hosts; 46, identifier:dep_id; 47, else_clause; 47, 48; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:dep; 52, subscript; 52, 53; 52, 54; 53, identifier:services; 54, identifier:dep_id; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:p_is_down; 58, False; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:dep_match; 62, list_comprehension; 62, 63; 62, 69; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:dep; 66, identifier:is_state; 67, argument_list; 67, 68; 68, identifier:stat; 69, for_in_clause; 69, 70; 69, 71; 70, identifier:stat; 71, identifier:status; 72, comment; 73, if_statement; 73, 74; 73, 77; 74, comparison_operator:in; 74, 75; 74, 76; 75, True; 76, identifier:dep_match; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:p_is_down; 81, True; 82, if_statement; 82, 83; 82, 85; 83, not_operator; 83, 84; 84, identifier:p_is_down; 85, block; 85, 86; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:enable_action; 89, True; 90, return_statement; 90, 91; 91, identifier:enable_action | def is_enable_action_dependent(self, hosts, services):
"""
Check if dependencies states match dependencies statuses
This basically means that a dependency is in a bad state and
it can explain this object state.
:param hosts: hosts objects, used to get object in act_depend_of
:type hosts: alignak.objects.host.Hosts
:param services: services objects, used to get object in act_depend_of
:type services: alignak.objects.service.Services
:return: True if all dependencies matches the status, false otherwise
:rtype: bool
"""
# Use to know if notification is raise or not
enable_action = False
for (dep_id, status, _, _) in self.act_depend_of:
if 'n' in status:
enable_action = True
else:
if dep_id in hosts:
dep = hosts[dep_id]
else:
dep = services[dep_id]
p_is_down = False
dep_match = [dep.is_state(stat) for stat in status]
# check if the parent match a case, so he is down
if True in dep_match:
p_is_down = True
if not p_is_down:
enable_action = True
return enable_action |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:update_hard_unknown_phase_state; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 17; 5, 18; 5, 37; 5, 38; 5, 39; 5, 40; 5, 110; 5, 111; 5, 112; 5, 113; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:was_in_hard_unknown_reach_phase; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:in_hard_unknown_reach_phase; 16, comment; 17, comment; 18, if_statement; 18, 19; 18, 30; 19, boolean_operator:or; 19, 20; 19, 25; 20, comparison_operator:!=; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:state_type; 24, string:'HARD'; 25, comparison_operator:!=; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:last_state_type; 29, string:'HARD'; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:in_hard_unknown_reach_phase; 36, False; 37, comment; 38, comment; 39, comment; 40, if_statement; 40, 41; 40, 45; 40, 88; 41, not_operator; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:in_hard_unknown_reach_phase; 45, block; 45, 46; 46, if_statement; 46, 47; 46, 71; 47, boolean_operator:or; 47, 48; 47, 59; 47, 60; 48, boolean_operator:and; 48, 49; 48, 54; 49, comparison_operator:==; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:state; 53, string:'UNKNOWN'; 54, comparison_operator:!=; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:last_state; 58, string:'UNKNOWN'; 59, line_continuation:\; 60, boolean_operator:and; 60, 61; 60, 66; 61, comparison_operator:==; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:state; 65, string:'UNREACHABLE'; 66, comparison_operator:!=; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:last_state; 70, string:'UNREACHABLE'; 71, block; 71, 72; 71, 78; 71, 79; 71, 87; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:in_hard_unknown_reach_phase; 77, True; 78, comment; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:state_before_hard_unknown_reach_phase; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:last_state; 87, return_statement; 88, else_clause; 88, 89; 88, 90; 89, comment; 90, block; 90, 91; 91, if_statement; 91, 92; 91, 103; 92, boolean_operator:and; 92, 93; 92, 98; 93, comparison_operator:!=; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:state; 97, string:'UNKNOWN'; 98, comparison_operator:!=; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:state; 102, string:'UNREACHABLE'; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:in_hard_unknown_reach_phase; 109, False; 110, comment; 111, comment; 112, comment; 113, if_statement; 113, 114; 113, 122; 114, boolean_operator:and; 114, 115; 114, 119; 115, not_operator; 115, 116; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:in_hard_unknown_reach_phase; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:was_in_hard_unknown_reach_phase; 122, block; 122, 123; 123, if_statement; 123, 124; 123, 131; 124, comparison_operator:!=; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:state; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:state_before_hard_unknown_reach_phase; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:was_in_hard_unknown_reach_phase; 137, False | def update_hard_unknown_phase_state(self):
"""Update in_hard_unknown_reach_phase attribute and
was_in_hard_unknown_reach_phase
UNKNOWN during a HARD state are not so important, and they should
not raise notif about it
:return: None
"""
self.was_in_hard_unknown_reach_phase = self.in_hard_unknown_reach_phase
# We do not care about SOFT state at all
# and we are sure we are no more in such a phase
if self.state_type != 'HARD' or self.last_state_type != 'HARD':
self.in_hard_unknown_reach_phase = False
# So if we are not in already in such a phase, we check for
# a start or not. So here we are sure to be in a HARD/HARD following
# state
if not self.in_hard_unknown_reach_phase:
if self.state == 'UNKNOWN' and self.last_state != 'UNKNOWN' \
or self.state == 'UNREACHABLE' and self.last_state != 'UNREACHABLE':
self.in_hard_unknown_reach_phase = True
# We also backup with which state we was before enter this phase
self.state_before_hard_unknown_reach_phase = self.last_state
return
else:
# if we were already in such a phase, look for its end
if self.state != 'UNKNOWN' and self.state != 'UNREACHABLE':
self.in_hard_unknown_reach_phase = False
# If we just exit the phase, look if we exit with a different state
# than we enter or not. If so, lie and say we were not in such phase
# because we need so to raise a new notif
if not self.in_hard_unknown_reach_phase and self.was_in_hard_unknown_reach_phase:
if self.state != self.state_before_hard_unknown_reach_phase:
self.was_in_hard_unknown_reach_phase = False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 1, 9; 2, function_name:get_next_notification_time; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:notif; 6, identifier:escalations; 7, identifier:timeperiods; 8, comment; 9, block; 9, 10; 9, 12; 9, 16; 9, 24; 9, 30; 9, 31; 9, 37; 9, 38; 9, 39; 9, 51; 9, 113; 9, 114; 9, 126; 9, 127; 9, 128; 9, 129; 9, 144; 9, 145; 9, 149; 9, 155; 9, 163; 9, 227; 9, 228; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:res; 15, None; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:now; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:time; 22, identifier:time; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:cls; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:__class__; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:notification_interval; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:notification_interval; 37, comment; 38, comment; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:in_notif_time; 42, binary_operator:-; 42, 43; 42, 48; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:time; 46, identifier:time; 47, argument_list; 48, attribute; 48, 49; 48, 50; 49, identifier:notif; 50, identifier:creation_time; 51, for_statement; 51, 52; 51, 53; 51, 56; 52, identifier:escalation_id; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:escalations; 56, block; 56, 57; 56, 63; 56, 71; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:escalation; 60, subscript; 60, 61; 60, 62; 61, identifier:escalations; 62, identifier:escalation_id; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:escalation_period; 66, subscript; 66, 67; 66, 68; 67, identifier:timeperiods; 68, attribute; 68, 69; 68, 70; 69, identifier:escalation; 70, identifier:escalation_period; 71, if_statement; 71, 72; 71, 91; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:escalation; 75, identifier:is_eligible; 76, argument_list; 76, 77; 76, 80; 76, 83; 76, 86; 76, 87; 76, 90; 77, attribute; 77, 78; 77, 79; 78, identifier:notif; 79, identifier:t_to_go; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:state; 83, attribute; 83, 84; 83, 85; 84, identifier:notif; 85, identifier:notif_nb; 86, identifier:in_notif_time; 87, attribute; 87, 88; 87, 89; 88, identifier:cls; 89, identifier:interval_length; 90, identifier:escalation_period; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 106; 93, boolean_operator:and; 93, 94; 93, 100; 93, 101; 94, comparison_operator:!=; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:escalation; 97, identifier:notification_interval; 98, unary_operator:-; 98, 99; 99, integer:1; 100, line_continuation:\; 101, comparison_operator:<; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:escalation; 104, identifier:notification_interval; 105, identifier:notification_interval; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:notification_interval; 110, attribute; 110, 111; 110, 112; 111, identifier:escalation; 112, identifier:notification_interval; 113, comment; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:std_time; 117, binary_operator:+; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:notif; 120, identifier:t_to_go; 121, binary_operator:*; 121, 122; 121, 123; 122, identifier:notification_interval; 123, attribute; 123, 124; 123, 125; 124, identifier:cls; 125, identifier:interval_length; 126, comment; 127, comment; 128, comment; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:<; 130, 131; 130, 132; 131, identifier:std_time; 132, identifier:now; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:std_time; 137, binary_operator:+; 137, 138; 137, 139; 138, identifier:now; 139, binary_operator:*; 139, 140; 139, 141; 140, identifier:notification_interval; 141, attribute; 141, 142; 141, 143; 142, identifier:cls; 143, identifier:interval_length; 144, comment; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:res; 148, identifier:std_time; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:creation_time; 152, attribute; 152, 153; 152, 154; 153, identifier:notif; 154, identifier:creation_time; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:in_notif_time; 158, binary_operator:-; 158, 159; 158, 160; 159, identifier:now; 160, attribute; 160, 161; 160, 162; 161, identifier:notif; 162, identifier:creation_time; 163, for_statement; 163, 164; 163, 165; 163, 168; 164, identifier:escalation_id; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:escalations; 168, block; 168, 169; 168, 175; 168, 176; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:escalation; 172, subscript; 172, 173; 172, 174; 173, identifier:escalations; 174, identifier:escalation_id; 175, comment; 176, if_statement; 176, 177; 176, 186; 177, comparison_operator:not; 177, 178; 177, 183; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:escalation; 181, identifier:get_name; 182, argument_list; 183, attribute; 183, 184; 183, 185; 184, identifier:notif; 185, identifier:already_start_escalations; 186, block; 186, 187; 186, 195; 186, 212; 186, 213; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:escalation_period; 190, subscript; 190, 191; 190, 192; 191, identifier:timeperiods; 192, attribute; 192, 193; 192, 194; 193, identifier:escalation; 194, identifier:escalation_period; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:next_t; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:escalation; 201, identifier:get_next_notif_time; 202, argument_list; 202, 203; 202, 204; 202, 207; 202, 208; 202, 211; 203, identifier:std_time; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:state; 207, identifier:creation_time; 208, attribute; 208, 209; 208, 210; 209, identifier:cls; 210, identifier:interval_length; 211, identifier:escalation_period; 212, comment; 213, if_statement; 213, 214; 213, 222; 214, boolean_operator:and; 214, 215; 214, 218; 215, comparison_operator:is; 215, 216; 215, 217; 216, identifier:next_t; 217, None; 218, comparison_operator:<; 218, 219; 218, 220; 218, 221; 219, identifier:now; 220, identifier:next_t; 221, identifier:res; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:res; 226, identifier:next_t; 227, comment; 228, return_statement; 228, 229; 229, identifier:res | def get_next_notification_time(self, notif, escalations, timeperiods):
# pylint: disable=too-many-locals
"""Get the next notification time for a notification
Take the standard notification_interval or ask for our escalation
if one of them need a smaller value to escalade
:param notif: Notification we need time
:type notif: alignak.objects.notification.Notification
:param escalations: Esclations objects, used to get escalation objects (interval, period)
:type escalations: alignak.objects.escalation.Escalations
:param timeperiods: Timeperiods objects, used to get escalation period
:type timeperiods: alignak.objects.timeperiod.Timeperiods
:return: Timestamp of next notification
:rtype: int
"""
res = None
now = time.time()
cls = self.__class__
# Look at the minimum notification interval
notification_interval = self.notification_interval
# and then look for currently active notifications, and take notification_interval
# if filled and less than the self value
in_notif_time = time.time() - notif.creation_time
for escalation_id in self.escalations:
escalation = escalations[escalation_id]
escalation_period = timeperiods[escalation.escalation_period]
if escalation.is_eligible(notif.t_to_go, self.state, notif.notif_nb,
in_notif_time, cls.interval_length, escalation_period):
if escalation.notification_interval != -1 and \
escalation.notification_interval < notification_interval:
notification_interval = escalation.notification_interval
# So take the by default time
std_time = notif.t_to_go + notification_interval * cls.interval_length
# Maybe the notification comes from retention data and
# next notification alert is in the past
# if so let use the now value instead
if std_time < now:
std_time = now + notification_interval * cls.interval_length
# standard time is a good one
res = std_time
creation_time = notif.creation_time
in_notif_time = now - notif.creation_time
for escalation_id in self.escalations:
escalation = escalations[escalation_id]
# If the escalation was already raised, we do not look for a new "early start"
if escalation.get_name() not in notif.already_start_escalations:
escalation_period = timeperiods[escalation.escalation_period]
next_t = escalation.get_next_notif_time(std_time, self.state,
creation_time, cls.interval_length,
escalation_period)
# If we got a real result (time base escalation), we add it
if next_t is not None and now < next_t < res:
res = next_t
# And we take the minimum of this result. Can be standard or escalation asked
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 1, 10; 2, function_name:get_business_rule_output; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:hosts; 6, identifier:services; 7, identifier:macromodulations; 8, identifier:timeperiods; 9, comment; 10, block; 10, 11; 10, 13; 10, 22; 10, 23; 10, 36; 10, 37; 10, 43; 10, 49; 10, 55; 10, 56; 10, 66; 10, 82; 10, 83; 10, 87; 10, 91; 10, 92; 10, 102; 10, 163; 10, 175; 10, 176; 10, 187; 10, 196; 10, 208; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:got_business_rule; 16, call; 16, 17; 16, 18; 17, identifier:getattr; 18, argument_list; 18, 19; 18, 20; 18, 21; 19, identifier:self; 20, string:'got_business_rule'; 21, False; 22, comment; 23, if_statement; 23, 24; 23, 33; 24, boolean_operator:or; 24, 25; 24, 28; 25, comparison_operator:is; 25, 26; 25, 27; 26, identifier:got_business_rule; 27, False; 28, comparison_operator:is; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:business_rule; 32, None; 33, block; 33, 34; 34, return_statement; 34, 35; 35, string:""; 36, comment; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:output_template; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:business_rule_output_template; 43, if_statement; 43, 44; 43, 46; 44, not_operator; 44, 45; 45, identifier:output_template; 46, block; 46, 47; 47, return_statement; 47, 48; 48, string:""; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:macroresolver; 52, call; 52, 53; 52, 54; 53, identifier:MacroResolver; 54, argument_list; 55, comment; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:elts; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:re; 62, identifier:findall; 63, argument_list; 63, 64; 63, 65; 64, string:r"\$\((.*)\)\$"; 65, identifier:output_template; 66, if_statement; 66, 67; 66, 69; 66, 74; 67, not_operator; 67, 68; 68, identifier:elts; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:child_template_string; 73, string:""; 74, else_clause; 74, 75; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:child_template_string; 79, subscript; 79, 80; 79, 81; 80, identifier:elts; 81, integer:0; 82, comment; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:children_output; 86, string:""; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:ok_count; 90, integer:0; 91, comment; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:items; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:business_rule; 100, identifier:list_all_elements; 101, argument_list; 102, for_statement; 102, 103; 102, 104; 102, 105; 103, identifier:item_uuid; 104, identifier:items; 105, block; 105, 106; 105, 128; 105, 129; 105, 130; 105, 142; 105, 151; 106, if_statement; 106, 107; 106, 110; 106, 117; 107, comparison_operator:in; 107, 108; 107, 109; 108, identifier:item_uuid; 109, identifier:hosts; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:item; 114, subscript; 114, 115; 114, 116; 115, identifier:hosts; 116, identifier:item_uuid; 117, elif_clause; 117, 118; 117, 121; 118, comparison_operator:in; 118, 119; 118, 120; 119, identifier:item_uuid; 120, identifier:services; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:item; 125, subscript; 125, 126; 125, 127; 126, identifier:services; 127, identifier:item_uuid; 128, comment; 129, comment; 130, if_statement; 130, 131; 130, 136; 131, comparison_operator:==; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:item; 134, identifier:last_hard_state_id; 135, integer:0; 136, block; 136, 137; 136, 141; 137, expression_statement; 137, 138; 138, augmented_assignment:+=; 138, 139; 138, 140; 139, identifier:ok_count; 140, integer:1; 141, continue_statement; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:data; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:item; 148, identifier:get_data_for_checks; 149, argument_list; 149, 150; 150, identifier:hosts; 151, expression_statement; 151, 152; 152, augmented_assignment:+=; 152, 153; 152, 154; 153, identifier:children_output; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:macroresolver; 157, identifier:resolve_simple_macros_in_string; 158, argument_list; 158, 159; 158, 160; 158, 161; 158, 162; 159, identifier:child_template_string; 160, identifier:data; 161, identifier:macromodulations; 162, identifier:timeperiods; 163, if_statement; 163, 164; 163, 170; 164, comparison_operator:==; 164, 165; 164, 166; 165, identifier:ok_count; 166, call; 166, 167; 166, 168; 167, identifier:len; 168, argument_list; 168, 169; 169, identifier:items; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:children_output; 174, string:"all checks were successful."; 175, comment; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:template_string; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:re; 182, identifier:sub; 183, argument_list; 183, 184; 183, 185; 183, 186; 184, string:r"\$\(.*\)\$"; 185, identifier:children_output; 186, identifier:output_template; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:data; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:get_data_for_checks; 194, argument_list; 194, 195; 195, identifier:hosts; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:output; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:macroresolver; 202, identifier:resolve_simple_macros_in_string; 203, argument_list; 203, 204; 203, 205; 203, 206; 203, 207; 204, identifier:template_string; 205, identifier:data; 206, identifier:macromodulations; 207, identifier:timeperiods; 208, return_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:output; 212, identifier:strip; 213, argument_list | def get_business_rule_output(self, hosts, services, macromodulations, timeperiods):
# pylint: disable=too-many-locals, too-many-branches
"""
Returns a status string for business rules based items formatted
using business_rule_output_template attribute as template.
The template may embed output formatting for itself, and for its child
(dependent) items. Child format string is expanded into the $( and )$,
using the string between brackets as format string.
Any business rule based item or child macro may be used. In addition,
the $STATUS$, $SHORTSTATUS$ and $FULLNAME$ macro which name is common
to hosts and services may be used to ease template writing.
Caution: only children in state not OK are displayed.
Example:
A business rule with a format string looking like
"$STATUS$ [ $($TATUS$: $HOSTNAME$,$SERVICEDESC$ )$ ]"
Would return
"CRITICAL [ CRITICAL: host1,srv1 WARNING: host2,srv2 ]"
:param hosts: Hosts object to look for objects
:type hosts: alignak.objects.host.Hosts
:param services: Services object to look for objects
:type services: alignak.objects.service.Services
:param macromodulations: Macromodulations object to look for objects
:type macromodulations: alignak.objects.macromodulation.Macromodulations
:param timeperiods: Timeperiods object to look for objects
:type timeperiods: alignak.objects.timeperiod.Timeperiods
:return: status for business rules
:rtype: str
"""
got_business_rule = getattr(self, 'got_business_rule', False)
# Checks that the service is a business rule.
if got_business_rule is False or self.business_rule is None:
return ""
# Checks that the business rule has a format specified.
output_template = self.business_rule_output_template
if not output_template:
return ""
macroresolver = MacroResolver()
# Extracts children template strings
elts = re.findall(r"\$\((.*)\)\$", output_template)
if not elts:
child_template_string = ""
else:
child_template_string = elts[0]
# Processes child services output
children_output = ""
ok_count = 0
# Expands child items format string macros.
items = self.business_rule.list_all_elements()
for item_uuid in items:
if item_uuid in hosts:
item = hosts[item_uuid]
elif item_uuid in services:
item = services[item_uuid]
# Do not display children in OK state
# todo: last_hard_state ? why not current state if state type is hard ?
if item.last_hard_state_id == 0:
ok_count += 1
continue
data = item.get_data_for_checks(hosts)
children_output += macroresolver.resolve_simple_macros_in_string(child_template_string,
data,
macromodulations,
timeperiods)
if ok_count == len(items):
children_output = "all checks were successful."
# Replaces children output string
template_string = re.sub(r"\$\(.*\)\$", children_output, output_template)
data = self.get_data_for_checks(hosts)
output = macroresolver.resolve_simple_macros_in_string(template_string, data,
macromodulations, timeperiods)
return output.strip() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 1, 8; 2, function_name:business_rule_notification_is_blocked; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:hosts; 6, identifier:services; 7, comment; 8, block; 8, 9; 8, 11; 8, 12; 8, 13; 8, 17; 8, 105; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:acknowledged; 16, integer:0; 17, for_statement; 17, 18; 17, 19; 17, 22; 18, identifier:src_prob_id; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:source_problems; 22, block; 22, 23; 22, 42; 23, if_statement; 23, 24; 23, 27; 23, 34; 24, comparison_operator:in; 24, 25; 24, 26; 25, identifier:src_prob_id; 26, identifier:hosts; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:src_prob; 31, subscript; 31, 32; 31, 33; 32, identifier:hosts; 33, identifier:src_prob_id; 34, else_clause; 34, 35; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:src_prob; 39, subscript; 39, 40; 39, 41; 40, identifier:services; 41, identifier:src_prob_id; 42, if_statement; 42, 43; 42, 48; 43, comparison_operator:!=; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:src_prob; 46, identifier:last_hard_state_id; 47, integer:0; 48, block; 48, 49; 49, if_statement; 49, 50; 49, 53; 49, 54; 49, 59; 49, 60; 49, 61; 50, attribute; 50, 51; 50, 52; 51, identifier:src_prob; 52, identifier:problem_has_been_acknowledged; 53, comment; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, augmented_assignment:+=; 56, 57; 56, 58; 57, identifier:acknowledged; 58, integer:1; 59, comment; 60, comment; 61, elif_clause; 61, 62; 61, 67; 62, comparison_operator:is; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:business_rule_downtime_as_ack; 66, True; 67, block; 67, 68; 68, if_statement; 68, 69; 68, 74; 68, 75; 68, 76; 68, 81; 69, comparison_operator:>; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:src_prob; 72, identifier:scheduled_downtime_depth; 73, integer:0; 74, comment; 75, comment; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, augmented_assignment:+=; 78, 79; 78, 80; 79, identifier:acknowledged; 80, integer:1; 81, elif_clause; 81, 82; 81, 98; 81, 99; 81, 100; 82, boolean_operator:and; 82, 83; 82, 88; 82, 89; 83, call; 83, 84; 83, 85; 84, identifier:hasattr; 85, argument_list; 85, 86; 85, 87; 86, identifier:src_prob; 87, string:"host"; 88, line_continuation:\; 89, comparison_operator:>; 89, 90; 89, 97; 90, attribute; 90, 91; 90, 96; 91, subscript; 91, 92; 91, 93; 92, identifier:hosts; 93, attribute; 93, 94; 93, 95; 94, identifier:src_prob; 95, identifier:host; 96, identifier:scheduled_downtime_depth; 97, integer:0; 98, comment; 99, comment; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, augmented_assignment:+=; 102, 103; 102, 104; 103, identifier:acknowledged; 104, integer:1; 105, return_statement; 105, 106; 106, comparison_operator:==; 106, 107; 106, 108; 107, identifier:acknowledged; 108, call; 108, 109; 108, 110; 109, identifier:len; 110, argument_list; 110, 111; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:source_problems | def business_rule_notification_is_blocked(self, hosts, services):
# pylint: disable=too-many-locals
"""Process business rule notifications behaviour. If all problems have
been acknowledged, no notifications should be sent if state is not OK.
By default, downtimes are ignored, unless explicitly told to be treated
as acknowledgements through with the business_rule_downtime_as_ack set.
:return: True if all source problem are acknowledged, otherwise False
:rtype: bool
"""
# Walks through problems to check if all items in non ok are
# acknowledged or in downtime period.
acknowledged = 0
for src_prob_id in self.source_problems:
if src_prob_id in hosts:
src_prob = hosts[src_prob_id]
else:
src_prob = services[src_prob_id]
if src_prob.last_hard_state_id != 0:
if src_prob.problem_has_been_acknowledged:
# Problem hast been acknowledged
acknowledged += 1
# Only check problems under downtime if we are
# explicitly told to do so.
elif self.business_rule_downtime_as_ack is True:
if src_prob.scheduled_downtime_depth > 0:
# Problem is under downtime, and downtimes should be
# treated as acknowledgements
acknowledged += 1
elif hasattr(src_prob, "host") and \
hosts[src_prob.host].scheduled_downtime_depth > 0:
# Host is under downtime, and downtimes should be
# treated as acknowledgements
acknowledged += 1
return acknowledged == len(self.source_problems) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 1, 16; 2, function_name:acknowledge_problem; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 4, identifier:self; 5, identifier:notification_period; 6, identifier:hosts; 7, identifier:services; 8, identifier:sticky; 9, identifier:notify; 10, identifier:author; 11, identifier:comment; 12, default_parameter; 12, 13; 12, 14; 13, identifier:end_time; 14, integer:0; 15, comment; 16, block; 16, 17; 16, 19; 16, 23; 16, 38; 16, 279; 16, 280; 16, 315; 17, expression_statement; 17, 18; 18, comment; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:comm; 22, None; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:logger; 27, identifier:debug; 28, argument_list; 28, 29; 28, 30; 28, 33; 29, string:"Acknowledge requested for %s %s."; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:my_type; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:get_name; 37, argument_list; 38, if_statement; 38, 39; 38, 46; 38, 47; 38, 262; 39, comparison_operator:!=; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:state; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:ok_up; 46, comment; 47, block; 47, 48; 47, 71; 47, 84; 47, 90; 47, 96; 47, 120; 47, 129; 47, 189; 47, 216; 47, 223; 47, 233; 47, 243; 47, 256; 48, if_statement; 48, 49; 48, 56; 49, boolean_operator:and; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:problem_has_been_acknowledged; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:acknowledgement; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:del_comment; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:getattr; 65, argument_list; 65, 66; 65, 69; 65, 70; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:acknowledgement; 69, string:'comment_id'; 70, None; 71, if_statement; 71, 72; 71, 73; 72, identifier:notify; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:create_notifications; 79, argument_list; 79, 80; 79, 81; 79, 82; 79, 83; 80, string:'ACKNOWLEDGEMENT'; 81, identifier:notification_period; 82, identifier:hosts; 83, identifier:services; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:problem_has_been_acknowledged; 89, True; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:sticky; 93, comparison_operator:==; 93, 94; 93, 95; 94, identifier:sticky; 95, integer:2; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:data; 99, dictionary; 99, 100; 99, 105; 99, 108; 99, 111; 99, 114; 99, 117; 100, pair; 100, 101; 100, 102; 101, string:'ref'; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:uuid; 105, pair; 105, 106; 105, 107; 106, string:'sticky'; 107, identifier:sticky; 108, pair; 108, 109; 108, 110; 109, string:'author'; 110, identifier:author; 111, pair; 111, 112; 111, 113; 112, string:'comment'; 113, identifier:comment; 114, pair; 114, 115; 114, 116; 115, string:'end_time'; 116, identifier:end_time; 117, pair; 117, 118; 117, 119; 118, string:'notify'; 119, identifier:notify; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:acknowledgement; 125, call; 125, 126; 125, 127; 126, identifier:Acknowledge; 127, argument_list; 127, 128; 128, identifier:data; 129, if_statement; 129, 130; 129, 135; 129, 160; 130, comparison_operator:==; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:self; 133, identifier:my_type; 134, string:'host'; 135, block; 135, 136; 135, 140; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:comment_type; 139, integer:1; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:broks; 146, identifier:append; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:acknowledgement; 153, identifier:get_raise_brok; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:get_name; 159, argument_list; 160, else_clause; 160, 161; 161, block; 161, 162; 161, 166; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:comment_type; 165, integer:2; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:broks; 172, identifier:append; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:acknowledgement; 179, identifier:get_raise_brok; 180, argument_list; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:host_name; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:get_name; 188, argument_list; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:data; 192, dictionary; 192, 193; 192, 196; 192, 199; 192, 202; 192, 205; 192, 208; 192, 211; 193, pair; 193, 194; 193, 195; 194, string:'author'; 195, identifier:author; 196, pair; 196, 197; 196, 198; 197, string:'comment'; 198, identifier:comment; 199, pair; 199, 200; 199, 201; 200, string:'comment_type'; 201, identifier:comment_type; 202, pair; 202, 203; 202, 204; 203, string:'entry_type'; 204, integer:4; 205, pair; 205, 206; 205, 207; 206, string:'source'; 207, integer:0; 208, pair; 208, 209; 208, 210; 209, string:'expires'; 210, False; 211, pair; 211, 212; 211, 213; 212, string:'ref'; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:uuid; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:comm; 219, call; 219, 220; 219, 221; 220, identifier:Comment; 221, argument_list; 221, 222; 222, identifier:data; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 230; 225, attribute; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:acknowledgement; 229, identifier:comment_id; 230, attribute; 230, 231; 230, 232; 231, identifier:comm; 232, identifier:uuid; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 242; 235, subscript; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:comments; 239, attribute; 239, 240; 239, 241; 240, identifier:comm; 241, identifier:uuid; 242, identifier:comm; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:broks; 249, identifier:append; 250, argument_list; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:get_update_status_brok; 255, argument_list; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:raise_acknowledge_log_entry; 261, argument_list; 262, else_clause; 262, 263; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, call; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:logger; 268, identifier:debug; 269, argument_list; 269, 270; 269, 271; 269, 274; 270, string:"Acknowledge requested for %s %s but element state is OK/UP."; 271, attribute; 271, 272; 271, 273; 272, identifier:self; 273, identifier:my_type; 274, call; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:self; 277, identifier:get_name; 278, argument_list; 279, comment; 280, if_statement; 280, 281; 280, 286; 281, comparison_operator:==; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:self; 284, identifier:my_type; 285, string:'host'; 286, block; 286, 287; 287, for_statement; 287, 288; 287, 289; 287, 292; 288, identifier:service_uuid; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:services; 292, block; 292, 293; 292, 299; 293, if_statement; 293, 294; 293, 297; 294, comparison_operator:not; 294, 295; 294, 296; 295, identifier:service_uuid; 296, identifier:services; 297, block; 297, 298; 298, continue_statement; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 306; 301, attribute; 301, 302; 301, 305; 302, subscript; 302, 303; 302, 304; 303, identifier:services; 304, identifier:service_uuid; 305, identifier:acknowledge_problem; 306, argument_list; 306, 307; 306, 308; 306, 309; 306, 310; 306, 311; 306, 312; 306, 313; 306, 314; 307, identifier:notification_period; 308, identifier:hosts; 309, identifier:services; 310, identifier:sticky; 311, identifier:notify; 312, identifier:author; 313, identifier:comment; 314, identifier:end_time; 315, return_statement; 315, 316; 316, identifier:comm | def acknowledge_problem(self, notification_period, hosts, services, sticky, notify, author,
comment, end_time=0):
# pylint: disable=too-many-arguments
"""
Add an acknowledge
:param sticky: acknowledge will be always present is host return in UP state
:type sticky: integer
:param notify: if to 1, send a notification
:type notify: integer
:param author: name of the author or the acknowledge
:type author: str
:param comment: comment (description) of the acknowledge
:type comment: str
:param end_time: end (timeout) of this acknowledge in seconds(timestamp) (0 to never end)
:type end_time: int
:return: None | alignak.comment.Comment
"""
comm = None
logger.debug("Acknowledge requested for %s %s.", self.my_type, self.get_name())
if self.state != self.ok_up:
# case have yet an acknowledge
if self.problem_has_been_acknowledged and self.acknowledgement:
self.del_comment(getattr(self.acknowledgement, 'comment_id', None))
if notify:
self.create_notifications('ACKNOWLEDGEMENT',
notification_period, hosts, services)
self.problem_has_been_acknowledged = True
sticky = sticky == 2
data = {
'ref': self.uuid, 'sticky': sticky, 'author': author, 'comment': comment,
'end_time': end_time, 'notify': notify
}
self.acknowledgement = Acknowledge(data)
if self.my_type == 'host':
comment_type = 1
self.broks.append(self.acknowledgement.get_raise_brok(self.get_name()))
else:
comment_type = 2
self.broks.append(self.acknowledgement.get_raise_brok(self.host_name,
self.get_name()))
data = {
'author': author, 'comment': comment, 'comment_type': comment_type, 'entry_type': 4,
'source': 0, 'expires': False, 'ref': self.uuid
}
comm = Comment(data)
self.acknowledgement.comment_id = comm.uuid
self.comments[comm.uuid] = comm
self.broks.append(self.get_update_status_brok())
self.raise_acknowledge_log_entry()
else:
logger.debug("Acknowledge requested for %s %s but element state is OK/UP.",
self.my_type, self.get_name())
# For an host, acknowledge all its services that are problems
if self.my_type == 'host':
for service_uuid in self.services:
if service_uuid not in services:
continue
services[service_uuid].acknowledge_problem(notification_period, hosts, services,
sticky, notify, author, comment,
end_time)
return comm |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 1, 15; 2, function_name:setup_logger; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:logger_configuration_file; 5, default_parameter; 5, 6; 5, 7; 6, identifier:log_dir; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:process_name; 10, string:''; 11, default_parameter; 11, 12; 11, 13; 12, identifier:log_file; 13, string:''; 14, comment; 15, block; 15, 16; 15, 18; 15, 27; 16, expression_statement; 16, 17; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:logger_; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:logging; 24, identifier:getLogger; 25, argument_list; 25, 26; 26, identifier:ALIGNAK_LOGGER_NAME; 27, for_statement; 27, 28; 27, 29; 27, 32; 27, 129; 28, identifier:handler; 29, attribute; 29, 30; 29, 31; 30, identifier:logger_; 31, identifier:handlers; 32, block; 32, 33; 32, 38; 32, 39; 33, if_statement; 33, 34; 33, 36; 34, not_operator; 34, 35; 35, identifier:process_name; 36, block; 36, 37; 37, break_statement; 38, comment; 39, if_statement; 39, 40; 39, 48; 39, 49; 39, 50; 39, 51; 40, comparison_operator:==; 40, 41; 40, 47; 41, call; 41, 42; 41, 43; 42, identifier:getattr; 43, argument_list; 43, 44; 43, 45; 43, 46; 44, identifier:handler; 45, string:'_name'; 46, None; 47, string:'daemons'; 48, comment; 49, comment; 50, comment; 51, block; 51, 52; 51, 128; 52, for_statement; 52, 53; 52, 54; 52, 57; 52, 58; 53, identifier:hdlr; 54, attribute; 54, 55; 54, 56; 55, identifier:logger_; 56, identifier:handlers; 57, comment; 58, block; 58, 59; 58, 94; 58, 124; 58, 125; 58, 126; 58, 127; 59, if_statement; 59, 60; 59, 67; 60, comparison_operator:in; 60, 61; 60, 62; 61, string:'alignak_tests'; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:hdlr; 65, identifier:formatter; 66, identifier:_fmt; 67, block; 67, 68; 67, 87; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:formatter; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:logging; 74, identifier:Formatter; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 84; 77, attribute; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:hdlr; 81, identifier:formatter; 82, identifier:_fmt; 83, identifier:replace; 84, argument_list; 84, 85; 84, 86; 85, string:"alignak_tests"; 86, identifier:process_name; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:hdlr; 91, identifier:setFormatter; 92, argument_list; 92, 93; 93, identifier:formatter; 94, if_statement; 94, 95; 94, 107; 95, boolean_operator:and; 95, 96; 95, 102; 96, call; 96, 97; 96, 98; 97, identifier:getattr; 98, argument_list; 98, 99; 98, 100; 98, 101; 99, identifier:hdlr; 100, string:'filename'; 101, None; 102, comparison_operator:in; 102, 103; 102, 104; 103, string:'alignak_tests'; 104, attribute; 104, 105; 104, 106; 105, identifier:hdlr; 106, identifier:filename; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:hdlr; 112, identifier:filename; 113, call; 113, 114; 113, 121; 114, attribute; 114, 115; 114, 120; 115, attribute; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:hdlr; 118, identifier:filename; 119, identifier:_fmt; 120, identifier:replace; 121, argument_list; 121, 122; 121, 123; 122, string:"alignak_tests"; 123, identifier:process_name; 124, comment; 125, comment; 126, comment; 127, comment; 128, break_statement; 129, else_clause; 129, 130; 130, block; 130, 131; 130, 153; 130, 369; 130, 370; 131, if_statement; 131, 132; 131, 144; 132, boolean_operator:or; 132, 133; 132, 135; 133, not_operator; 133, 134; 134, identifier:logger_configuration_file; 135, not_operator; 135, 136; 136, call; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:os; 140, identifier:path; 141, identifier:exists; 142, argument_list; 142, 143; 143, identifier:logger_configuration_file; 144, block; 144, 145; 144, 152; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:print; 148, argument_list; 148, 149; 149, binary_operator:%; 149, 150; 149, 151; 150, string:"The logger configuration file does not exist: %s"; 151, identifier:logger_configuration_file; 152, return_statement; 153, with_statement; 153, 154; 153, 164; 154, with_clause; 154, 155; 155, with_item; 155, 156; 156, as_pattern; 156, 157; 156, 162; 157, call; 157, 158; 157, 159; 158, identifier:open; 159, argument_list; 159, 160; 159, 161; 160, identifier:logger_configuration_file; 161, string:'rt'; 162, as_pattern_target; 162, 163; 163, identifier:_file; 164, block; 164, 165; 164, 174; 164, 178; 164, 189; 164, 197; 164, 205; 164, 206; 164, 245; 164, 246; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:config; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:json; 171, identifier:load; 172, argument_list; 172, 173; 173, identifier:_file; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:truncate; 177, False; 178, if_statement; 178, 179; 178, 184; 179, boolean_operator:and; 179, 180; 179, 182; 180, not_operator; 180, 181; 181, identifier:process_name; 182, not_operator; 182, 183; 183, identifier:log_dir; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:truncate; 188, True; 189, if_statement; 189, 190; 189, 192; 190, not_operator; 190, 191; 191, identifier:process_name; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:process_name; 196, string:'alignak_tests'; 197, if_statement; 197, 198; 197, 200; 198, not_operator; 198, 199; 199, identifier:log_dir; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 204; 203, identifier:log_dir; 204, string:'/tmp'; 205, comment; 206, for_statement; 206, 207; 206, 208; 206, 211; 207, identifier:formatter; 208, subscript; 208, 209; 208, 210; 209, identifier:config; 210, string:'formatters'; 211, block; 211, 212; 211, 222; 212, if_statement; 212, 213; 212, 220; 213, comparison_operator:not; 213, 214; 213, 215; 214, string:'format'; 215, subscript; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:config; 218, string:'formatters'; 219, identifier:formatter; 220, block; 220, 221; 221, continue_statement; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 231; 223, 232; 224, subscript; 224, 225; 224, 230; 225, subscript; 225, 226; 225, 229; 226, subscript; 226, 227; 226, 228; 227, identifier:config; 228, string:'formatters'; 229, identifier:formatter; 230, string:'format'; 231, line_continuation:\; 232, call; 232, 233; 232, 242; 233, attribute; 233, 234; 233, 241; 234, subscript; 234, 235; 234, 240; 235, subscript; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:config; 238, string:'formatters'; 239, identifier:formatter; 240, string:'format'; 241, identifier:replace; 242, argument_list; 242, 243; 242, 244; 243, string:"%(daemon)s"; 244, identifier:process_name; 245, comment; 246, for_statement; 246, 247; 246, 248; 246, 251; 247, identifier:hdlr; 248, subscript; 248, 249; 248, 250; 249, identifier:config; 250, string:'handlers'; 251, block; 251, 252; 251, 262; 251, 304; 251, 327; 252, if_statement; 252, 253; 252, 260; 253, comparison_operator:not; 253, 254; 253, 255; 254, string:'filename'; 255, subscript; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:config; 258, string:'handlers'; 259, identifier:hdlr; 260, block; 260, 261; 261, continue_statement; 262, if_statement; 262, 263; 262, 268; 262, 279; 263, boolean_operator:and; 263, 264; 263, 265; 264, identifier:log_file; 265, comparison_operator:==; 265, 266; 265, 267; 266, identifier:hdlr; 267, string:'daemons'; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 278; 271, subscript; 271, 272; 271, 277; 272, subscript; 272, 273; 272, 276; 273, subscript; 273, 274; 273, 275; 274, identifier:config; 275, string:'handlers'; 276, identifier:hdlr; 277, string:'filename'; 278, identifier:log_file; 279, else_clause; 279, 280; 280, block; 280, 281; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 290; 282, 291; 283, subscript; 283, 284; 283, 289; 284, subscript; 284, 285; 284, 288; 285, subscript; 285, 286; 285, 287; 286, identifier:config; 287, string:'handlers'; 288, identifier:hdlr; 289, string:'filename'; 290, line_continuation:\; 291, call; 291, 292; 291, 301; 292, attribute; 292, 293; 292, 300; 293, subscript; 293, 294; 293, 299; 294, subscript; 294, 295; 294, 298; 295, subscript; 295, 296; 295, 297; 296, identifier:config; 297, string:'handlers'; 298, identifier:hdlr; 299, string:'filename'; 300, identifier:replace; 301, argument_list; 301, 302; 301, 303; 302, string:"%(logdir)s"; 303, identifier:log_dir; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 313; 305, 314; 306, subscript; 306, 307; 306, 312; 307, subscript; 307, 308; 307, 311; 308, subscript; 308, 309; 308, 310; 309, identifier:config; 310, string:'handlers'; 311, identifier:hdlr; 312, string:'filename'; 313, line_continuation:\; 314, call; 314, 315; 314, 324; 315, attribute; 315, 316; 315, 323; 316, subscript; 316, 317; 316, 322; 317, subscript; 317, 318; 317, 321; 318, subscript; 318, 319; 318, 320; 319, identifier:config; 320, string:'handlers'; 321, identifier:hdlr; 322, string:'filename'; 323, identifier:replace; 324, argument_list; 324, 325; 324, 326; 325, string:"%(daemon)s"; 326, identifier:process_name; 327, if_statement; 327, 328; 327, 344; 328, boolean_operator:and; 328, 329; 328, 330; 329, identifier:truncate; 330, call; 330, 331; 330, 336; 331, attribute; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:os; 334, identifier:path; 335, identifier:exists; 336, argument_list; 336, 337; 337, subscript; 337, 338; 337, 343; 338, subscript; 338, 339; 338, 342; 339, subscript; 339, 340; 339, 341; 340, identifier:config; 341, string:'handlers'; 342, identifier:hdlr; 343, string:'filename'; 344, block; 344, 345; 345, with_statement; 345, 346; 345, 362; 346, with_clause; 346, 347; 347, with_item; 347, 348; 348, as_pattern; 348, 349; 348, 360; 349, call; 349, 350; 349, 351; 350, identifier:open; 351, argument_list; 351, 352; 351, 359; 352, subscript; 352, 353; 352, 358; 353, subscript; 353, 354; 353, 357; 354, subscript; 354, 355; 354, 356; 355, identifier:config; 356, string:'handlers'; 357, identifier:hdlr; 358, string:'filename'; 359, string:"w"; 360, as_pattern_target; 360, 361; 361, identifier:file_log_file; 362, block; 362, 363; 363, expression_statement; 363, 364; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:file_log_file; 367, identifier:truncate; 368, argument_list; 369, comment; 370, expression_statement; 370, 371; 371, call; 371, 372; 371, 373; 372, identifier:logger_dictConfig; 373, argument_list; 373, 374; 374, identifier:config | def setup_logger(logger_configuration_file, log_dir=None, process_name='', log_file=''):
# pylint: disable=too-many-branches
"""
Configure the provided logger
- get and update the content of the Json configuration file
- configure the logger with this file
If a log_dir and process_name are provided, the format and filename in the configuration file
are updated with the provided values if they contain the patterns %(logdir)s and %(daemon)s
If no log_dir and process_name are provided, this function will truncate the log file
defined in the configuration file.
If a log file name is provided, it will override the default defined log file name.
At first, this function checks if the logger is still existing and initialized to
update the handlers and formatters. This mainly happens during the unit tests.
:param logger_configuration_file: Python Json logger configuration file
:rtype logger_configuration_file: str
:param log_dir: default log directory to update the defined logging handlers
:rtype log_dir: str
:param process_name: process name to update the defined logging formatters
:rtype process_name: str
:param log_file: log file name to update the defined log file
:rtype log_file: str
:return: None
"""
logger_ = logging.getLogger(ALIGNAK_LOGGER_NAME)
for handler in logger_.handlers:
if not process_name:
break
# Logger is already configured?
if getattr(handler, '_name', None) == 'daemons':
# Update the declared formats and file names with the process name
# This is for unit tests purpose only: alignak_tests will be replaced
# with the provided process name
for hdlr in logger_.handlers:
# print("- handler : %s (%s)" % (hdlr, hdlr.formatter._fmt))
if 'alignak_tests' in hdlr.formatter._fmt:
formatter = logging.Formatter(hdlr.formatter._fmt.replace("alignak_tests",
process_name))
hdlr.setFormatter(formatter)
if getattr(hdlr, 'filename', None) and 'alignak_tests' in hdlr.filename:
hdlr.filename = hdlr.filename._fmt.replace("alignak_tests", process_name)
# print("- handler : %s (%s) -> %s" % (hdlr, hdlr.formatter._fmt,
# hdlr.filename))
# else:
# print("- handler : %s (%s)" % (hdlr, hdlr.formatter._fmt))
break
else:
if not logger_configuration_file or not os.path.exists(logger_configuration_file):
print("The logger configuration file does not exist: %s" % logger_configuration_file)
return
with open(logger_configuration_file, 'rt') as _file:
config = json.load(_file)
truncate = False
if not process_name and not log_dir:
truncate = True
if not process_name:
process_name = 'alignak_tests'
if not log_dir:
log_dir = '/tmp'
# Update the declared formats with the process name
for formatter in config['formatters']:
if 'format' not in config['formatters'][formatter]:
continue
config['formatters'][formatter]['format'] = \
config['formatters'][formatter]['format'].replace("%(daemon)s", process_name)
# Update the declared log file names with the log directory
for hdlr in config['handlers']:
if 'filename' not in config['handlers'][hdlr]:
continue
if log_file and hdlr == 'daemons':
config['handlers'][hdlr]['filename'] = log_file
else:
config['handlers'][hdlr]['filename'] = \
config['handlers'][hdlr]['filename'].replace("%(logdir)s", log_dir)
config['handlers'][hdlr]['filename'] = \
config['handlers'][hdlr]['filename'].replace("%(daemon)s", process_name)
if truncate and os.path.exists(config['handlers'][hdlr]['filename']):
with open(config['handlers'][hdlr]['filename'], "w") as file_log_file:
file_log_file.truncate()
# Configure the logger, any error will raise an exception
logger_dictConfig(config) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:want_service_notification; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:notifways; 6, identifier:timeperiods; 7, identifier:timestamp; 8, identifier:state; 9, identifier:n_type; 10, identifier:business_impact; 11, default_parameter; 11, 12; 11, 13; 12, identifier:cmd; 13, None; 14, block; 14, 15; 14, 17; 14, 25; 14, 26; 14, 53; 14, 59; 14, 60; 14, 61; 14, 92; 14, 93; 15, expression_statement; 15, 16; 16, comment; 17, if_statement; 17, 18; 17, 22; 18, not_operator; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:service_notifications_enabled; 22, block; 22, 23; 23, return_statement; 23, 24; 24, False; 25, comment; 26, for_statement; 26, 27; 26, 28; 26, 31; 27, identifier:downtime_id; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:downtimes; 31, block; 31, 32; 31, 40; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:downtime; 35, subscript; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:downtimes; 39, identifier:downtime_id; 40, if_statement; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:downtime; 43, identifier:is_in_effect; 44, block; 44, 45; 44, 51; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:in_scheduled_downtime; 50, True; 51, return_statement; 51, 52; 52, False; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:in_scheduled_downtime; 58, False; 59, comment; 60, comment; 61, for_statement; 61, 62; 61, 63; 61, 66; 62, identifier:notifway_id; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:notificationways; 66, block; 66, 67; 66, 73; 66, 87; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:notifway; 70, subscript; 70, 71; 70, 72; 71, identifier:notifways; 72, identifier:notifway_id; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:nw_b; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:notifway; 79, identifier:want_service_notification; 80, argument_list; 80, 81; 80, 82; 80, 83; 80, 84; 80, 85; 80, 86; 81, identifier:timeperiods; 82, identifier:timestamp; 83, identifier:state; 84, identifier:n_type; 85, identifier:business_impact; 86, identifier:cmd; 87, if_statement; 87, 88; 87, 89; 88, identifier:nw_b; 89, block; 89, 90; 90, return_statement; 90, 91; 91, True; 92, comment; 93, return_statement; 93, 94; 94, False | def want_service_notification(self, notifways, timeperiods,
timestamp, state, n_type, business_impact, cmd=None):
"""Check if notification options match the state of the service
:param timestamp: time we want to notify the contact (usually now)
:type timestamp: int
:param state: host or service state ("WARNING", "CRITICAL" ..)
:type state: str
:param n_type: type of notification ("PROBLEM", "RECOVERY" ..)
:type n_type: str
:param business_impact: impact of this service
:type business_impact: int
:param cmd: command launched to notify the contact
:type cmd: str
:return: True if contact wants notification, otherwise False
:rtype: bool
"""
if not self.service_notifications_enabled:
return False
# If we are in downtime, we do not want notification
for downtime_id in self.downtimes:
downtime = self.downtimes[downtime_id]
if downtime.is_in_effect:
self.in_scheduled_downtime = True
return False
self.in_scheduled_downtime = False
# Now the rest is for sub notificationways. If one is OK, we are ok
# We will filter in another phase
for notifway_id in self.notificationways:
notifway = notifways[notifway_id]
nw_b = notifway.want_service_notification(timeperiods, timestamp,
state, n_type, business_impact, cmd)
if nw_b:
return True
# Oh... no one is ok for it? so no, sorry
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:explode; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:contactgroups; 6, identifier:notificationways; 7, block; 7, 8; 7, 10; 7, 11; 7, 18; 7, 19; 7, 20; 7, 39; 7, 40; 7, 80; 7, 81; 7, 82; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:apply_partial_inheritance; 16, argument_list; 16, 17; 17, string:'contactgroups'; 18, comment; 19, comment; 20, for_statement; 20, 21; 20, 22; 20, 25; 21, identifier:prop; 22, attribute; 22, 23; 22, 24; 23, identifier:Contact; 24, identifier:special_properties; 25, block; 25, 26; 25, 32; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:==; 27, 28; 27, 29; 28, identifier:prop; 29, string:'contact_name'; 30, block; 30, 31; 31, continue_statement; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:apply_partial_inheritance; 37, argument_list; 37, 38; 38, identifier:prop; 39, comment; 40, for_statement; 40, 41; 40, 42; 40, 43; 41, identifier:contact; 42, identifier:self; 43, block; 43, 44; 43, 60; 44, if_statement; 44, 45; 44, 58; 45, not_operator; 45, 46; 46, parenthesized_expression; 46, 47; 47, boolean_operator:and; 47, 48; 47, 53; 48, call; 48, 49; 48, 50; 49, identifier:hasattr; 50, argument_list; 50, 51; 50, 52; 51, identifier:contact; 52, string:'contact_name'; 53, call; 53, 54; 53, 55; 54, identifier:hasattr; 55, argument_list; 55, 56; 55, 57; 56, identifier:contact; 57, string:'contactgroups'; 58, block; 58, 59; 59, continue_statement; 60, for_statement; 60, 61; 60, 62; 60, 65; 61, identifier:contactgroup; 62, attribute; 62, 63; 62, 64; 63, identifier:contact; 64, identifier:contactgroups; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:contactgroups; 70, identifier:add_member; 71, argument_list; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:contact; 74, identifier:contact_name; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:contactgroup; 78, identifier:strip; 79, argument_list; 80, comment; 81, comment; 82, for_statement; 82, 83; 82, 84; 82, 85; 83, identifier:contact; 84, identifier:self; 85, block; 85, 86; 85, 90; 85, 94; 85, 145; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:need_notificationway; 89, False; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:params; 93, dictionary; 94, for_statement; 94, 95; 94, 96; 94, 99; 95, identifier:param; 96, attribute; 96, 97; 96, 98; 97, identifier:Contact; 98, identifier:simple_way_parameters; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 106; 100, 121; 101, call; 101, 102; 101, 103; 102, identifier:hasattr; 103, argument_list; 103, 104; 103, 105; 104, identifier:contact; 105, identifier:param; 106, block; 106, 107; 106, 111; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:need_notificationway; 110, True; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:params; 115, identifier:param; 116, call; 116, 117; 116, 118; 117, identifier:getattr; 118, argument_list; 118, 119; 118, 120; 119, identifier:contact; 120, identifier:param; 121, elif_clause; 121, 122; 121, 129; 121, 130; 121, 131; 122, attribute; 122, 123; 122, 128; 123, subscript; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:contact; 126, identifier:properties; 127, identifier:param; 128, identifier:has_default; 129, comment; 130, comment; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 135; 134, identifier:setattr; 135, argument_list; 135, 136; 135, 137; 135, 138; 136, identifier:contact; 137, identifier:param; 138, attribute; 138, 139; 138, 144; 139, subscript; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:contact; 142, identifier:properties; 143, identifier:param; 144, identifier:default; 145, if_statement; 145, 146; 145, 147; 146, identifier:need_notificationway; 147, block; 147, 148; 147, 162; 147, 168; 147, 176; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:cname; 151, call; 151, 152; 151, 153; 152, identifier:getattr; 153, argument_list; 153, 154; 153, 155; 153, 156; 154, identifier:contact; 155, string:'contact_name'; 156, call; 156, 157; 156, 158; 157, identifier:getattr; 158, argument_list; 158, 159; 158, 160; 158, 161; 159, identifier:contact; 160, string:'alias'; 161, string:''; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:nw_name; 165, binary_operator:+; 165, 166; 165, 167; 166, identifier:cname; 167, string:'_inner_nw'; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:notificationways; 172, identifier:new_inner_member; 173, argument_list; 173, 174; 173, 175; 174, identifier:nw_name; 175, identifier:params; 176, if_statement; 176, 177; 176, 183; 176, 191; 177, not_operator; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:hasattr; 180, argument_list; 180, 181; 180, 182; 181, identifier:contact; 182, string:'notificationways'; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:contact; 188, identifier:notificationways; 189, list:[nw_name]; 189, 190; 190, identifier:nw_name; 191, else_clause; 191, 192; 192, block; 192, 193; 192, 204; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:contact; 197, identifier:notificationways; 198, call; 198, 199; 198, 200; 199, identifier:list; 200, argument_list; 200, 201; 201, attribute; 201, 202; 201, 203; 202, identifier:contact; 203, identifier:notificationways; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 211; 206, attribute; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:contact; 209, identifier:notificationways; 210, identifier:append; 211, argument_list; 211, 212; 212, identifier:nw_name | def explode(self, contactgroups, notificationways):
"""Explode all contact for each contactsgroup
:param contactgroups: contactgroups to explode
:type contactgroups: alignak.objects.contactgroup.Contactgroups
:param notificationways: notificationways to explode
:type notificationways: alignak.objects.notificationway.Notificationways
:return: None
"""
# Contactgroups property need to be fulfill for got the information
self.apply_partial_inheritance('contactgroups')
# _special properties maybe came from a template, so
# import them before grok ourselves
for prop in Contact.special_properties:
if prop == 'contact_name':
continue
self.apply_partial_inheritance(prop)
# Register ourselves into the contactsgroups we are in
for contact in self:
if not (hasattr(contact, 'contact_name') and hasattr(contact, 'contactgroups')):
continue
for contactgroup in contact.contactgroups:
contactgroups.add_member(contact.contact_name, contactgroup.strip())
# Now create a notification way with the simple parameter of the
# contacts
for contact in self:
need_notificationway = False
params = {}
for param in Contact.simple_way_parameters:
if hasattr(contact, param):
need_notificationway = True
params[param] = getattr(contact, param)
elif contact.properties[param].has_default: # put a default text value
# Remove the value and put a default value
setattr(contact, param, contact.properties[param].default)
if need_notificationway:
cname = getattr(contact, 'contact_name', getattr(contact, 'alias', ''))
nw_name = cname + '_inner_nw'
notificationways.new_inner_member(nw_name, params)
if not hasattr(contact, 'notificationways'):
contact.notificationways = [nw_name]
else:
contact.notificationways = list(contact.notificationways)
contact.notificationways.append(nw_name) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:receive; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:arg_formats; 7, None; 8, block; 8, 9; 8, 11; 8, 12; 8, 13; 8, 18; 8, 22; 8, 26; 8, 30; 8, 166; 8, 167; 8, 186; 8, 187; 8, 230; 8, 231; 8, 244; 8, 245; 8, 259; 8, 303; 8, 304; 8, 308; 8, 357; 8, 358; 8, 372; 8, 408; 8, 412; 8, 441; 8, 442; 8, 450; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:msg; 16, list:[[]]; 16, 17; 17, list:[]; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:raw_msg; 21, list:[]; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:escaped; 25, False; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:command_sep_found; 29, False; 30, while_statement; 30, 31; 30, 32; 31, True; 32, block; 32, 33; 32, 43; 32, 50; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:tmp; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:board; 41, identifier:read; 42, argument_list; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:raw_msg; 47, identifier:append; 48, argument_list; 48, 49; 49, identifier:tmp; 50, if_statement; 50, 51; 50, 52; 50, 53; 50, 54; 50, 104; 51, identifier:escaped; 52, comment; 53, comment; 54, block; 54, 55; 55, if_statement; 55, 56; 55, 61; 55, 76; 56, comparison_operator:in; 56, 57; 56, 58; 57, identifier:tmp; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_escaped_characters; 61, block; 61, 62; 61, 72; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 70; 64, attribute; 64, 65; 64, 69; 65, subscript; 65, 66; 65, 67; 66, identifier:msg; 67, unary_operator:-; 67, 68; 68, integer:1; 69, identifier:append; 70, argument_list; 70, 71; 71, identifier:tmp; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:escaped; 75, False; 76, else_clause; 76, 77; 77, block; 77, 78; 77, 90; 77, 100; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 86; 80, attribute; 80, 81; 80, 85; 81, subscript; 81, 82; 81, 83; 82, identifier:msg; 83, unary_operator:-; 83, 84; 84, integer:1; 85, identifier:append; 86, argument_list; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_byte_escape_sep; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 98; 92, attribute; 92, 93; 92, 97; 93, subscript; 93, 94; 93, 95; 94, identifier:msg; 95, unary_operator:-; 95, 96; 96, integer:1; 97, identifier:append; 98, argument_list; 98, 99; 99, identifier:tmp; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:escaped; 103, False; 104, else_clause; 104, 105; 104, 106; 105, comment; 106, block; 106, 107; 107, if_statement; 107, 108; 107, 113; 107, 118; 107, 119; 107, 133; 107, 134; 107, 146; 107, 147; 107, 153; 107, 154; 108, comparison_operator:==; 108, 109; 108, 110; 109, identifier:tmp; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:_byte_escape_sep; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:escaped; 117, True; 118, comment; 119, elif_clause; 119, 120; 119, 125; 120, comparison_operator:==; 120, 121; 120, 122; 121, identifier:tmp; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_byte_field_sep; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:msg; 130, identifier:append; 131, argument_list; 131, 132; 132, list:[]; 133, comment; 134, elif_clause; 134, 135; 134, 140; 135, comparison_operator:==; 135, 136; 135, 137; 136, identifier:tmp; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:_byte_command_sep; 140, block; 140, 141; 140, 145; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:command_sep_found; 144, True; 145, break_statement; 146, comment; 147, elif_clause; 147, 148; 147, 151; 148, comparison_operator:==; 148, 149; 148, 150; 149, identifier:tmp; 150, string:b''; 151, block; 151, 152; 152, break_statement; 153, comment; 154, else_clause; 154, 155; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 164; 158, attribute; 158, 159; 158, 163; 159, subscript; 159, 160; 159, 161; 160, identifier:msg; 161, unary_operator:-; 161, 162; 162, integer:1; 163, identifier:append; 164, argument_list; 164, 165; 165, identifier:tmp; 166, comment; 167, if_statement; 167, 168; 167, 183; 168, boolean_operator:and; 168, 169; 168, 175; 169, comparison_operator:==; 169, 170; 169, 174; 170, call; 170, 171; 170, 172; 171, identifier:len; 172, argument_list; 172, 173; 173, identifier:msg; 174, integer:1; 175, comparison_operator:==; 175, 176; 175, 182; 176, call; 176, 177; 176, 178; 177, identifier:len; 178, argument_list; 178, 179; 179, subscript; 179, 180; 179, 181; 180, identifier:msg; 181, integer:0; 182, integer:0; 183, block; 183, 184; 184, return_statement; 184, 185; 185, None; 186, comment; 187, if_statement; 187, 188; 187, 190; 187, 191; 188, not_operator; 188, 189; 189, identifier:command_sep_found; 190, comment; 191, block; 191, 192; 191, 201; 191, 212; 191, 225; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:joined_raw; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, string:b''; 198, identifier:join; 199, argument_list; 199, 200; 200, identifier:raw_msg; 201, if_statement; 201, 202; 201, 209; 202, comparison_operator:==; 202, 203; 202, 208; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:joined_raw; 206, identifier:strip; 207, argument_list; 208, string:b''; 209, block; 209, 210; 210, return_statement; 210, 211; 211, None; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:err; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, string:"Incomplete message ({})"; 218, identifier:format; 219, argument_list; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:joined_raw; 223, identifier:decode; 224, argument_list; 225, raise_statement; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:EOFError; 228, argument_list; 228, 229; 229, identifier:err; 230, comment; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:fields; 234, list_comprehension; 234, 235; 234, 241; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, string:b''; 238, identifier:join; 239, argument_list; 239, 240; 240, identifier:m; 241, for_in_clause; 241, 242; 241, 243; 242, identifier:m; 243, identifier:msg; 244, comment; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:cmd; 248, call; 248, 249; 248, 258; 249, attribute; 249, 250; 249, 257; 250, call; 250, 251; 250, 256; 251, attribute; 251, 252; 251, 255; 252, subscript; 252, 253; 252, 254; 253, identifier:fields; 254, integer:0; 255, identifier:strip; 256, argument_list; 257, identifier:decode; 258, argument_list; 259, try_statement; 259, 260; 259, 272; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:cmd_name; 264, subscript; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:_int_to_cmd_name; 268, call; 268, 269; 268, 270; 269, identifier:int; 270, argument_list; 270, 271; 271, identifier:cmd; 272, except_clause; 272, 273; 272, 276; 273, tuple; 273, 274; 273, 275; 274, identifier:ValueError; 275, identifier:IndexError; 276, block; 276, 277; 277, if_statement; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:give_warnings; 281, block; 281, 282; 281, 286; 281, 295; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:cmd_name; 285, string:"unknown"; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:w; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, string:"Recieved unrecognized command ({})."; 292, identifier:format; 293, argument_list; 293, 294; 294, identifier:cmd; 295, expression_statement; 295, 296; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:warnings; 299, identifier:warn; 300, argument_list; 300, 301; 300, 302; 301, identifier:w; 302, identifier:Warning; 303, comment; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:arg_format_list; 307, list:[]; 308, if_statement; 308, 309; 308, 312; 308, 313; 308, 321; 309, comparison_operator:!=; 309, 310; 309, 311; 310, identifier:arg_formats; 311, None; 312, comment; 313, block; 313, 314; 314, expression_statement; 314, 315; 315, assignment; 315, 316; 315, 317; 316, identifier:arg_format_list; 317, call; 317, 318; 317, 319; 318, identifier:list; 319, argument_list; 319, 320; 320, identifier:arg_formats; 321, else_clause; 321, 322; 322, block; 322, 323; 323, try_statement; 323, 324; 323, 325; 323, 326; 323, 335; 324, comment; 325, comment; 326, block; 326, 327; 327, expression_statement; 327, 328; 328, assignment; 328, 329; 328, 330; 329, identifier:arg_format_list; 330, subscript; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:_cmd_name_to_format; 334, identifier:cmd_name; 335, except_clause; 335, 336; 335, 337; 335, 338; 336, identifier:KeyError; 337, comment; 338, block; 338, 339; 339, expression_statement; 339, 340; 340, assignment; 340, 341; 340, 342; 341, identifier:arg_format_list; 342, list_comprehension; 342, 343; 342, 344; 343, string:"g"; 344, for_in_clause; 344, 345; 344, 346; 345, identifier:i; 346, call; 346, 347; 346, 348; 347, identifier:range; 348, argument_list; 348, 349; 349, call; 349, 350; 349, 351; 350, identifier:len; 351, argument_list; 351, 352; 352, subscript; 352, 353; 352, 354; 353, identifier:fields; 354, slice; 354, 355; 354, 356; 355, integer:1; 356, colon; 357, comment; 358, expression_statement; 358, 359; 359, assignment; 359, 360; 359, 361; 360, identifier:arg_format_list; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:self; 364, identifier:_treat_star_format; 365, argument_list; 365, 366; 365, 367; 366, identifier:arg_format_list; 367, subscript; 367, 368; 367, 369; 368, identifier:fields; 369, slice; 369, 370; 369, 371; 370, integer:1; 371, colon; 372, if_statement; 372, 373; 372, 383; 373, comparison_operator:>; 373, 374; 373, 382; 374, call; 374, 375; 374, 376; 375, identifier:len; 376, argument_list; 376, 377; 377, subscript; 377, 378; 377, 379; 378, identifier:fields; 379, slice; 379, 380; 379, 381; 380, integer:1; 381, colon; 382, integer:0; 383, block; 383, 384; 384, if_statement; 384, 385; 384, 398; 385, comparison_operator:!=; 385, 386; 385, 390; 386, call; 386, 387; 386, 388; 387, identifier:len; 388, argument_list; 388, 389; 389, identifier:arg_format_list; 390, call; 390, 391; 390, 392; 391, identifier:len; 392, argument_list; 392, 393; 393, subscript; 393, 394; 393, 395; 394, identifier:fields; 395, slice; 395, 396; 395, 397; 396, integer:1; 397, colon; 398, block; 398, 399; 398, 403; 399, expression_statement; 399, 400; 400, assignment; 400, 401; 400, 402; 401, identifier:err; 402, string:"Number of argument formats must match the number of recieved arguments."; 403, raise_statement; 403, 404; 404, call; 404, 405; 404, 406; 405, identifier:ValueError; 406, argument_list; 406, 407; 407, identifier:err; 408, expression_statement; 408, 409; 409, assignment; 409, 410; 409, 411; 410, identifier:received; 411, list:[]; 412, for_statement; 412, 413; 412, 416; 412, 424; 413, pattern_list; 413, 414; 413, 415; 414, identifier:i; 415, identifier:f; 416, call; 416, 417; 416, 418; 417, identifier:enumerate; 418, argument_list; 418, 419; 419, subscript; 419, 420; 419, 421; 420, identifier:fields; 421, slice; 421, 422; 421, 423; 422, integer:1; 423, colon; 424, block; 424, 425; 425, expression_statement; 425, 426; 426, call; 426, 427; 426, 430; 427, attribute; 427, 428; 427, 429; 428, identifier:received; 429, identifier:append; 430, argument_list; 430, 431; 431, call; 431, 432; 431, 439; 432, subscript; 432, 433; 432, 436; 433, attribute; 433, 434; 433, 435; 434, identifier:self; 435, identifier:_recv_methods; 436, subscript; 436, 437; 436, 438; 437, identifier:arg_format_list; 438, identifier:i; 439, argument_list; 439, 440; 440, identifier:f; 441, comment; 442, expression_statement; 442, 443; 443, assignment; 443, 444; 443, 445; 444, identifier:message_time; 445, call; 445, 446; 445, 449; 446, attribute; 446, 447; 446, 448; 447, identifier:time; 448, identifier:time; 449, argument_list; 450, return_statement; 450, 451; 451, expression_list; 451, 452; 451, 453; 451, 454; 452, identifier:cmd_name; 453, identifier:received; 454, identifier:message_time | def receive(self,arg_formats=None):
"""
Recieve commands coming off the serial port.
arg_formats is an optimal keyword that specifies the formats to use to
parse incoming arguments. If specified here, arg_formats supercedes
the formats specified on initialization.
"""
# Read serial input until a command separator or empty character is
# reached
msg = [[]]
raw_msg = []
escaped = False
command_sep_found = False
while True:
tmp = self.board.read()
raw_msg.append(tmp)
if escaped:
# Either drop the escape character or, if this wasn't really
# an escape, keep previous escape character and new character
if tmp in self._escaped_characters:
msg[-1].append(tmp)
escaped = False
else:
msg[-1].append(self._byte_escape_sep)
msg[-1].append(tmp)
escaped = False
else:
# look for escape character
if tmp == self._byte_escape_sep:
escaped = True
# or field separator
elif tmp == self._byte_field_sep:
msg.append([])
# or command separator
elif tmp == self._byte_command_sep:
command_sep_found = True
break
# or any empty characater
elif tmp == b'':
break
# okay, must be something
else:
msg[-1].append(tmp)
# No message received given timeouts
if len(msg) == 1 and len(msg[0]) == 0:
return None
# Make sure the message terminated properly
if not command_sep_found:
# empty message (likely from line endings being included)
joined_raw = b''.join(raw_msg)
if joined_raw.strip() == b'':
return None
err = "Incomplete message ({})".format(joined_raw.decode())
raise EOFError(err)
# Turn message into fields
fields = [b''.join(m) for m in msg]
# Get the command name.
cmd = fields[0].strip().decode()
try:
cmd_name = self._int_to_cmd_name[int(cmd)]
except (ValueError,IndexError):
if self.give_warnings:
cmd_name = "unknown"
w = "Recieved unrecognized command ({}).".format(cmd)
warnings.warn(w,Warning)
# Figure out what formats to use for each argument.
arg_format_list = []
if arg_formats != None:
# The user specified formats
arg_format_list = list(arg_formats)
else:
try:
# See if class was initialized with a format for arguments to this
# command
arg_format_list = self._cmd_name_to_format[cmd_name]
except KeyError:
# if not, guess for all arguments
arg_format_list = ["g" for i in range(len(fields[1:]))]
# Deal with "*" format
arg_format_list = self._treat_star_format(arg_format_list,fields[1:])
if len(fields[1:]) > 0:
if len(arg_format_list) != len(fields[1:]):
err = "Number of argument formats must match the number of recieved arguments."
raise ValueError(err)
received = []
for i, f in enumerate(fields[1:]):
received.append(self._recv_methods[arg_format_list[i]](f))
# Record the time the message arrived
message_time = time.time()
return cmd_name, received, message_time |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:update_share; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:share_id; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 21; 8, 31; 8, 41; 8, 60; 8, 74; 8, 84; 8, 88; 8, 97; 8, 112; 8, 138; 8, 159; 8, 168; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:perms; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:kwargs; 17, identifier:get; 18, argument_list; 18, 19; 18, 20; 19, string:'perms'; 20, None; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:password; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:kwargs; 27, identifier:get; 28, argument_list; 28, 29; 28, 30; 29, string:'password'; 30, None; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:public_upload; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:kwargs; 37, identifier:get; 38, argument_list; 38, 39; 38, 40; 39, string:'public_upload'; 40, None; 41, if_statement; 41, 42; 41, 55; 42, boolean_operator:and; 42, 43; 42, 49; 43, parenthesized_expression; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:isinstance; 46, argument_list; 46, 47; 46, 48; 47, identifier:perms; 48, identifier:int; 49, parenthesized_expression; 49, 50; 50, comparison_operator:>; 50, 51; 50, 52; 51, identifier:perms; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:OCS_PERMISSION_ALL; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:perms; 59, None; 60, if_statement; 60, 61; 60, 71; 61, not_operator; 61, 62; 62, parenthesized_expression; 62, 63; 63, boolean_operator:or; 63, 64; 63, 67; 64, boolean_operator:or; 64, 65; 64, 66; 65, identifier:perms; 66, identifier:password; 67, parenthesized_expression; 67, 68; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:public_upload; 70, None; 71, block; 71, 72; 72, return_statement; 72, 73; 73, False; 74, if_statement; 74, 75; 74, 81; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:isinstance; 78, argument_list; 78, 79; 78, 80; 79, identifier:share_id; 80, identifier:int; 81, block; 81, 82; 82, return_statement; 82, 83; 83, False; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:data; 87, dictionary; 88, if_statement; 88, 89; 88, 90; 89, identifier:perms; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:data; 95, string:'permissions'; 96, identifier:perms; 97, if_statement; 97, 98; 97, 105; 98, call; 98, 99; 98, 100; 99, identifier:isinstance; 100, argument_list; 100, 101; 100, 102; 101, identifier:password; 102, attribute; 102, 103; 102, 104; 103, identifier:six; 104, identifier:string_types; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, subscript; 108, 109; 108, 110; 109, identifier:data; 110, string:'password'; 111, identifier:password; 112, if_statement; 112, 113; 112, 124; 113, boolean_operator:and; 113, 114; 113, 118; 114, parenthesized_expression; 114, 115; 115, comparison_operator:is; 115, 116; 115, 117; 116, identifier:public_upload; 117, None; 118, parenthesized_expression; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:isinstance; 121, argument_list; 121, 122; 121, 123; 122, identifier:public_upload; 123, identifier:bool; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 130; 127, subscript; 127, 128; 127, 129; 128, identifier:data; 129, string:'publicUpload'; 130, call; 130, 131; 130, 137; 131, attribute; 131, 132; 131, 136; 132, call; 132, 133; 132, 134; 133, identifier:str; 134, argument_list; 134, 135; 135, identifier:public_upload; 136, identifier:lower; 137, argument_list; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:res; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:_make_ocs_request; 145, argument_list; 145, 146; 145, 147; 145, 150; 145, 156; 146, string:'PUT'; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:OCS_SERVICE_SHARE; 150, binary_operator:+; 150, 151; 150, 152; 151, string:'shares/'; 152, call; 152, 153; 152, 154; 153, identifier:str; 154, argument_list; 154, 155; 155, identifier:share_id; 156, keyword_argument; 156, 157; 156, 158; 157, identifier:data; 158, identifier:data; 159, if_statement; 159, 160; 159, 165; 160, comparison_operator:==; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:res; 163, identifier:status_code; 164, integer:200; 165, block; 165, 166; 166, return_statement; 166, 167; 167, True; 168, raise_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:HTTPResponseError; 171, argument_list; 171, 172; 172, identifier:res | def update_share(self, share_id, **kwargs):
"""Updates a given share
:param share_id: (int) Share ID
:param perms: (int) update permissions (see share_file_with_user() below)
:param password: (string) updated password for public link Share
:param public_upload: (boolean) enable/disable public upload for public shares
:returns: True if the operation succeeded, False otherwise
:raises: HTTPResponseError in case an HTTP error status was returned
"""
perms = kwargs.get('perms', None)
password = kwargs.get('password', None)
public_upload = kwargs.get('public_upload', None)
if (isinstance(perms, int)) and (perms > self.OCS_PERMISSION_ALL):
perms = None
if not (perms or password or (public_upload is not None)):
return False
if not isinstance(share_id, int):
return False
data = {}
if perms:
data['permissions'] = perms
if isinstance(password, six.string_types):
data['password'] = password
if (public_upload is not None) and (isinstance(public_upload, bool)):
data['publicUpload'] = str(public_upload).lower()
res = self._make_ocs_request(
'PUT',
self.OCS_SERVICE_SHARE,
'shares/' + str(share_id),
data=data
)
if res.status_code == 200:
return True
raise HTTPResponseError(res) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:get_shares; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:path; 7, string:''; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kwargs; 10, block; 10, 11; 10, 13; 10, 26; 10, 30; 10, 155; 10, 168; 10, 227; 11, expression_statement; 11, 12; 12, comment; 13, if_statement; 13, 14; 13, 23; 14, not_operator; 14, 15; 15, parenthesized_expression; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:isinstance; 18, argument_list; 18, 19; 18, 20; 19, identifier:path; 20, attribute; 20, 21; 20, 22; 21, identifier:six; 22, identifier:string_types; 23, block; 23, 24; 24, return_statement; 24, 25; 25, None; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:data; 29, string:'shares'; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:!=; 31, 32; 31, 33; 32, identifier:path; 33, string:''; 34, block; 34, 35; 34, 39; 34, 53; 34, 60; 34, 70; 34, 85; 34, 95; 34, 117; 34, 127; 34, 146; 35, expression_statement; 35, 36; 36, augmented_assignment:+=; 36, 37; 36, 38; 37, identifier:data; 38, string:'?'; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:path; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_encode_string; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_normalize_path; 51, argument_list; 51, 52; 52, identifier:path; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:args; 56, dictionary; 56, 57; 57, pair; 57, 58; 57, 59; 58, string:'path'; 59, identifier:path; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:reshares; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:kwargs; 66, identifier:get; 67, argument_list; 67, 68; 67, 69; 68, string:'reshares'; 69, False; 70, if_statement; 70, 71; 70, 78; 71, boolean_operator:and; 71, 72; 71, 77; 72, call; 72, 73; 72, 74; 73, identifier:isinstance; 74, argument_list; 74, 75; 74, 76; 75, identifier:reshares; 76, identifier:bool; 77, identifier:reshares; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, subscript; 81, 82; 81, 83; 82, identifier:args; 83, string:'reshares'; 84, identifier:reshares; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:subfiles; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:kwargs; 91, identifier:get; 92, argument_list; 92, 93; 92, 94; 93, string:'subfiles'; 94, False; 95, if_statement; 95, 96; 95, 103; 96, boolean_operator:and; 96, 97; 96, 102; 97, call; 97, 98; 97, 99; 98, identifier:isinstance; 99, argument_list; 99, 100; 99, 101; 100, identifier:subfiles; 101, identifier:bool; 102, identifier:subfiles; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:args; 108, string:'subfiles'; 109, call; 109, 110; 109, 116; 110, attribute; 110, 111; 110, 115; 111, call; 111, 112; 111, 113; 112, identifier:str; 113, argument_list; 113, 114; 114, identifier:subfiles; 115, identifier:lower; 116, argument_list; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:shared_with_me; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:kwargs; 123, identifier:get; 124, argument_list; 124, 125; 124, 126; 125, string:'shared_with_me'; 126, False; 127, if_statement; 127, 128; 127, 135; 128, boolean_operator:and; 128, 129; 128, 134; 129, call; 129, 130; 129, 131; 130, identifier:isinstance; 131, argument_list; 131, 132; 131, 133; 132, identifier:shared_with_me; 133, identifier:bool; 134, identifier:shared_with_me; 135, block; 135, 136; 135, 142; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:args; 140, string:'shared_with_me'; 141, string:"true"; 142, delete_statement; 142, 143; 143, subscript; 143, 144; 143, 145; 144, identifier:args; 145, string:'path'; 146, expression_statement; 146, 147; 147, augmented_assignment:+=; 147, 148; 147, 149; 148, identifier:data; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:parse; 152, identifier:urlencode; 153, argument_list; 153, 154; 154, identifier:args; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:res; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:_make_ocs_request; 162, argument_list; 162, 163; 162, 164; 162, 167; 163, string:'GET'; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:OCS_SERVICE_SHARE; 167, identifier:data; 168, if_statement; 168, 169; 168, 174; 169, comparison_operator:==; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:res; 172, identifier:status_code; 173, integer:200; 174, block; 174, 175; 174, 186; 174, 193; 174, 197; 174, 225; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:tree; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:ET; 181, identifier:fromstring; 182, argument_list; 182, 183; 183, attribute; 183, 184; 183, 185; 184, identifier:res; 185, identifier:content; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:_check_ocs_status; 191, argument_list; 191, 192; 192, identifier:tree; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:shares; 196, list:[]; 197, for_statement; 197, 198; 197, 199; 197, 210; 198, identifier:element; 199, call; 199, 200; 199, 208; 200, attribute; 200, 201; 200, 207; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:tree; 204, identifier:find; 205, argument_list; 205, 206; 206, string:'data'; 207, identifier:iter; 208, argument_list; 208, 209; 209, string:'element'; 210, block; 210, 211; 210, 213; 211, expression_statement; 211, 212; 212, string:'''share_attr = {}
for child in element:
key = child.tag
value = child.text
share_attr[key] = value
shares.append(share_attr)'''; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:shares; 217, identifier:append; 218, argument_list; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:_get_shareinfo; 223, argument_list; 223, 224; 224, identifier:element; 225, return_statement; 225, 226; 226, identifier:shares; 227, raise_statement; 227, 228; 228, call; 228, 229; 228, 230; 229, identifier:HTTPResponseError; 230, argument_list; 230, 231; 231, identifier:res | def get_shares(self, path='', **kwargs):
"""Returns array of shares
:param path: path to the share to be checked
:param reshares: (optional, boolean) returns not only the shares from
the current user but all shares from the given file (default: False)
:param subfiles: (optional, boolean) returns all shares within
a folder, given that path defines a folder (default: False)
:param shared_with_me: (optional, boolean) returns all shares which are
shared with me (default: False)
:returns: array of shares ShareInfo instances or empty array if the operation failed
:raises: HTTPResponseError in case an HTTP error status was returned
"""
if not (isinstance(path, six.string_types)):
return None
data = 'shares'
if path != '':
data += '?'
path = self._encode_string(self._normalize_path(path))
args = {'path': path}
reshares = kwargs.get('reshares', False)
if isinstance(reshares, bool) and reshares:
args['reshares'] = reshares
subfiles = kwargs.get('subfiles', False)
if isinstance(subfiles, bool) and subfiles:
args['subfiles'] = str(subfiles).lower()
shared_with_me = kwargs.get('shared_with_me', False)
if isinstance(shared_with_me, bool) and shared_with_me:
args['shared_with_me'] = "true"
del args['path']
data += parse.urlencode(args)
res = self._make_ocs_request(
'GET',
self.OCS_SERVICE_SHARE,
data
)
if res.status_code == 200:
tree = ET.fromstring(res.content)
self._check_ocs_status(tree)
shares = []
for element in tree.find('data').iter('element'):
'''share_attr = {}
for child in element:
key = child.tag
value = child.text
share_attr[key] = value
shares.append(share_attr)'''
shares.append(self._get_shareinfo(element))
return shares
raise HTTPResponseError(res) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:share_file_with_user; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:path; 6, identifier:user; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 22; 9, 34; 9, 70; 9, 88; 9, 97; 9, 125; 9, 141; 9, 160; 9, 215; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:remote_user; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:kwargs; 18, identifier:get; 19, argument_list; 19, 20; 19, 21; 20, string:'remote_user'; 21, False; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:perms; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:kwargs; 28, identifier:get; 29, argument_list; 29, 30; 29, 31; 30, string:'perms'; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:OCS_PERMISSION_READ; 34, if_statement; 34, 35; 34, 67; 35, parenthesized_expression; 35, 36; 36, boolean_operator:or; 36, 37; 36, 52; 37, parenthesized_expression; 37, 38; 38, boolean_operator:or; 38, 39; 38, 46; 39, parenthesized_expression; 39, 40; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 43; 42, identifier:isinstance; 43, argument_list; 43, 44; 43, 45; 44, identifier:perms; 45, identifier:int; 46, parenthesized_expression; 46, 47; 47, comparison_operator:>; 47, 48; 47, 49; 48, identifier:perms; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:OCS_PERMISSION_ALL; 52, parenthesized_expression; 52, 53; 53, boolean_operator:or; 53, 54; 53, 63; 54, parenthesized_expression; 54, 55; 55, not_operator; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:isinstance; 58, argument_list; 58, 59; 58, 60; 59, identifier:user; 60, attribute; 60, 61; 60, 62; 61, identifier:six; 62, identifier:string_types; 63, parenthesized_expression; 63, 64; 64, comparison_operator:==; 64, 65; 64, 66; 65, identifier:user; 66, string:''; 67, block; 67, 68; 68, return_statement; 68, 69; 69, False; 70, if_statement; 70, 71; 70, 81; 71, boolean_operator:and; 71, 72; 71, 73; 72, identifier:remote_user; 73, parenthesized_expression; 73, 74; 74, not_operator; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:user; 78, identifier:endswith; 79, argument_list; 79, 80; 80, string:'/'; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:user; 85, binary_operator:+; 85, 86; 85, 87; 86, identifier:user; 87, string:'/'; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:path; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:_normalize_path; 95, argument_list; 95, 96; 96, identifier:path; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:post_data; 100, dictionary; 100, 101; 100, 111; 100, 114; 100, 122; 101, pair; 101, 102; 101, 103; 102, string:'shareType'; 103, conditional_expression:if; 103, 104; 103, 107; 103, 108; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:OCS_SHARE_TYPE_REMOTE; 107, identifier:remote_user; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:OCS_SHARE_TYPE_USER; 111, pair; 111, 112; 111, 113; 112, string:'shareWith'; 113, identifier:user; 114, pair; 114, 115; 114, 116; 115, string:'path'; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:_encode_string; 120, argument_list; 120, 121; 121, identifier:path; 122, pair; 122, 123; 122, 124; 123, string:'permissions'; 124, identifier:perms; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:res; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:_make_ocs_request; 132, argument_list; 132, 133; 132, 134; 132, 137; 132, 138; 133, string:'POST'; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:OCS_SERVICE_SHARE; 137, string:'shares'; 138, keyword_argument; 138, 139; 138, 140; 139, identifier:data; 140, identifier:post_data; 141, if_statement; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:_debug; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 149; 148, identifier:print; 149, argument_list; 149, 150; 150, binary_operator:%; 150, 151; 150, 154; 151, concatenated_string; 151, 152; 151, 153; 152, string:'OCS share_file request for file %s with permissions %i '; 153, string:'returned: %i'; 154, tuple; 154, 155; 154, 156; 154, 157; 155, identifier:path; 156, identifier:perms; 157, attribute; 157, 158; 157, 159; 158, identifier:res; 159, identifier:status_code; 160, if_statement; 160, 161; 160, 166; 161, comparison_operator:==; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:res; 164, identifier:status_code; 165, integer:200; 166, block; 166, 167; 166, 178; 166, 185; 166, 194; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:tree; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:ET; 173, identifier:fromstring; 174, argument_list; 174, 175; 175, attribute; 175, 176; 175, 177; 176, identifier:res; 177, identifier:content; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:_check_ocs_status; 183, argument_list; 183, 184; 184, identifier:tree; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:data_el; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:tree; 191, identifier:find; 192, argument_list; 192, 193; 193, string:'data'; 194, return_statement; 194, 195; 195, call; 195, 196; 195, 197; 196, identifier:ShareInfo; 197, argument_list; 197, 198; 198, dictionary; 198, 199; 198, 209; 198, 212; 199, pair; 199, 200; 199, 201; 200, string:'id'; 201, attribute; 201, 202; 201, 208; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:data_el; 205, identifier:find; 206, argument_list; 206, 207; 207, string:'id'; 208, identifier:text; 209, pair; 209, 210; 209, 211; 210, string:'path'; 211, identifier:path; 212, pair; 212, 213; 212, 214; 213, string:'permissions'; 214, identifier:perms; 215, raise_statement; 215, 216; 216, call; 216, 217; 216, 218; 217, identifier:HTTPResponseError; 218, argument_list; 218, 219; 219, identifier:res | def share_file_with_user(self, path, user, **kwargs):
"""Shares a remote file with specified user
:param path: path to the remote file to share
:param user: name of the user whom we want to share a file/folder
:param perms (optional): permissions of the shared object
defaults to read only (1)
http://doc.owncloud.org/server/6.0/admin_manual/sharing_api/index.html
:param remote_user (optional): True if it is a federated users
defaults to False if it is a local user
:returns: instance of :class:`ShareInfo` with the share info
or False if the operation failed
:raises: HTTPResponseError in case an HTTP error status was returned
"""
remote_user = kwargs.get('remote_user', False)
perms = kwargs.get('perms', self.OCS_PERMISSION_READ)
if (((not isinstance(perms, int)) or (perms > self.OCS_PERMISSION_ALL))
or ((not isinstance(user, six.string_types)) or (user == ''))):
return False
if remote_user and (not user.endswith('/')):
user = user + '/'
path = self._normalize_path(path)
post_data = {
'shareType': self.OCS_SHARE_TYPE_REMOTE if remote_user else
self.OCS_SHARE_TYPE_USER,
'shareWith': user,
'path': self._encode_string(path),
'permissions': perms
}
res = self._make_ocs_request(
'POST',
self.OCS_SERVICE_SHARE,
'shares',
data=post_data
)
if self._debug:
print('OCS share_file request for file %s with permissions %i '
'returned: %i' % (path, perms, res.status_code))
if res.status_code == 200:
tree = ET.fromstring(res.content)
self._check_ocs_status(tree)
data_el = tree.find('data')
return ShareInfo(
{
'id': data_el.find('id').text,
'path': path,
'permissions': perms
}
)
raise HTTPResponseError(res) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:get_attribute; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:app; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:key; 10, None; 11, block; 11, 12; 11, 14; 11, 18; 11, 57; 11, 70; 11, 199; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:path; 17, string:'getattribute'; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:is; 19, 20; 19, 21; 20, identifier:app; 21, None; 22, block; 22, 23; 22, 35; 23, expression_statement; 23, 24; 24, augmented_assignment:+=; 24, 25; 24, 26; 25, identifier:path; 26, binary_operator:+; 26, 27; 26, 28; 27, string:'/'; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:parse; 31, identifier:quote; 32, argument_list; 32, 33; 32, 34; 33, identifier:app; 34, string:''; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:key; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, augmented_assignment:+=; 41, 42; 41, 43; 42, identifier:path; 43, binary_operator:+; 43, 44; 43, 45; 44, string:'/'; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:parse; 48, identifier:quote; 49, argument_list; 49, 50; 49, 56; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_encode_string; 54, argument_list; 54, 55; 55, identifier:key; 56, string:''; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:res; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_make_ocs_request; 64, argument_list; 64, 65; 64, 66; 64, 69; 65, string:'GET'; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:OCS_SERVICE_PRIVATEDATA; 69, identifier:path; 70, if_statement; 70, 71; 70, 76; 71, comparison_operator:==; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:res; 74, identifier:status_code; 75, integer:200; 76, block; 76, 77; 76, 88; 76, 95; 76, 99; 76, 183; 76, 197; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:tree; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:ET; 83, identifier:fromstring; 84, argument_list; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:res; 87, identifier:content; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:_check_ocs_status; 93, argument_list; 93, 94; 94, identifier:tree; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:values; 98, list:[]; 99, for_statement; 99, 100; 99, 101; 99, 112; 100, identifier:element; 101, call; 101, 102; 101, 110; 102, attribute; 102, 103; 102, 109; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:tree; 106, identifier:find; 107, argument_list; 107, 108; 108, string:'data'; 109, identifier:iter; 110, argument_list; 110, 111; 111, string:'element'; 112, block; 112, 113; 112, 124; 112, 135; 112, 148; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:app_text; 116, attribute; 116, 117; 116, 123; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:element; 120, identifier:find; 121, argument_list; 121, 122; 122, string:'app'; 123, identifier:text; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:key_text; 127, attribute; 127, 128; 127, 134; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:element; 131, identifier:find; 132, argument_list; 132, 133; 133, string:'key'; 134, identifier:text; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:value_text; 138, boolean_operator:or; 138, 139; 138, 147; 139, attribute; 139, 140; 139, 146; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:element; 143, identifier:find; 144, argument_list; 144, 145; 145, string:'value'; 146, identifier:text; 147, string:''; 148, if_statement; 148, 149; 148, 152; 148, 179; 149, comparison_operator:is; 149, 150; 149, 151; 150, identifier:key; 151, None; 152, block; 152, 153; 153, if_statement; 153, 154; 153, 157; 153, 168; 154, comparison_operator:is; 154, 155; 154, 156; 155, identifier:app; 156, None; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:values; 162, identifier:append; 163, argument_list; 163, 164; 164, tuple; 164, 165; 164, 166; 164, 167; 165, identifier:app_text; 166, identifier:key_text; 167, identifier:value_text; 168, else_clause; 168, 169; 169, block; 169, 170; 170, expression_statement; 170, 171; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:values; 174, identifier:append; 175, argument_list; 175, 176; 176, tuple; 176, 177; 176, 178; 177, identifier:key_text; 178, identifier:value_text; 179, else_clause; 179, 180; 180, block; 180, 181; 181, return_statement; 181, 182; 182, identifier:value_text; 183, if_statement; 183, 184; 183, 194; 184, boolean_operator:and; 184, 185; 184, 191; 185, comparison_operator:==; 185, 186; 185, 190; 186, call; 186, 187; 186, 188; 187, identifier:len; 188, argument_list; 188, 189; 189, identifier:values; 190, integer:0; 191, comparison_operator:is; 191, 192; 191, 193; 192, identifier:key; 193, None; 194, block; 194, 195; 195, return_statement; 195, 196; 196, None; 197, return_statement; 197, 198; 198, identifier:values; 199, raise_statement; 199, 200; 200, call; 200, 201; 200, 202; 201, identifier:HTTPResponseError; 202, argument_list; 202, 203; 203, identifier:res | def get_attribute(self, app=None, key=None):
"""Returns an application attribute
:param app: application id
:param key: attribute key or None to retrieve all values for the
given application
:returns: attribute value if key was specified, or an array of tuples
(key, value) for each attribute
:raises: HTTPResponseError in case an HTTP error status was returned
"""
path = 'getattribute'
if app is not None:
path += '/' + parse.quote(app, '')
if key is not None:
path += '/' + parse.quote(self._encode_string(key), '')
res = self._make_ocs_request(
'GET',
self.OCS_SERVICE_PRIVATEDATA,
path
)
if res.status_code == 200:
tree = ET.fromstring(res.content)
self._check_ocs_status(tree)
values = []
for element in tree.find('data').iter('element'):
app_text = element.find('app').text
key_text = element.find('key').text
value_text = element.find('value').text or ''
if key is None:
if app is None:
values.append((app_text, key_text, value_text))
else:
values.append((key_text, value_text))
else:
return value_text
if len(values) == 0 and key is not None:
return None
return values
raise HTTPResponseError(res) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_make_dav_request; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:method; 6, identifier:path; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 45; 9, 54; 9, 82; 9, 96; 9, 112; 9, 123; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_debug; 16, block; 16, 17; 16, 26; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:print; 20, argument_list; 20, 21; 21, binary_operator:%; 21, 22; 21, 23; 22, string:'DAV request: %s %s'; 23, tuple; 23, 24; 23, 25; 24, identifier:method; 25, identifier:path; 26, if_statement; 26, 27; 26, 33; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:kwargs; 30, identifier:get; 31, argument_list; 31, 32; 32, string:'headers'; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:print; 37, argument_list; 37, 38; 37, 39; 38, string:'Headers: '; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:kwargs; 42, identifier:get; 43, argument_list; 43, 44; 44, string:'headers'; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:path; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_normalize_path; 52, argument_list; 52, 53; 53, identifier:path; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:res; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_session; 62, identifier:request; 63, argument_list; 63, 64; 63, 65; 63, 80; 64, identifier:method; 65, binary_operator:+; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_webdav_url; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:parse; 72, identifier:quote; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:_encode_string; 78, argument_list; 78, 79; 79, identifier:path; 80, dictionary_splat; 80, 81; 81, identifier:kwargs; 82, if_statement; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:_debug; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 90; 89, identifier:print; 90, argument_list; 90, 91; 91, binary_operator:%; 91, 92; 91, 93; 92, string:'DAV status: %i'; 93, attribute; 93, 94; 93, 95; 94, identifier:res; 95, identifier:status_code; 96, if_statement; 96, 97; 96, 104; 97, comparison_operator:in; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:res; 100, identifier:status_code; 101, list:[200, 207]; 101, 102; 101, 103; 102, integer:200; 103, integer:207; 104, block; 104, 105; 105, return_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:_parse_dav_response; 110, argument_list; 110, 111; 111, identifier:res; 112, if_statement; 112, 113; 112, 120; 113, comparison_operator:in; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:res; 116, identifier:status_code; 117, list:[204, 201]; 117, 118; 117, 119; 118, integer:204; 119, integer:201; 120, block; 120, 121; 121, return_statement; 121, 122; 122, True; 123, raise_statement; 123, 124; 124, call; 124, 125; 124, 126; 125, identifier:HTTPResponseError; 126, argument_list; 126, 127; 127, identifier:res | def _make_dav_request(self, method, path, **kwargs):
"""Makes a WebDAV request
:param method: HTTP method
:param path: remote path of the targetted file
:param \*\*kwargs: optional arguments that ``requests.Request.request`` accepts
:returns array of :class:`FileInfo` if the response
contains it, or True if the operation succeded, False
if it didn't
"""
if self._debug:
print('DAV request: %s %s' % (method, path))
if kwargs.get('headers'):
print('Headers: ', kwargs.get('headers'))
path = self._normalize_path(path)
res = self._session.request(
method,
self._webdav_url + parse.quote(self._encode_string(path)),
**kwargs
)
if self._debug:
print('DAV status: %i' % res.status_code)
if res.status_code in [200, 207]:
return self._parse_dav_response(res)
if res.status_code in [204, 201]:
return True
raise HTTPResponseError(res) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:load_delimited; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:filename; 5, identifier:converters; 6, default_parameter; 6, 7; 6, 8; 7, identifier:delimiter; 8, string:r'\s+'; 9, block; 9, 10; 9, 12; 9, 13; 9, 20; 9, 35; 9, 36; 9, 45; 9, 46; 9, 47; 9, 48; 9, 49; 9, 50; 9, 51; 9, 169; 9, 170; 10, expression_statement; 10, 11; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:n_columns; 16, call; 16, 17; 16, 18; 17, identifier:len; 18, argument_list; 18, 19; 19, identifier:converters; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:columns; 23, call; 23, 24; 23, 25; 24, identifier:tuple; 25, generator_expression; 25, 26; 25, 29; 26, call; 26, 27; 26, 28; 27, identifier:list; 28, argument_list; 29, for_in_clause; 29, 30; 29, 31; 30, identifier:_; 31, call; 31, 32; 31, 33; 32, identifier:range; 33, argument_list; 33, 34; 34, identifier:n_columns; 35, comment; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:splitter; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:re; 42, identifier:compile; 43, argument_list; 43, 44; 44, identifier:delimiter; 45, comment; 46, comment; 47, comment; 48, comment; 49, comment; 50, comment; 51, with_statement; 51, 52; 51, 64; 52, with_clause; 52, 53; 53, with_item; 53, 54; 54, as_pattern; 54, 55; 54, 62; 55, call; 55, 56; 55, 57; 56, identifier:_open; 57, argument_list; 57, 58; 57, 59; 58, identifier:filename; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:mode; 61, string:'r'; 62, as_pattern_target; 62, 63; 63, identifier:input_file; 64, block; 64, 65; 65, for_statement; 65, 66; 65, 69; 65, 74; 65, 75; 66, pattern_list; 66, 67; 66, 68; 67, identifier:row; 68, identifier:line; 69, call; 69, 70; 69, 71; 70, identifier:enumerate; 71, argument_list; 71, 72; 71, 73; 72, identifier:input_file; 73, integer:1; 74, comment; 75, block; 75, 76; 75, 92; 75, 93; 75, 120; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:data; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:splitter; 82, identifier:split; 83, argument_list; 83, 84; 83, 89; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:line; 87, identifier:strip; 88, argument_list; 89, binary_operator:-; 89, 90; 89, 91; 90, identifier:n_columns; 91, integer:1; 92, comment; 93, if_statement; 93, 94; 93, 100; 94, comparison_operator:!=; 94, 95; 94, 96; 95, identifier:n_columns; 96, call; 96, 97; 96, 98; 97, identifier:len; 98, argument_list; 98, 99; 99, identifier:data; 100, block; 100, 101; 101, raise_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:ValueError; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, concatenated_string; 107, 108; 107, 109; 108, string:'Expected {} columns, got {} at '; 109, string:'{}:{:d}:\n\t{}'; 110, identifier:format; 111, argument_list; 111, 112; 111, 113; 111, 117; 111, 118; 111, 119; 112, identifier:n_columns; 113, call; 113, 114; 113, 115; 114, identifier:len; 115, argument_list; 115, 116; 116, identifier:data; 117, identifier:filename; 118, identifier:row; 119, identifier:line; 120, for_statement; 120, 121; 120, 125; 120, 131; 120, 132; 121, pattern_list; 121, 122; 121, 123; 121, 124; 122, identifier:value; 123, identifier:column; 124, identifier:converter; 125, call; 125, 126; 125, 127; 126, identifier:zip; 127, argument_list; 127, 128; 127, 129; 127, 130; 128, identifier:data; 129, identifier:columns; 130, identifier:converters; 131, comment; 132, block; 132, 133; 132, 162; 133, try_statement; 133, 134; 133, 142; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:converted_value; 138, call; 138, 139; 138, 140; 139, identifier:converter; 140, argument_list; 140, 141; 141, identifier:value; 142, except_clause; 142, 143; 143, block; 143, 144; 144, raise_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:ValueError; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, concatenated_string; 150, 151; 150, 152; 151, string:"Couldn't convert value {} using {} "; 152, string:"found at {}:{:d}:\n\t{}"; 153, identifier:format; 154, argument_list; 154, 155; 154, 156; 154, 159; 154, 160; 154, 161; 155, identifier:value; 156, attribute; 156, 157; 156, 158; 157, identifier:converter; 158, identifier:__name__; 159, identifier:filename; 160, identifier:row; 161, identifier:line; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:column; 166, identifier:append; 167, argument_list; 167, 168; 168, identifier:converted_value; 169, comment; 170, if_statement; 170, 171; 170, 174; 170, 179; 171, comparison_operator:==; 171, 172; 171, 173; 172, identifier:n_columns; 173, integer:1; 174, block; 174, 175; 175, return_statement; 175, 176; 176, subscript; 176, 177; 176, 178; 177, identifier:columns; 178, integer:0; 179, else_clause; 179, 180; 180, block; 180, 181; 181, return_statement; 181, 182; 182, identifier:columns | def load_delimited(filename, converters, delimiter=r'\s+'):
r"""Utility function for loading in data from an annotation file where columns
are delimited. The number of columns is inferred from the length of
the provided converters list.
Examples
--------
>>> # Load in a one-column list of event times (floats)
>>> load_delimited('events.txt', [float])
>>> # Load in a list of labeled events, separated by commas
>>> load_delimited('labeled_events.csv', [float, str], ',')
Parameters
----------
filename : str
Path to the annotation file
converters : list of functions
Each entry in column ``n`` of the file will be cast by the function
``converters[n]``.
delimiter : str
Separator regular expression.
By default, lines will be split by any amount of whitespace.
Returns
-------
columns : tuple of lists
Each list in this tuple corresponds to values in one of the columns
in the file.
"""
# Initialize list of empty lists
n_columns = len(converters)
columns = tuple(list() for _ in range(n_columns))
# Create re object for splitting lines
splitter = re.compile(delimiter)
# Note: we do io manually here for two reasons.
# 1. The csv module has difficulties with unicode, which may lead
# to failures on certain annotation strings
#
# 2. numpy's text loader does not handle non-numeric data
#
with _open(filename, mode='r') as input_file:
for row, line in enumerate(input_file, 1):
# Split each line using the supplied delimiter
data = splitter.split(line.strip(), n_columns - 1)
# Throw a helpful error if we got an unexpected # of columns
if n_columns != len(data):
raise ValueError('Expected {} columns, got {} at '
'{}:{:d}:\n\t{}'.format(n_columns, len(data),
filename, row, line))
for value, column, converter in zip(data, columns, converters):
# Try converting the value, throw a helpful error on failure
try:
converted_value = converter(value)
except:
raise ValueError("Couldn't convert value {} using {} "
"found at {}:{:d}:\n\t{}".format(
value, converter.__name__, filename,
row, line))
column.append(converted_value)
# Sane output
if n_columns == 1:
return columns[0]
else:
return columns |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:validate; 3, parameters; 3, 4; 3, 5; 4, identifier:reference_patterns; 5, identifier:estimated_patterns; 6, block; 6, 7; 6, 9; 6, 10; 6, 25; 6, 40; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, if_statement; 10, 11; 10, 17; 11, comparison_operator:==; 11, 12; 11, 16; 12, call; 12, 13; 12, 14; 13, identifier:_n_onset_midi; 14, argument_list; 14, 15; 15, identifier:reference_patterns; 16, integer:0; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:warnings; 22, identifier:warn; 23, argument_list; 23, 24; 24, string:'Reference patterns are empty.'; 25, if_statement; 25, 26; 25, 32; 26, comparison_operator:==; 26, 27; 26, 31; 27, call; 27, 28; 27, 29; 28, identifier:_n_onset_midi; 29, argument_list; 29, 30; 30, identifier:estimated_patterns; 31, integer:0; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:warnings; 37, identifier:warn; 38, argument_list; 38, 39; 39, string:'Estimated patterns are empty.'; 40, for_statement; 40, 41; 40, 42; 40, 45; 41, identifier:patterns; 42, list:[reference_patterns, estimated_patterns]; 42, 43; 42, 44; 43, identifier:reference_patterns; 44, identifier:estimated_patterns; 45, block; 45, 46; 46, for_statement; 46, 47; 46, 48; 46, 49; 47, identifier:pattern; 48, identifier:patterns; 49, block; 49, 50; 49, 65; 50, if_statement; 50, 51; 50, 57; 51, comparison_operator:<=; 51, 52; 51, 56; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:pattern; 56, integer:0; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:ValueError; 61, argument_list; 61, 62; 62, concatenated_string; 62, 63; 62, 64; 63, string:"Each pattern must contain at least one "; 64, string:"occurrence."; 65, for_statement; 65, 66; 65, 67; 65, 68; 66, identifier:occurrence; 67, identifier:pattern; 68, block; 68, 69; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:onset_midi; 71, identifier:occurrence; 72, block; 72, 73; 73, if_statement; 73, 74; 73, 80; 74, comparison_operator:!=; 74, 75; 74, 79; 75, call; 75, 76; 75, 77; 76, identifier:len; 77, argument_list; 77, 78; 78, identifier:onset_midi; 79, integer:2; 80, block; 80, 81; 81, raise_statement; 81, 82; 82, call; 82, 83; 82, 84; 83, identifier:ValueError; 84, argument_list; 84, 85; 85, concatenated_string; 85, 86; 85, 87; 86, string:"The (onset, midi) tuple must "; 87, string:"contain exactly 2 elements." | def validate(reference_patterns, estimated_patterns):
"""Checks that the input annotations to a metric look like valid pattern
lists, and throws helpful errors if not.
Parameters
----------
reference_patterns : list
The reference patterns using the format returned by
:func:`mir_eval.io.load_patterns()`
estimated_patterns : list
The estimated patterns in the same format
Returns
-------
"""
# Warn if pattern lists are empty
if _n_onset_midi(reference_patterns) == 0:
warnings.warn('Reference patterns are empty.')
if _n_onset_midi(estimated_patterns) == 0:
warnings.warn('Estimated patterns are empty.')
for patterns in [reference_patterns, estimated_patterns]:
for pattern in patterns:
if len(pattern) <= 0:
raise ValueError("Each pattern must contain at least one "
"occurrence.")
for occurrence in pattern:
for onset_midi in occurrence:
if len(onset_midi) != 2:
raise ValueError("The (onset, midi) tuple must "
"contain exactly 2 elements.") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:three_layer_FPR; 3, parameters; 3, 4; 3, 5; 4, identifier:reference_patterns; 5, identifier:estimated_patterns; 6, block; 6, 7; 6, 9; 6, 15; 6, 64; 6, 120; 6, 237; 6, 238; 6, 259; 6, 260; 6, 271; 6, 272; 6, 289; 6, 306; 6, 316; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 12; 11, identifier:validate; 12, argument_list; 12, 13; 12, 14; 13, identifier:reference_patterns; 14, identifier:estimated_patterns; 15, function_definition; 15, 16; 15, 17; 15, 20; 16, function_name:compute_first_layer_PR; 17, parameters; 17, 18; 17, 19; 18, identifier:ref_occs; 19, identifier:est_occs; 20, block; 20, 21; 20, 23; 20, 24; 20, 35; 20, 36; 20, 48; 20, 60; 21, expression_statement; 21, 22; 22, comment; 23, comment; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:s; 27, call; 27, 28; 27, 29; 28, identifier:len; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:_occurrence_intersection; 32, argument_list; 32, 33; 32, 34; 33, identifier:ref_occs; 34, identifier:est_occs; 35, comment; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:precision; 39, binary_operator:/; 39, 40; 39, 41; 40, identifier:s; 41, call; 41, 42; 41, 43; 42, identifier:float; 43, argument_list; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:len; 46, argument_list; 46, 47; 47, identifier:ref_occs; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:recall; 51, binary_operator:/; 51, 52; 51, 53; 52, identifier:s; 53, call; 53, 54; 53, 55; 54, identifier:float; 55, argument_list; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, identifier:est_occs; 60, return_statement; 60, 61; 61, expression_list; 61, 62; 61, 63; 62, identifier:precision; 63, identifier:recall; 64, function_definition; 64, 65; 64, 66; 64, 69; 65, function_name:compute_second_layer_PR; 66, parameters; 66, 67; 66, 68; 67, identifier:ref_pattern; 68, identifier:est_pattern; 69, block; 69, 70; 69, 72; 69, 73; 69, 81; 69, 82; 69, 99; 69, 116; 70, expression_statement; 70, 71; 71, comment; 72, comment; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:F_1; 76, call; 76, 77; 76, 78; 77, identifier:compute_layer; 78, argument_list; 78, 79; 78, 80; 79, identifier:ref_pattern; 80, identifier:est_pattern; 81, comment; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:precision; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:np; 88, identifier:mean; 89, argument_list; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:max; 94, argument_list; 94, 95; 94, 96; 95, identifier:F_1; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:axis; 98, integer:0; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:recall; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:np; 105, identifier:mean; 106, argument_list; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:np; 110, identifier:max; 111, argument_list; 111, 112; 111, 113; 112, identifier:F_1; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:axis; 115, integer:1; 116, return_statement; 116, 117; 117, expression_list; 117, 118; 117, 119; 118, identifier:precision; 119, identifier:recall; 120, function_definition; 120, 121; 120, 122; 120, 128; 121, function_name:compute_layer; 122, parameters; 122, 123; 122, 124; 122, 125; 123, identifier:ref_elements; 124, identifier:est_elements; 125, default_parameter; 125, 126; 125, 127; 126, identifier:layer; 127, integer:1; 128, block; 128, 129; 128, 131; 128, 147; 128, 154; 128, 155; 128, 162; 128, 163; 128, 174; 128, 175; 128, 235; 129, expression_statement; 129, 130; 130, comment; 131, if_statement; 131, 132; 131, 139; 132, boolean_operator:and; 132, 133; 132, 136; 133, comparison_operator:!=; 133, 134; 133, 135; 134, identifier:layer; 135, integer:1; 136, comparison_operator:!=; 136, 137; 136, 138; 137, identifier:layer; 138, integer:2; 139, block; 139, 140; 140, raise_statement; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:ValueError; 143, argument_list; 143, 144; 144, binary_operator:%; 144, 145; 144, 146; 145, string:"Layer (%d) must be an integer between 1 and 2"; 146, identifier:layer; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:nP; 150, call; 150, 151; 150, 152; 151, identifier:len; 152, argument_list; 152, 153; 153, identifier:ref_elements; 154, comment; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:nQ; 158, call; 158, 159; 158, 160; 159, identifier:len; 160, argument_list; 160, 161; 161, identifier:est_elements; 162, comment; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:F; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:np; 169, identifier:zeros; 170, argument_list; 170, 171; 171, tuple; 171, 172; 171, 173; 172, identifier:nP; 173, identifier:nQ; 174, comment; 175, for_statement; 175, 176; 175, 177; 175, 181; 176, identifier:iP; 177, call; 177, 178; 177, 179; 178, identifier:range; 179, argument_list; 179, 180; 180, identifier:nP; 181, block; 181, 182; 182, for_statement; 182, 183; 182, 184; 182, 188; 183, identifier:iQ; 184, call; 184, 185; 184, 186; 185, identifier:range; 186, argument_list; 186, 187; 187, identifier:nQ; 188, block; 188, 189; 188, 207; 188, 208; 188, 222; 189, if_statement; 189, 190; 189, 193; 189, 198; 190, comparison_operator:==; 190, 191; 190, 192; 191, identifier:layer; 192, integer:1; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:func; 197, identifier:compute_first_layer_PR; 198, elif_clause; 198, 199; 198, 202; 199, comparison_operator:==; 199, 200; 199, 201; 200, identifier:layer; 201, integer:2; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:func; 206, identifier:compute_second_layer_PR; 207, comment; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 213; 210, pattern_list; 210, 211; 210, 212; 211, identifier:precision; 212, identifier:recall; 213, call; 213, 214; 213, 215; 214, identifier:func; 215, argument_list; 215, 216; 215, 219; 216, subscript; 216, 217; 216, 218; 217, identifier:ref_elements; 218, identifier:iP; 219, subscript; 219, 220; 219, 221; 220, identifier:est_elements; 221, identifier:iQ; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 228; 224, subscript; 224, 225; 224, 226; 224, 227; 225, identifier:F; 226, identifier:iP; 227, identifier:iQ; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:util; 231, identifier:f_measure; 232, argument_list; 232, 233; 232, 234; 233, identifier:precision; 234, identifier:recall; 235, return_statement; 235, 236; 236, identifier:F; 237, comment; 238, if_statement; 238, 239; 238, 253; 239, boolean_operator:or; 239, 240; 239, 246; 239, 247; 240, comparison_operator:==; 240, 241; 240, 245; 241, call; 241, 242; 241, 243; 242, identifier:_n_onset_midi; 243, argument_list; 243, 244; 244, identifier:reference_patterns; 245, integer:0; 246, line_continuation:\; 247, comparison_operator:==; 247, 248; 247, 252; 248, call; 248, 249; 248, 250; 249, identifier:_n_onset_midi; 250, argument_list; 250, 251; 251, identifier:estimated_patterns; 252, integer:0; 253, block; 253, 254; 254, return_statement; 254, 255; 255, expression_list; 255, 256; 255, 257; 255, 258; 256, float:0.; 257, float:0.; 258, float:0.; 259, comment; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:F_2; 263, call; 263, 264; 263, 265; 264, identifier:compute_layer; 265, argument_list; 265, 266; 265, 267; 265, 268; 266, identifier:reference_patterns; 267, identifier:estimated_patterns; 268, keyword_argument; 268, 269; 268, 270; 269, identifier:layer; 270, integer:2; 271, comment; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:precision_3; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:np; 278, identifier:mean; 279, argument_list; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:np; 283, identifier:max; 284, argument_list; 284, 285; 284, 286; 285, identifier:F_2; 286, keyword_argument; 286, 287; 286, 288; 287, identifier:axis; 288, integer:0; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:recall_3; 292, call; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:np; 295, identifier:mean; 296, argument_list; 296, 297; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:np; 300, identifier:max; 301, argument_list; 301, 302; 301, 303; 302, identifier:F_2; 303, keyword_argument; 303, 304; 303, 305; 304, identifier:axis; 305, integer:1; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:f_measure_3; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:util; 312, identifier:f_measure; 313, argument_list; 313, 314; 313, 315; 314, identifier:precision_3; 315, identifier:recall_3; 316, return_statement; 316, 317; 317, expression_list; 317, 318; 317, 319; 317, 320; 318, identifier:f_measure_3; 319, identifier:precision_3; 320, identifier:recall_3 | def three_layer_FPR(reference_patterns, estimated_patterns):
"""Three Layer F1 Score, Precision and Recall. As described by Meridith.
Examples
--------
>>> ref_patterns = mir_eval.io.load_patterns("ref_pattern.txt")
>>> est_patterns = mir_eval.io.load_patterns("est_pattern.txt")
>>> F, P, R = mir_eval.pattern.three_layer_FPR(ref_patterns,
... est_patterns)
Parameters
----------
reference_patterns : list
The reference patterns in the format returned by
:func:`mir_eval.io.load_patterns()`
estimated_patterns : list
The estimated patterns in the same format
Returns
-------
f_measure : float
The three-layer F1 Score
precision : float
The three-layer Precision
recall : float
The three-layer Recall
"""
validate(reference_patterns, estimated_patterns)
def compute_first_layer_PR(ref_occs, est_occs):
"""Computes the first layer Precision and Recall values given the
set of occurrences in the reference and the set of occurrences in the
estimation.
Parameters
----------
ref_occs :
est_occs :
Returns
-------
"""
# Find the length of the intersection between reference and estimation
s = len(_occurrence_intersection(ref_occs, est_occs))
# Compute the first layer scores
precision = s / float(len(ref_occs))
recall = s / float(len(est_occs))
return precision, recall
def compute_second_layer_PR(ref_pattern, est_pattern):
"""Computes the second layer Precision and Recall values given the
set of occurrences in the reference and the set of occurrences in the
estimation.
Parameters
----------
ref_pattern :
est_pattern :
Returns
-------
"""
# Compute the first layer scores
F_1 = compute_layer(ref_pattern, est_pattern)
# Compute the second layer scores
precision = np.mean(np.max(F_1, axis=0))
recall = np.mean(np.max(F_1, axis=1))
return precision, recall
def compute_layer(ref_elements, est_elements, layer=1):
"""Computes the F-measure matrix for a given layer. The reference and
estimated elements can be either patters or occurrences, depending
on the layer.
For layer 1, the elements must be occurrences.
For layer 2, the elements must be patterns.
Parameters
----------
ref_elements :
est_elements :
layer :
(Default value = 1)
Returns
-------
"""
if layer != 1 and layer != 2:
raise ValueError("Layer (%d) must be an integer between 1 and 2"
% layer)
nP = len(ref_elements) # Number of elements in reference
nQ = len(est_elements) # Number of elements in estimation
F = np.zeros((nP, nQ)) # F-measure matrix for the given layer
for iP in range(nP):
for iQ in range(nQ):
if layer == 1:
func = compute_first_layer_PR
elif layer == 2:
func = compute_second_layer_PR
# Compute layer scores
precision, recall = func(ref_elements[iP], est_elements[iQ])
F[iP, iQ] = util.f_measure(precision, recall)
return F
# If no patterns were provided, metric is zero
if _n_onset_midi(reference_patterns) == 0 or \
_n_onset_midi(estimated_patterns) == 0:
return 0., 0., 0.
# Compute the second layer (it includes the first layer)
F_2 = compute_layer(reference_patterns, estimated_patterns, layer=2)
# Compute the final scores (third layer)
precision_3 = np.mean(np.max(F_2, axis=0))
recall_3 = np.mean(np.max(F_2, axis=1))
f_measure_3 = util.f_measure(precision_3, recall_3)
return f_measure_3, precision_3, recall_3 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:match_notes; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 4, identifier:ref_intervals; 5, identifier:ref_pitches; 6, identifier:ref_velocities; 7, identifier:est_intervals; 8, identifier:est_pitches; 9, identifier:est_velocities; 10, default_parameter; 10, 11; 10, 12; 11, identifier:onset_tolerance; 12, float:0.05; 13, default_parameter; 13, 14; 13, 15; 14, identifier:pitch_tolerance; 15, float:50.0; 16, default_parameter; 16, 17; 16, 18; 17, identifier:offset_ratio; 18, float:0.2; 19, default_parameter; 19, 20; 19, 21; 20, identifier:offset_min_tolerance; 21, float:0.05; 22, default_parameter; 22, 23; 22, 24; 23, identifier:strict; 24, False; 25, default_parameter; 25, 26; 25, 27; 26, identifier:velocity_tolerance; 27, float:0.1; 28, block; 28, 29; 28, 31; 28, 32; 28, 49; 28, 50; 28, 68; 28, 69; 28, 79; 28, 91; 28, 92; 28, 101; 28, 102; 28, 111; 28, 112; 28, 122; 28, 132; 28, 133; 28, 134; 28, 167; 28, 168; 28, 176; 28, 177; 28, 178; 28, 189; 28, 190; 28, 197; 28, 198; 28, 204; 28, 205; 28, 216; 29, expression_statement; 29, 30; 30, comment; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:matching; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:transcription; 38, identifier:match_notes; 39, argument_list; 39, 40; 39, 41; 39, 42; 39, 43; 39, 44; 39, 45; 39, 46; 39, 47; 39, 48; 40, identifier:ref_intervals; 41, identifier:ref_pitches; 42, identifier:est_intervals; 43, identifier:est_pitches; 44, identifier:onset_tolerance; 45, identifier:pitch_tolerance; 46, identifier:offset_ratio; 47, identifier:offset_min_tolerance; 48, identifier:strict; 49, comment; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, pattern_list; 52, 53; 52, 54; 53, identifier:min_velocity; 54, identifier:max_velocity; 55, expression_list; 55, 56; 55, 62; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:np; 59, identifier:min; 60, argument_list; 60, 61; 61, identifier:ref_velocities; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:np; 65, identifier:max; 66, argument_list; 66, 67; 67, identifier:ref_velocities; 68, comment; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:velocity_range; 72, call; 72, 73; 72, 74; 73, identifier:max; 74, argument_list; 74, 75; 74, 76; 75, integer:1; 76, binary_operator:-; 76, 77; 76, 78; 77, identifier:max_velocity; 78, identifier:min_velocity; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:ref_velocities; 82, binary_operator:/; 82, 83; 82, 87; 83, parenthesized_expression; 83, 84; 84, binary_operator:-; 84, 85; 84, 86; 85, identifier:ref_velocities; 86, identifier:min_velocity; 87, call; 87, 88; 87, 89; 88, identifier:float; 89, argument_list; 89, 90; 90, identifier:velocity_range; 91, comment; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:matching; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:np; 98, identifier:array; 99, argument_list; 99, 100; 100, identifier:matching; 101, comment; 102, if_statement; 102, 103; 102, 108; 103, comparison_operator:==; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:matching; 106, identifier:size; 107, integer:0; 108, block; 108, 109; 109, return_statement; 109, 110; 110, list:[]; 111, comment; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:ref_matched_velocities; 115, subscript; 115, 116; 115, 117; 116, identifier:ref_velocities; 117, subscript; 117, 118; 117, 119; 117, 121; 118, identifier:matching; 119, slice; 119, 120; 120, colon; 121, integer:0; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:est_matched_velocities; 125, subscript; 125, 126; 125, 127; 126, identifier:est_velocities; 127, subscript; 127, 128; 127, 129; 127, 131; 128, identifier:matching; 129, slice; 129, 130; 130, colon; 131, integer:1; 132, comment; 133, comment; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, pattern_list; 136, 137; 136, 138; 137, identifier:slope; 138, identifier:intercept; 139, subscript; 139, 140; 139, 166; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:np; 144, identifier:linalg; 145, identifier:lstsq; 146, argument_list; 146, 147; 146, 165; 147, attribute; 147, 148; 147, 164; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:np; 151, identifier:vstack; 152, argument_list; 152, 153; 153, list:[est_matched_velocities,
np.ones(len(est_matched_velocities))]; 153, 154; 153, 155; 154, identifier:est_matched_velocities; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:np; 158, identifier:ones; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 162; 161, identifier:len; 162, argument_list; 162, 163; 163, identifier:est_matched_velocities; 164, identifier:T; 165, identifier:ref_matched_velocities; 166, integer:0; 167, comment; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:est_matched_velocities; 171, binary_operator:+; 171, 172; 171, 175; 172, binary_operator:*; 172, 173; 172, 174; 173, identifier:slope; 174, identifier:est_matched_velocities; 175, identifier:intercept; 176, comment; 177, comment; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:velocity_diff; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:np; 184, identifier:abs; 185, argument_list; 185, 186; 186, binary_operator:-; 186, 187; 186, 188; 187, identifier:est_matched_velocities; 188, identifier:ref_matched_velocities; 189, comment; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:velocity_within_tolerance; 193, parenthesized_expression; 193, 194; 194, comparison_operator:<; 194, 195; 194, 196; 195, identifier:velocity_diff; 196, identifier:velocity_tolerance; 197, comment; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:matching; 201, subscript; 201, 202; 201, 203; 202, identifier:matching; 203, identifier:velocity_within_tolerance; 204, comment; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:matching; 208, list_comprehension; 208, 209; 208, 213; 209, call; 209, 210; 209, 211; 210, identifier:tuple; 211, argument_list; 211, 212; 212, identifier:_; 213, for_in_clause; 213, 214; 213, 215; 214, identifier:_; 215, identifier:matching; 216, return_statement; 216, 217; 217, identifier:matching | def match_notes(
ref_intervals, ref_pitches, ref_velocities, est_intervals, est_pitches,
est_velocities, onset_tolerance=0.05, pitch_tolerance=50.0,
offset_ratio=0.2, offset_min_tolerance=0.05, strict=False,
velocity_tolerance=0.1):
"""Match notes, taking note velocity into consideration.
This function first calls :func:`mir_eval.transcription.match_notes` to
match notes according to the supplied intervals, pitches, onset, offset,
and pitch tolerances. The velocities of the matched notes are then used to
estimate a slope and intercept which can rescale the estimated velocities
so that they are as close as possible (in L2 sense) to their matched
reference velocities. Velocities are then normalized to the range [0, 1]. A
estimated note is then further only considered correct if its velocity is
within ``velocity_tolerance`` of its matched (according to pitch and
timing) reference note.
Parameters
----------
ref_intervals : np.ndarray, shape=(n,2)
Array of reference notes time intervals (onset and offset times)
ref_pitches : np.ndarray, shape=(n,)
Array of reference pitch values in Hertz
ref_velocities : np.ndarray, shape=(n,)
Array of MIDI velocities (i.e. between 0 and 127) of reference notes
est_intervals : np.ndarray, shape=(m,2)
Array of estimated notes time intervals (onset and offset times)
est_pitches : np.ndarray, shape=(m,)
Array of estimated pitch values in Hertz
est_velocities : np.ndarray, shape=(m,)
Array of MIDI velocities (i.e. between 0 and 127) of estimated notes
onset_tolerance : float > 0
The tolerance for an estimated note's onset deviating from the
reference note's onset, in seconds. Default is 0.05 (50 ms).
pitch_tolerance : float > 0
The tolerance for an estimated note's pitch deviating from the
reference note's pitch, in cents. Default is 50.0 (50 cents).
offset_ratio : float > 0 or None
The ratio of the reference note's duration used to define the
offset_tolerance. Default is 0.2 (20%), meaning the
``offset_tolerance`` will equal the ``ref_duration * 0.2``, or 0.05 (50
ms), whichever is greater. If ``offset_ratio`` is set to ``None``,
offsets are ignored in the matching.
offset_min_tolerance : float > 0
The minimum tolerance for offset matching. See offset_ratio description
for an explanation of how the offset tolerance is determined. Note:
this parameter only influences the results if ``offset_ratio`` is not
``None``.
strict : bool
If ``strict=False`` (the default), threshold checks for onset, offset,
and pitch matching are performed using ``<=`` (less than or equal). If
``strict=True``, the threshold checks are performed using ``<`` (less
than).
velocity_tolerance : float > 0
Estimated notes are considered correct if, after rescaling and
normalization to [0, 1], they are within ``velocity_tolerance`` of a
matched reference note.
Returns
-------
matching : list of tuples
A list of matched reference and estimated notes.
``matching[i] == (i, j)`` where reference note ``i`` matches estimated
note ``j``.
"""
# Compute note matching as usual using standard transcription function
matching = transcription.match_notes(
ref_intervals, ref_pitches, est_intervals, est_pitches,
onset_tolerance, pitch_tolerance, offset_ratio, offset_min_tolerance,
strict)
# Rescale reference velocities to the range [0, 1]
min_velocity, max_velocity = np.min(ref_velocities), np.max(ref_velocities)
# Make the smallest possible range 1 to avoid divide by zero
velocity_range = max(1, max_velocity - min_velocity)
ref_velocities = (ref_velocities - min_velocity)/float(velocity_range)
# Convert matching list-of-tuples to array for fancy indexing
matching = np.array(matching)
# When there is no matching, return an empty list
if matching.size == 0:
return []
# Grab velocities for matched notes
ref_matched_velocities = ref_velocities[matching[:, 0]]
est_matched_velocities = est_velocities[matching[:, 1]]
# Find slope and intercept of line which produces best least-squares fit
# between matched est and ref velocities
slope, intercept = np.linalg.lstsq(
np.vstack([est_matched_velocities,
np.ones(len(est_matched_velocities))]).T,
ref_matched_velocities)[0]
# Re-scale est velocities to match ref
est_matched_velocities = slope*est_matched_velocities + intercept
# Compute the absolute error of (rescaled) estimated velocities vs.
# normalized reference velocities. Error will be in [0, 1]
velocity_diff = np.abs(est_matched_velocities - ref_matched_velocities)
# Check whether each error is within the provided tolerance
velocity_within_tolerance = (velocity_diff < velocity_tolerance)
# Only keep matches whose velocity was within the provided tolerance
matching = matching[velocity_within_tolerance]
# Convert back to list-of-tuple format
matching = [tuple(_) for _ in matching]
return matching |
Subsets and Splits