sequence
stringlengths 492
15.9k
| code
stringlengths 75
8.58k
|
---|---|
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, 14; 8, 18; 8, 24; 8, 43; 8, 69; 8, 78; 8, 102; 8, 113; 8, 119; 8, 173; 9, assert_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:_status_fn; 13, string:"Asked to join a task which hasn't had any commands executed on it"; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:check_interval; 17, float:0.2; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:status_fn; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:_status_fn; 24, if_statement; 24, 25; 24, 35; 25, not_operator; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:wait_for_file; 30, argument_list; 30, 31; 30, 32; 31, identifier:status_fn; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:max_wait_sec; 34, integer:30; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:log; 41, argument_list; 41, 42; 42, string:f"Retrying waiting for {status_fn}"; 43, while_statement; 43, 44; 43, 51; 44, not_operator; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:exists; 49, argument_list; 49, 50; 50, identifier:status_fn; 51, block; 51, 52; 51, 59; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:log; 57, argument_list; 57, 58; 58, string:f"Still waiting for {self._cmd}"; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:wait_for_file; 64, argument_list; 64, 65; 64, 66; 65, identifier:status_fn; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:max_wait_sec; 68, integer:30; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:contents; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:read; 76, argument_list; 76, 77; 77, identifier:status_fn; 78, if_statement; 78, 79; 78, 85; 79, comparison_operator:==; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, identifier:contents; 84, integer:0; 85, block; 85, 86; 85, 93; 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, identifier:check_interval; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:contents; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:read; 100, argument_list; 100, 101; 101, identifier:status_fn; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:status; 105, call; 105, 106; 105, 107; 106, identifier:int; 107, argument_list; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:contents; 111, identifier:strip; 112, argument_list; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:last_status; 118, identifier:status; 119, if_statement; 119, 120; 119, 123; 120, comparison_operator:!=; 120, 121; 120, 122; 121, identifier:status; 122, integer:0; 123, block; 123, 124; 123, 131; 123, 155; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:extra_msg; 127, conditional_expression:if; 127, 128; 127, 129; 127, 130; 128, string:'(ignoring error)'; 129, identifier:ignore_errors; 130, string:'(failing)'; 131, if_statement; 131, 132; 131, 140; 132, boolean_operator:or; 132, 133; 132, 139; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:util; 136, identifier:is_set; 137, argument_list; 137, 138; 138, string:'NCLUSTER_RUN_WITH_OUTPUT_ON_FAILURE'; 139, True; 140, block; 140, 141; 140, 148; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:log; 146, argument_list; 146, 147; 147, string:f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'"; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:log; 153, argument_list; 153, 154; 154, string:f"\n{'*'*80}\nEnd failing output"; 155, if_statement; 155, 156; 155, 158; 155, 164; 156, not_operator; 156, 157; 157, identifier:ignore_errors; 158, block; 158, 159; 159, raise_statement; 159, 160; 160, call; 160, 161; 160, 162; 161, identifier:RuntimeError; 162, argument_list; 162, 163; 163, string:f"Command {self._cmd} returned status {status}"; 164, else_clause; 164, 165; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:log; 171, argument_list; 171, 172; 172, string:f"Warning: command {self._cmd} returned status {status}"; 173, return_statement; 173, 174; 174, identifier:status | def join(self, ignore_errors=False):
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 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, 34; 24, 42; 24, 50; 24, 158; 24, 179; 24, 189; 24, 233; 24, 244; 24, 270; 24, 281; 24, 287; 24, 331; 25, if_statement; 25, 26; 25, 30; 26, not_operator; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_can_run; 30, block; 30, 31; 31, assert_statement; 31, 32; 31, 33; 32, False; 33, string:"Using .run before initialization finished"; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:in; 35, 36; 35, 37; 36, string:'\n'; 37, identifier:cmd; 38, block; 38, 39; 39, assert_statement; 39, 40; 39, 41; 40, False; 41, string:"Don't support multi-line for run2"; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:cmd; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:cmd; 48, identifier:strip; 49, argument_list; 50, if_statement; 50, 51; 50, 54; 50, 155; 51, attribute; 51, 52; 51, 53; 52, identifier:cmd; 53, identifier:startswith; 54, ERROR; 54, 55; 54, 97; 54, 111; 54, 112; 54, 154; 55, comparison_operator:not; 55, 56; 55, 96; 56, binary_operator:+; 56, 57; 56, 62; 56, 95; 57, attribute; 57, 58; 57, 59; 57, 61; 58, string:'
return '; 59, ERROR; 59, 60; 60, identifier:self; 61, identifier:run_counter; 62, ERROR; 62, 63; 62, 64; 62, 71; 62, 74; 62, 75; 62, 78; 62, 79; 62, 82; 62, 83; 62, 86; 62, 87; 62, 88; 62, 94; 63, integer:1; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:log; 68, argument_list; 68, 69; 68, 70; 69, string:"tmux> %s"; 70, identifier:cmd; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_cmd; 74, identifier:cmd; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:_cmd_fn; 78, string:f'{self.remote_scratch}/{self.run_counter}.cmd'; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:_status_fn; 82, string:f'{self.remote_scratch}/{self.run_counter}.status'; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:_out_fn; 86, string:f'{self.remote_scratch}/{self.run_counter}.out'; 87, identifier:cmd; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:util; 91, identifier:shell_strip_comment; 92, argument_list; 92, 93; 93, identifier:cmd; 94, identifier:assert; 95, string:'&'; 96, identifier:cmd; 97, ERROR; 97, 98; 98, call; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 101; 99, 103; 100, string:f"cmd {cmd} contains &, that breaks things"; 101, ERROR; 101, 102; 102, identifier:self; 103, identifier:file_write; 104, argument_list; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_cmd_fn; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:cmd; 110, string:'\n'; 111, identifier:modified_cmd; 112, binary_operator:+; 112, 113; 112, 136; 112, 145; 113, binary_operator:+; 113, 114; 113, 135; 114, attribute; 114, 115; 114, 131; 114, 134; 115, call; 115, 116; 115, 130; 116, attribute; 116, 117; 116, 126; 116, 129; 117, call; 117, 118; 117, 124; 118, attribute; 118, 119; 118, 120; 118, 123; 119, string:f'{cmd} > >(tee -a {self._out_fn}) 2> >(tee -a {self._out_fn} >&2); echo $? > {self._status_fn}'; 120, ERROR; 120, 121; 120, 122; 121, identifier:modified_cmd; 122, identifier:shlex; 123, identifier:quote; 124, argument_list; 124, 125; 125, identifier:modified_cmd; 126, ERROR; 126, 127; 126, 128; 127, identifier:start_time; 128, identifier:time; 129, identifier:time; 130, argument_list; 131, ERROR; 131, 132; 131, 133; 132, identifier:tmux_window; 133, identifier:self; 134, identifier:tmux_session; 135, string:':'; 136, ERROR; 136, 137; 136, 143; 136, 144; 137, call; 137, 138; 137, 139; 138, identifier:str; 139, argument_list; 139, 140; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:tmux_window_id; 143, identifier:tmux_cmd; 144, string:f"tmux send-keys -t {tmux_window} {modified_cmd} Enter"; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:_run_raw; 149, argument_list; 149, 150; 149, 151; 150, identifier:tmux_cmd; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:ignore_errors; 153, identifier:ignore_errors; 154, identifier:non_blocking; 155, block; 155, 156; 156, return_statement; 156, 157; 157, integer:0; 158, if_statement; 158, 159; 158, 171; 159, not_operator; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:wait_for_file; 164, argument_list; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:_status_fn; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:max_wait_sec; 170, integer:60; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:log; 177, argument_list; 177, 178; 178, string:f"Retrying waiting for {self._status_fn}"; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:elapsed_time; 182, binary_operator:-; 182, 183; 182, 188; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:time; 186, identifier:time; 187, argument_list; 188, identifier:start_time; 189, while_statement; 189, 190; 189, 203; 190, boolean_operator:and; 190, 191; 190, 200; 191, not_operator; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:exists; 196, argument_list; 196, 197; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:_status_fn; 200, comparison_operator:<; 200, 201; 200, 202; 201, identifier:elapsed_time; 202, identifier:max_wait_sec; 203, block; 203, 204; 203, 211; 203, 223; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:log; 209, argument_list; 209, 210; 210, string:f"Still waiting for {cmd}"; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:wait_for_file; 216, argument_list; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:_status_fn; 220, keyword_argument; 220, 221; 220, 222; 221, identifier:max_wait_sec; 222, integer:60; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 226; 225, identifier:elapsed_time; 226, binary_operator:-; 226, 227; 226, 232; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:time; 230, identifier:time; 231, argument_list; 232, identifier:start_time; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:contents; 236, call; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:read; 240, argument_list; 240, 241; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:_status_fn; 244, if_statement; 244, 245; 244, 251; 245, comparison_operator:==; 245, 246; 245, 250; 246, call; 246, 247; 246, 248; 247, identifier:len; 248, argument_list; 248, 249; 249, identifier:contents; 250, integer:0; 251, block; 251, 252; 251, 259; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:time; 256, identifier:sleep; 257, argument_list; 257, 258; 258, identifier:check_interval; 259, expression_statement; 259, 260; 260, assignment; 260, 261; 260, 262; 261, identifier:contents; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:read; 266, argument_list; 266, 267; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:_status_fn; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:status; 273, call; 273, 274; 273, 275; 274, identifier:int; 275, argument_list; 275, 276; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:contents; 279, identifier:strip; 280, argument_list; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:self; 285, identifier:last_status; 286, identifier:status; 287, if_statement; 287, 288; 287, 291; 288, comparison_operator:!=; 288, 289; 288, 290; 289, identifier:status; 290, integer:0; 291, block; 291, 292; 291, 299; 291, 306; 291, 313; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:extra_msg; 295, conditional_expression:if; 295, 296; 295, 297; 295, 298; 296, string:'(ignoring error)'; 297, identifier:ignore_errors; 298, string:'(failing)'; 299, expression_statement; 299, 300; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:self; 303, identifier:log; 304, argument_list; 304, 305; 305, string:f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'"; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 311; 308, attribute; 308, 309; 308, 310; 309, identifier:self; 310, identifier:log; 311, argument_list; 311, 312; 312, string:f"\n{'*'*80}\nEnd failing output"; 313, if_statement; 313, 314; 313, 316; 313, 322; 314, not_operator; 314, 315; 315, identifier:ignore_errors; 316, block; 316, 317; 317, raise_statement; 317, 318; 318, call; 318, 319; 318, 320; 319, identifier:RuntimeError; 320, argument_list; 320, 321; 321, string:f"Command {cmd} returned status {status}"; 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:self; 328, identifier:log; 329, argument_list; 329, 330; 330, string:f"Warning: command {cmd} returned status {status}"; 331, return_statement; 331, 332; 332, call; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:self; 335, identifier:read; 336, argument_list; 336, 337; 337, attribute; 337, 338; 337, 339; 338, identifier:self; 339, 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:
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('
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"
self.file_write(self._cmd_fn, cmd + '\n')
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 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, 44; 21, 75; 21, 121; 21, 262; 21, 277; 21, 290; 21, 302; 21, 326; 21, 347; 21, 357; 22, if_statement; 22, 23; 22, 26; 23, comparison_operator:in; 23, 24; 23, 25; 24, string:'*'; 25, identifier:local_fn; 26, block; 26, 27; 26, 43; 27, for_statement; 27, 28; 27, 29; 27, 35; 28, identifier:local_subfn; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:glob; 32, identifier:glob; 33, argument_list; 33, 34; 34, identifier:local_fn; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:upload; 41, argument_list; 41, 42; 42, identifier:local_subfn; 43, return_statement; 44, if_statement; 44, 45; 44, 52; 44, 53; 44, 58; 45, ERROR; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:log; 50, argument_list; 50, 51; 51, string:"skipping backup file {local_fn}"; 52, identifier:return; 53, ERROR; 53, 54; 54, not_operator; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:sftp; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:sftp; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:u; 67, identifier:call_with_retries; 68, argument_list; 68, 69; 68, 74; 69, attribute; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:ssh_client; 73, identifier:open_sftp; 74, string:'self.ssh_client.open_sftp'; 75, function_definition; 75, 76; 75, 77; 75, 80; 76, function_name:maybe_fix_mode; 77, parameters; 77, 78; 77, 79; 78, identifier:local_fn_; 79, identifier:remote_fn_; 80, block; 80, 81; 80, 102; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:mode; 84, subscript; 84, 85; 84, 98; 85, call; 85, 86; 85, 87; 86, identifier:oct; 87, argument_list; 87, 88; 88, subscript; 88, 89; 88, 95; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:os; 92, identifier:stat; 93, argument_list; 93, 94; 94, identifier:local_fn_; 95, attribute; 95, 96; 95, 97; 96, identifier:stat; 97, identifier:ST_MODE; 98, slice; 98, 99; 98, 101; 99, unary_operator:-; 99, 100; 100, integer:3; 101, colon; 102, if_statement; 102, 103; 102, 106; 103, comparison_operator:in; 103, 104; 103, 105; 104, string:'7'; 105, identifier:mode; 106, block; 106, 107; 106, 114; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:log; 112, argument_list; 112, 113; 113, string:f"Making {remote_fn_} executable with mode {mode}"; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:_run_raw; 119, argument_list; 119, 120; 120, string:f"chmod {mode} {remote_fn_}"; 121, function_definition; 121, 122; 121, 123; 121, 126; 122, function_name:_put_dir; 123, parameters; 123, 124; 123, 125; 124, identifier:source; 125, identifier:target; 126, block; 126, 127; 126, 160; 126, 169; 126, 174; 127, function_definition; 127, 128; 127, 129; 127, 137; 128, function_name:_safe_mkdir; 129, parameters; 129, 130; 129, 131; 129, 134; 130, identifier:path; 131, default_parameter; 131, 132; 131, 133; 132, identifier:mode; 133, integer:511; 134, default_parameter; 134, 135; 134, 136; 135, identifier:ignore_existing; 136, True; 137, block; 137, 138; 138, try_statement; 138, 139; 138, 150; 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:self; 145, identifier:sftp; 146, identifier:mkdir; 147, argument_list; 147, 148; 147, 149; 148, identifier:path; 149, identifier:mode; 150, except_clause; 150, 151; 150, 152; 151, identifier:IOError; 152, block; 152, 153; 153, if_statement; 153, 154; 153, 155; 153, 157; 154, identifier:ignore_existing; 155, block; 155, 156; 156, pass_statement; 157, else_clause; 157, 158; 158, block; 158, 159; 159, raise_statement; 160, assert_statement; 160, 161; 161, call; 161, 162; 161, 167; 162, attribute; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:os; 165, identifier:path; 166, identifier:isdir; 167, argument_list; 167, 168; 168, identifier:source; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 172; 171, identifier:_safe_mkdir; 172, argument_list; 172, 173; 173, identifier:target; 174, for_statement; 174, 175; 174, 176; 174, 182; 175, identifier:item; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:os; 179, identifier:listdir; 180, argument_list; 180, 181; 181, identifier:source; 182, block; 182, 183; 183, if_statement; 183, 184; 183, 200; 183, 249; 184, call; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:os; 188, identifier:path; 189, identifier:isfile; 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:os; 195, identifier:path; 196, identifier:join; 197, argument_list; 197, 198; 197, 199; 198, identifier:source; 199, identifier:item; 200, block; 200, 201; 200, 227; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:sftp; 207, identifier:put; 208, argument_list; 208, 209; 208, 218; 209, call; 209, 210; 209, 215; 210, attribute; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:os; 213, identifier:path; 214, identifier:join; 215, argument_list; 215, 216; 215, 217; 216, identifier:source; 217, identifier:item; 218, call; 218, 219; 218, 224; 219, attribute; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:os; 222, identifier:path; 223, identifier:join; 224, argument_list; 224, 225; 224, 226; 225, identifier:target; 226, identifier:item; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 230; 229, identifier:maybe_fix_mode; 230, argument_list; 230, 231; 230, 240; 231, call; 231, 232; 231, 237; 232, attribute; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:os; 235, identifier:path; 236, identifier:join; 237, argument_list; 237, 238; 237, 239; 238, identifier:source; 239, identifier:item; 240, call; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:os; 244, identifier:path; 245, identifier:join; 246, argument_list; 246, 247; 246, 248; 247, identifier:target; 248, identifier:item; 249, else_clause; 249, 250; 250, block; 250, 251; 250, 256; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 254; 253, identifier:_safe_mkdir; 254, argument_list; 254, 255; 255, string:f'{target}/{item}'; 256, expression_statement; 256, 257; 257, call; 257, 258; 257, 259; 258, identifier:_put_dir; 259, argument_list; 259, 260; 259, 261; 260, string:f'{source}/{item}'; 261, string:f'{target}/{item}'; 262, if_statement; 262, 263; 262, 265; 263, not_operator; 263, 264; 264, identifier:remote_fn; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:remote_fn; 269, call; 269, 270; 269, 275; 270, attribute; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:os; 273, identifier:path; 274, identifier:basename; 275, argument_list; 275, 276; 276, identifier:local_fn; 277, expression_statement; 277, 278; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:log; 282, argument_list; 282, 283; 283, binary_operator:+; 283, 284; 283, 289; 284, binary_operator:+; 284, 285; 284, 288; 285, binary_operator:+; 285, 286; 285, 287; 286, string:'uploading '; 287, identifier:local_fn; 288, string:' to '; 289, identifier:remote_fn; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:remote_fn; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:remote_fn; 296, identifier:replace; 297, argument_list; 297, 298; 297, 299; 298, string:'~'; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:homedir; 302, if_statement; 302, 303; 302, 306; 303, comparison_operator:in; 303, 304; 303, 305; 304, string:'/'; 305, identifier:remote_fn; 306, block; 306, 307; 306, 318; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:remote_dir; 310, call; 310, 311; 310, 316; 311, attribute; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:os; 314, identifier:path; 315, identifier:dirname; 316, argument_list; 316, 317; 317, identifier:remote_fn; 318, assert_statement; 318, 319; 318, 325; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:exists; 323, argument_list; 323, 324; 324, identifier:remote_dir; 325, string:f"Remote dir {remote_dir} doesn't exist"; 326, if_statement; 326, 327; 326, 335; 327, boolean_operator:and; 327, 328; 327, 329; 328, identifier:dont_overwrite; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:exists; 333, argument_list; 333, 334; 334, identifier:remote_fn; 335, block; 335, 336; 335, 346; 336, expression_statement; 336, 337; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:log; 341, argument_list; 341, 342; 342, binary_operator:%; 342, 343; 342, 344; 343, string:"Remote file %s exists, skipping"; 344, tuple; 344, 345; 345, identifier:remote_fn; 346, return_statement; 347, assert_statement; 347, 348; 347, 356; 348, call; 348, 349; 348, 354; 349, attribute; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:os; 352, identifier:path; 353, identifier:exists; 354, argument_list; 354, 355; 355, identifier:local_fn; 356, string:f"{local_fn} not found"; 357, if_statement; 357, 358; 357, 366; 357, 373; 358, call; 358, 359; 358, 364; 359, attribute; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:os; 362, identifier:path; 363, identifier:isdir; 364, argument_list; 364, 365; 365, identifier:local_fn; 366, block; 366, 367; 367, expression_statement; 367, 368; 368, call; 368, 369; 368, 370; 369, identifier:_put_dir; 370, argument_list; 370, 371; 370, 372; 371, identifier:local_fn; 372, identifier:remote_fn; 373, else_clause; 373, 374; 374, block; 374, 375; 374, 388; 374, 418; 374, 432; 375, assert_statement; 375, 376; 375, 384; 376, call; 376, 377; 376, 382; 377, attribute; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:os; 380, identifier:path; 381, identifier:isfile; 382, argument_list; 382, 383; 383, identifier:local_fn; 384, binary_operator:%; 384, 385; 384, 386; 385, string:"%s is not a file"; 386, tuple; 386, 387; 387, identifier:local_fn; 388, if_statement; 388, 389; 388, 402; 389, boolean_operator:and; 389, 390; 389, 396; 390, call; 390, 391; 390, 394; 391, attribute; 391, 392; 391, 393; 392, identifier:self; 393, identifier:exists; 394, argument_list; 394, 395; 395, identifier:remote_fn; 396, call; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:self; 399, identifier:isdir; 400, argument_list; 400, 401; 401, identifier:remote_fn; 402, block; 402, 403; 403, expression_statement; 403, 404; 404, assignment; 404, 405; 404, 406; 405, identifier:remote_fn; 406, binary_operator:+; 406, 407; 406, 410; 407, binary_operator:+; 407, 408; 407, 409; 408, identifier:remote_fn; 409, string:'/'; 410, call; 410, 411; 410, 416; 411, attribute; 411, 412; 411, 415; 412, attribute; 412, 413; 412, 414; 413, identifier:os; 414, identifier:path; 415, identifier:basename; 416, argument_list; 416, 417; 417, identifier:local_fn; 418, expression_statement; 418, 419; 419, call; 419, 420; 419, 425; 420, attribute; 420, 421; 420, 424; 421, attribute; 421, 422; 421, 423; 422, identifier:self; 423, identifier:sftp; 424, identifier:put; 425, argument_list; 425, 426; 425, 429; 426, keyword_argument; 426, 427; 426, 428; 427, identifier:localpath; 428, identifier:local_fn; 429, keyword_argument; 429, 430; 429, 431; 430, identifier:remotepath; 431, identifier:remote_fn; 432, expression_statement; 432, 433; 433, call; 433, 434; 433, 435; 434, identifier:maybe_fix_mode; 435, argument_list; 435, 436; 435, 437; 436, identifier:local_fn; 437, identifier:remote_fn | def upload(self, local_fn: str, remote_fn: str = '',
dont_overwrite: bool = False) -> None:
if '*' in local_fn:
for local_subfn in glob.glob(local_fn):
self.upload(local_subfn)
return
if '
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_):
mode = oct(os.stat(local_fn_)[stat.ST_MODE])[-3:]
if '7' in mode:
self.log(f"Making {remote_fn_} executable with mode {mode}")
self._run_raw(f"chmod {mode} {remote_fn_}")
def _put_dir(source, target):
def _safe_mkdir(path, mode=511, ignore_existing=True):
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,)
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, 51; 7, 57; 7, 83; 7, 89; 7, 105; 8, function_definition; 8, 9; 8, 10; 8, 13; 9, function_name:call_method; 10, parameters; 10, 11; 10, 12; 11, identifier:obj; 12, identifier:method; 13, block; 13, 14; 13, 41; 14, if_statement; 14, 15; 14, 20; 14, 29; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:obj; 19, identifier:type; 20, block; 20, 21; 20, 25; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:instance; 24, None; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:owner; 28, identifier:obj; 29, else_clause; 29, 30; 30, block; 30, 31; 30, 35; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:instance; 34, identifier:obj; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:owner; 38, attribute; 38, 39; 38, 40; 39, identifier:obj; 40, identifier:__class__; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 50; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:method; 46, identifier:__get__; 47, argument_list; 47, 48; 47, 49; 48, identifier:instance; 49, identifier:owner; 50, argument_list; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:default_name; 54, subscript; 54, 55; 54, 56; 55, identifier:names; 56, integer:0; 57, function_definition; 57, 58; 57, 59; 57, 61; 58, function_name:default_fn; 59, parameters; 59, 60; 60, identifier:obj; 61, block; 61, 62; 62, for_statement; 62, 63; 62, 64; 62, 65; 63, identifier:cls; 64, identifier:bases; 65, block; 65, 66; 66, if_statement; 66, 67; 66, 72; 67, call; 67, 68; 67, 69; 68, identifier:hasattr; 69, argument_list; 69, 70; 69, 71; 70, identifier:cls; 71, identifier:default_name; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:call_method; 76, argument_list; 76, 77; 76, 78; 77, identifier:obj; 78, call; 78, 79; 78, 80; 79, identifier:getattr; 80, argument_list; 80, 81; 80, 82; 81, identifier:cls; 82, identifier:default_name; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:default_fn; 87, identifier:__name__; 88, identifier:default_name; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:fns; 92, list_comprehension; 92, 93; 92, 98; 92, 101; 93, tuple; 93, 94; 93, 95; 94, identifier:name; 95, subscript; 95, 96; 95, 97; 96, identifier:attrs; 97, identifier:name; 98, for_in_clause; 98, 99; 98, 100; 99, identifier:name; 100, identifier:names; 101, if_clause; 101, 102; 102, comparison_operator:in; 102, 103; 102, 104; 103, identifier:name; 104, identifier:attrs; 105, if_statement; 105, 106; 105, 112; 105, 118; 105, 153; 106, comparison_operator:>; 106, 107; 106, 111; 107, call; 107, 108; 107, 109; 108, identifier:len; 109, argument_list; 109, 110; 110, identifier:fns; 111, integer:1; 112, block; 112, 113; 113, raise_statement; 113, 114; 114, call; 114, 115; 114, 116; 115, identifier:RuntimeError; 116, argument_list; 116, 117; 117, string:"Cannot have more than one setup or teardown method per context (class or test)."; 118, elif_clause; 118, 119; 118, 125; 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; 125, 134; 125, 145; 125, 151; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 131; 128, pattern_list; 128, 129; 128, 130; 129, identifier:name; 130, identifier:fn; 131, subscript; 131, 132; 131, 133; 132, identifier:fns; 133, integer:0; 134, function_definition; 134, 135; 134, 136; 134, 138; 135, function_name:child_fn; 136, parameters; 136, 137; 137, identifier:obj; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:call_method; 142, argument_list; 142, 143; 142, 144; 143, identifier:obj; 144, identifier:fn; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:child_fn; 149, identifier:__name__; 150, identifier:name; 151, return_statement; 151, 152; 152, identifier:child_fn; 153, else_clause; 153, 154; 154, block; 154, 155; 155, return_statement; 155, 156; 156, identifier:default_fn | def get_child_fn(attrs, names, bases):
def call_method(obj, method):
if isinstance(obj, type):
instance = None
owner = obj
else:
instance = obj
owner = obj.__class__
method.__get__(instance, owner)()
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
fns = [(name, attrs[name]) for name in names if name in attrs]
if len(fns) > 1:
raise RuntimeError("Cannot have more than one setup or teardown method per context (class or test).")
elif len(fns) == 1:
name, fn = fns[0]
def child_fn(obj):
call_method(obj, fn)
child_fn.__name__ = name
return child_fn
else:
return default_fn |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 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, block; 20, 21; 20, 60; 20, 67; 20, 92; 20, 103; 20, 116; 20, 169; 20, 366; 20, 372; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:response; 24, None; 25, block; 25, 26; 26, with_statement; 26, 27; 26, 34; 27, with_clause; 27, 28; 28, with_item; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:warnings; 32, identifier:catch_warnings; 33, argument_list; 34, block; 34, 35; 34, 40; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 38; 37, identifier:_ignore_warnings; 38, argument_list; 38, 39; 39, identifier:self; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:response; 43, call; 43, 44; 43, 51; 44, attribute; 44, 45; 44, 50; 45, subscript; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_sessions; 49, integer:0; 50, identifier:get; 51, argument_list; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_base_url; 55, keyword_argument; 55, 56; 55, 57; 56, identifier:verify; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_tlsverify; 60, if_statement; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:response; 63, identifier:ok; 64, block; 64, 65; 65, return_statement; 65, 66; 66, None; 67, if_statement; 67, 68; 67, 77; 68, comparison_operator:!=; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:response; 71, identifier:status_code; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:requests; 75, identifier:codes; 76, identifier:unauthorized; 77, block; 77, 78; 78, raise_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:exceptions; 82, identifier:DXFUnexpectedStatusCodeError; 83, argument_list; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:response; 86, identifier:status_code; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:requests; 90, identifier:codes; 91, identifier:unauthorized; 92, if_statement; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:_insecure; 96, block; 96, 97; 97, raise_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:exceptions; 101, identifier:DXFAuthInsecureError; 102, argument_list; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:parsed; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:www_authenticate; 109, identifier:parse; 110, argument_list; 110, 111; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:response; 114, identifier:headers; 115, string:'www-authenticate'; 116, if_statement; 116, 117; 116, 124; 116, 151; 116, 163; 117, boolean_operator:and; 117, 118; 117, 121; 118, comparison_operator:is; 118, 119; 118, 120; 119, identifier:username; 120, None; 121, comparison_operator:is; 121, 122; 121, 123; 122, identifier:password; 123, None; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:headers; 128, dictionary; 128, 129; 129, pair; 129, 130; 129, 131; 130, string:'Authorization'; 131, binary_operator:+; 131, 132; 131, 133; 132, string:'Basic '; 133, call; 133, 134; 133, 149; 134, attribute; 134, 135; 134, 148; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:base64; 138, identifier:b64encode; 139, argument_list; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:_to_bytes_2and3; 142, argument_list; 142, 143; 143, binary_operator:+; 143, 144; 143, 147; 144, binary_operator:+; 144, 145; 144, 146; 145, identifier:username; 146, string:':'; 147, identifier:password; 148, identifier:decode; 149, argument_list; 149, 150; 150, string:'utf-8'; 151, elif_clause; 151, 152; 151, 155; 152, comparison_operator:is; 152, 153; 152, 154; 153, identifier:authorization; 154, None; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:headers; 159, dictionary; 159, 160; 160, pair; 160, 161; 160, 162; 161, string:'Authorization'; 162, identifier:authorization; 163, else_clause; 163, 164; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:headers; 168, dictionary; 169, if_statement; 169, 170; 169, 173; 170, comparison_operator:in; 170, 171; 170, 172; 171, string:'bearer'; 172, identifier:parsed; 173, block; 173, 174; 173, 180; 173, 221; 173, 235; 173, 246; 173, 261; 173, 271; 173, 277; 173, 290; 173, 299; 173, 334; 173, 339; 173, 347; 173, 362; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:info; 177, subscript; 177, 178; 177, 179; 178, identifier:parsed; 179, string:'bearer'; 180, if_statement; 180, 181; 180, 186; 180, 204; 180, 215; 181, boolean_operator:and; 181, 182; 181, 183; 182, identifier:actions; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:_repo; 186, block; 186, 187; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:scope; 190, binary_operator:+; 190, 191; 190, 198; 191, binary_operator:+; 191, 192; 191, 197; 192, binary_operator:+; 192, 193; 192, 194; 193, string:'repository:'; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:_repo; 197, string:':'; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, string:','; 201, identifier:join; 202, argument_list; 202, 203; 203, identifier:actions; 204, elif_clause; 204, 205; 204, 208; 205, comparison_operator:in; 205, 206; 205, 207; 206, string:'scope'; 207, identifier:info; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:scope; 212, subscript; 212, 213; 212, 214; 213, identifier:info; 214, string:'scope'; 215, else_clause; 215, 216; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:scope; 220, string:''; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:url_parts; 224, call; 224, 225; 224, 226; 225, identifier:list; 226, argument_list; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:urlparse; 230, identifier:urlparse; 231, argument_list; 231, 232; 232, subscript; 232, 233; 232, 234; 233, identifier:info; 234, string:'realm'; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 238; 237, identifier:query; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:urlparse; 241, identifier:parse_qs; 242, argument_list; 242, 243; 243, subscript; 243, 244; 243, 245; 244, identifier:url_parts; 245, integer:4; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:query; 250, identifier:update; 251, argument_list; 251, 252; 252, dictionary; 252, 253; 252, 258; 253, pair; 253, 254; 253, 255; 254, string:'service'; 255, subscript; 255, 256; 255, 257; 256, identifier:info; 257, string:'service'; 258, pair; 258, 259; 258, 260; 259, string:'scope'; 260, identifier:scope; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 266; 263, subscript; 263, 264; 263, 265; 264, identifier:url_parts; 265, integer:4; 266, call; 266, 267; 266, 268; 267, identifier:urlencode; 268, argument_list; 268, 269; 268, 270; 269, identifier:query; 270, True; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 276; 273, subscript; 273, 274; 273, 275; 274, identifier:url_parts; 275, integer:0; 276, string:'https'; 277, if_statement; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:_auth_host; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 287; 284, subscript; 284, 285; 284, 286; 285, identifier:url_parts; 286, integer:1; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:_auth_host; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:auth_url; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:urlparse; 296, identifier:urlunparse; 297, argument_list; 297, 298; 298, identifier:url_parts; 299, with_statement; 299, 300; 299, 307; 300, with_clause; 300, 301; 301, with_item; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:warnings; 305, identifier:catch_warnings; 306, argument_list; 307, block; 307, 308; 307, 313; 308, expression_statement; 308, 309; 309, call; 309, 310; 309, 311; 310, identifier:_ignore_warnings; 311, argument_list; 311, 312; 312, identifier:self; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:r; 316, call; 316, 317; 316, 324; 317, attribute; 317, 318; 317, 323; 318, subscript; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:self; 321, identifier:_sessions; 322, integer:0; 323, identifier:get; 324, argument_list; 324, 325; 324, 326; 324, 329; 325, identifier:auth_url; 326, keyword_argument; 326, 327; 326, 328; 327, identifier:headers; 328, identifier:headers; 329, keyword_argument; 329, 330; 329, 331; 330, identifier:verify; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:_tlsverify; 334, expression_statement; 334, 335; 335, call; 335, 336; 335, 337; 336, identifier:_raise_for_status; 337, argument_list; 337, 338; 338, identifier:r; 339, expression_statement; 339, 340; 340, assignment; 340, 341; 340, 342; 341, identifier:rjson; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:r; 345, identifier:json; 346, argument_list; 347, expression_statement; 347, 348; 348, assignment; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, identifier:self; 351, identifier:token; 352, conditional_expression:if; 352, 353; 352, 356; 352, 359; 353, subscript; 353, 354; 353, 355; 354, identifier:rjson; 355, string:'access_token'; 356, comparison_operator:in; 356, 357; 356, 358; 357, string:'access_token'; 358, identifier:rjson; 359, subscript; 359, 360; 359, 361; 360, identifier:rjson; 361, string:'token'; 362, return_statement; 362, 363; 363, attribute; 363, 364; 363, 365; 364, identifier:self; 365, identifier:_token; 366, expression_statement; 366, 367; 367, assignment; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:self; 370, identifier:_headers; 371, identifier:headers; 372, return_statement; 372, 373; 373, None | def authenticate(self,
username=None, password=None,
actions=None, response=None,
authorization=None):
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
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, 23; 11, 34; 11, 46; 11, 59; 11, 74; 11, 84; 11, 97; 11, 229; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:ddl; 15, None; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_ddl; 22, identifier:ddl; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:is; 24, 25; 24, 26; 25, identifier:source_database; 26, None; 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:source_database; 33, identifier:source_database; 34, if_statement; 34, 35; 34, 40; 35, comparison_operator:is; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:_ddl; 39, None; 40, block; 40, 41; 41, raise_statement; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:ValueError; 44, argument_list; 44, 45; 45, string:"DDL is not specified"; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:ret; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:_DDL_PARSE_EXPR; 54, identifier:parseString; 55, argument_list; 55, 56; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:_ddl; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:in; 60, 61; 60, 62; 61, string:"schema"; 62, identifier:ret; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 71; 66, attribute; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_table; 70, identifier:schema; 71, subscript; 71, 72; 71, 73; 72, identifier:ret; 73, string:"schema"; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:_table; 80, identifier:name; 81, subscript; 81, 82; 81, 83; 82, identifier:ret; 83, string:"table"; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_table; 90, identifier:is_temp; 91, conditional_expression:if; 91, 92; 91, 93; 91, 96; 92, True; 93, comparison_operator:in; 93, 94; 93, 95; 94, string:"temp"; 95, identifier:ret; 96, False; 97, for_statement; 97, 98; 97, 99; 97, 102; 98, identifier:ret_col; 99, subscript; 99, 100; 99, 101; 100, identifier:ret; 101, string:"columns"; 102, block; 102, 103; 103, if_statement; 103, 104; 103, 111; 103, 157; 104, comparison_operator:==; 104, 105; 104, 110; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:ret_col; 108, identifier:getName; 109, argument_list; 110, string:"column"; 111, block; 111, 112; 111, 144; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:col; 115, call; 115, 116; 115, 123; 116, attribute; 116, 117; 116, 122; 117, attribute; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:_table; 121, identifier:columns; 122, identifier:append; 123, argument_list; 123, 124; 123, 129; 123, 134; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:column_name; 126, subscript; 126, 127; 126, 128; 127, identifier:ret_col; 128, string:"name"; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:data_type_array; 131, subscript; 131, 132; 131, 133; 132, identifier:ret_col; 133, string:"type"; 134, keyword_argument; 134, 135; 134, 136; 135, identifier:array_brackets; 136, conditional_expression:if; 136, 137; 136, 140; 136, 143; 137, subscript; 137, 138; 137, 139; 138, identifier:ret_col; 139, string:'array_brackets'; 140, comparison_operator:in; 140, 141; 140, 142; 141, string:"array_brackets"; 142, identifier:ret_col; 143, None; 144, if_statement; 144, 145; 144, 148; 145, comparison_operator:in; 145, 146; 145, 147; 146, string:"constraint"; 147, identifier:ret_col; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:col; 153, identifier:constraint; 154, subscript; 154, 155; 154, 156; 155, identifier:ret_col; 156, string:"constraint"; 157, elif_clause; 157, 158; 157, 165; 158, comparison_operator:==; 158, 159; 158, 164; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:ret_col; 162, identifier:getName; 163, argument_list; 164, string:"constraint"; 165, block; 165, 166; 166, for_statement; 166, 167; 166, 168; 166, 171; 167, identifier:col_name; 168, subscript; 168, 169; 168, 170; 169, identifier:ret_col; 170, string:"constraint_columns"; 171, block; 171, 172; 171, 182; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:col; 175, subscript; 175, 176; 175, 181; 176, attribute; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:_table; 180, identifier:columns; 181, identifier:col_name; 182, if_statement; 182, 183; 182, 188; 182, 201; 182, 216; 183, comparison_operator:==; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:ret_col; 186, string:"type"; 187, string:"PRIMARY KEY"; 188, block; 188, 189; 188, 195; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:col; 193, identifier:not_null; 194, True; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:col; 199, identifier:primary_key; 200, True; 201, elif_clause; 201, 202; 201, 209; 202, comparison_operator:in; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:ret_col; 205, string:"type"; 206, list:["UNIQUE", "UNIQUE KEY"]; 206, 207; 206, 208; 207, string:"UNIQUE"; 208, string:"UNIQUE KEY"; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:col; 214, identifier:unique; 215, True; 216, elif_clause; 216, 217; 216, 222; 217, comparison_operator:==; 217, 218; 217, 221; 218, subscript; 218, 219; 218, 220; 219, identifier:ret_col; 220, string:"type"; 221, string:"NOT NULL"; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:col; 227, identifier:not_null; 228, True; 229, return_statement; 229, 230; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:_table | def parse(self, ddl=None, source_database=None):
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)
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":
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":
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, 17; 6, 26; 6, 33; 6, 58; 6, 76; 6, 85; 6, 94; 6, 103; 6, 116; 7, if_statement; 7, 8; 7, 14; 8, call; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:is_time_valid; 12, argument_list; 12, 13; 13, identifier:timestamp; 14, block; 14, 15; 15, return_statement; 15, 16; 16, identifier:timestamp; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:t_day; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:get_next_valid_day; 24, argument_list; 24, 25; 25, identifier:timestamp; 26, if_statement; 26, 27; 26, 30; 27, comparison_operator:is; 27, 28; 27, 29; 28, identifier:t_day; 29, None; 30, block; 30, 31; 31, return_statement; 31, 32; 32, identifier:t_day; 33, if_statement; 33, 34; 33, 37; 33, 47; 34, comparison_operator:<; 34, 35; 34, 36; 35, identifier:timestamp; 36, identifier:t_day; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:sec_from_morning; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:get_next_future_timerange_valid; 45, argument_list; 45, 46; 46, identifier:t_day; 47, else_clause; 47, 48; 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_valid; 56, argument_list; 56, 57; 57, identifier:timestamp; 58, if_statement; 58, 59; 58, 62; 59, comparison_operator:is; 59, 60; 59, 61; 60, identifier:sec_from_morning; 61, None; 62, block; 62, 63; 63, if_statement; 63, 64; 63, 71; 64, boolean_operator:and; 64, 65; 64, 68; 65, comparison_operator:is; 65, 66; 65, 67; 66, identifier:t_day; 67, None; 68, comparison_operator:is; 68, 69; 68, 70; 69, identifier:sec_from_morning; 70, None; 71, block; 71, 72; 72, return_statement; 72, 73; 73, binary_operator:+; 73, 74; 73, 75; 74, identifier:t_day; 75, identifier:sec_from_morning; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:timestamp; 79, binary_operator:+; 79, 80; 79, 84; 80, call; 80, 81; 80, 82; 81, identifier:get_day; 82, argument_list; 82, 83; 83, identifier:timestamp; 84, integer:86400; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:t_day2; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:get_next_valid_day; 92, argument_list; 92, 93; 93, identifier:timestamp; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:sec_from_morning; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:get_next_future_timerange_valid; 101, argument_list; 101, 102; 102, identifier:t_day2; 103, if_statement; 103, 104; 103, 111; 104, boolean_operator:and; 104, 105; 104, 108; 105, comparison_operator:is; 105, 106; 105, 107; 106, identifier:t_day2; 107, None; 108, comparison_operator:is; 108, 109; 108, 110; 109, identifier:sec_from_morning; 110, None; 111, block; 111, 112; 112, return_statement; 112, 113; 113, binary_operator:+; 113, 114; 113, 115; 114, identifier:t_day2; 115, identifier:sec_from_morning; 116, return_statement; 116, 117; 117, None | def get_next_valid_time_from_t(self, timestamp):
if self.is_time_valid(timestamp):
return timestamp
t_day = self.get_next_valid_day(timestamp)
if t_day is None:
return t_day
if timestamp < t_day:
sec_from_morning = self.get_next_future_timerange_valid(t_day)
else:
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
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
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, 18; 6, 27; 6, 52; 6, 67; 6, 78; 6, 87; 6, 96; 6, 105; 6, 120; 6, 131; 7, if_statement; 7, 8; 7, 15; 8, not_operator; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:is_time_valid; 13, argument_list; 13, 14; 14, identifier:timestamp; 15, block; 15, 16; 16, return_statement; 16, 17; 17, identifier:timestamp; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:t_day; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:get_next_invalid_day; 25, argument_list; 25, 26; 26, identifier:timestamp; 27, if_statement; 27, 28; 27, 31; 27, 41; 28, comparison_operator:<; 28, 29; 28, 30; 29, identifier:timestamp; 30, identifier:t_day; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:sec_from_morning; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:get_next_future_timerange_invalid; 39, argument_list; 39, 40; 40, identifier:t_day; 41, else_clause; 41, 42; 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_invalid; 50, argument_list; 50, 51; 51, identifier:timestamp; 52, if_statement; 52, 53; 52, 60; 53, boolean_operator:and; 53, 54; 53, 57; 54, comparison_operator:is; 54, 55; 54, 56; 55, identifier:t_day; 56, None; 57, comparison_operator:is; 57, 58; 57, 59; 58, identifier:sec_from_morning; 59, None; 60, block; 60, 61; 61, return_statement; 61, 62; 62, binary_operator:+; 62, 63; 62, 66; 63, binary_operator:+; 63, 64; 63, 65; 64, identifier:t_day; 65, identifier:sec_from_morning; 66, integer:1; 67, if_statement; 67, 68; 67, 75; 68, boolean_operator:and; 68, 69; 68, 72; 69, comparison_operator:is; 69, 70; 69, 71; 70, identifier:t_day; 71, None; 72, comparison_operator:is; 72, 73; 72, 74; 73, identifier:sec_from_morning; 74, None; 75, block; 75, 76; 76, return_statement; 76, 77; 77, identifier:t_day; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:timestamp; 81, binary_operator:+; 81, 82; 81, 86; 82, call; 82, 83; 82, 84; 83, identifier:get_day; 84, argument_list; 84, 85; 85, identifier:timestamp; 86, integer:86400; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:t_day2; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:get_next_invalid_day; 94, argument_list; 94, 95; 95, identifier:timestamp; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:sec_from_morning; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:get_next_future_timerange_invalid; 103, argument_list; 103, 104; 104, identifier:t_day2; 105, if_statement; 105, 106; 105, 113; 106, boolean_operator:and; 106, 107; 106, 110; 107, comparison_operator:is; 107, 108; 107, 109; 108, identifier:t_day2; 109, None; 110, comparison_operator:is; 110, 111; 110, 112; 111, identifier:sec_from_morning; 112, None; 113, block; 113, 114; 114, return_statement; 114, 115; 115, binary_operator:+; 115, 116; 115, 119; 116, binary_operator:+; 116, 117; 116, 118; 117, identifier:t_day2; 118, identifier:sec_from_morning; 119, integer:1; 120, if_statement; 120, 121; 120, 128; 121, boolean_operator:and; 121, 122; 121, 125; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:t_day2; 124, None; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:sec_from_morning; 127, None; 128, block; 128, 129; 129, return_statement; 129, 130; 130, identifier:t_day2; 131, return_statement; 131, 132; 132, None | def get_next_invalid_time_from_t(self, timestamp):
if not self.is_time_valid(timestamp):
return timestamp
t_day = self.get_next_invalid_day(timestamp)
if timestamp < t_day:
sec_from_morning = self.get_next_future_timerange_invalid(t_day)
else:
sec_from_morning = self.get_next_future_timerange_invalid(timestamp)
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning + 1
if t_day is not None and sec_from_morning is None:
return t_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
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, 18; 8, 33; 8, 51; 8, 64; 8, 79; 8, 97; 8, 110; 8, 119; 8, 278; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:now; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:time; 15, identifier:localtime; 16, argument_list; 16, 17; 17, identifier:ref; 18, if_statement; 18, 19; 18, 24; 19, comparison_operator:==; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:syear; 23, integer:0; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:syear; 30, attribute; 30, 31; 30, 32; 31, identifier:now; 32, identifier:tm_year; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:day_start; 36, call; 36, 37; 36, 38; 37, identifier:find_day_by_weekday_offset; 38, argument_list; 38, 39; 38, 42; 38, 45; 38, 48; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:syear; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:smon; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:swday; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:swday_offset; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:start_time; 54, call; 54, 55; 54, 56; 55, identifier:get_start_of_day; 56, argument_list; 56, 57; 56, 60; 56, 63; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:syear; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:smon; 63, identifier:day_start; 64, if_statement; 64, 65; 64, 70; 65, comparison_operator:==; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:eyear; 69, integer:0; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:eyear; 76, attribute; 76, 77; 76, 78; 77, identifier:now; 78, identifier:tm_year; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:day_end; 82, call; 82, 83; 82, 84; 83, identifier:find_day_by_weekday_offset; 84, argument_list; 84, 85; 84, 88; 84, 91; 84, 94; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:eyear; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:emon; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:ewday; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:ewday_offset; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:end_time; 100, call; 100, 101; 100, 102; 101, identifier:get_end_of_day; 102, argument_list; 102, 103; 102, 106; 102, 109; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:eyear; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:emon; 109, identifier:day_end; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:now_epoch; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:time; 116, identifier:mktime; 117, argument_list; 117, 118; 118, identifier:now; 119, if_statement; 119, 120; 119, 123; 119, 201; 120, comparison_operator:>; 120, 121; 120, 122; 121, identifier:start_time; 122, identifier:end_time; 123, block; 123, 124; 124, if_statement; 124, 125; 124, 128; 124, 164; 125, comparison_operator:>; 125, 126; 125, 127; 126, identifier:now_epoch; 127, identifier:end_time; 128, block; 128, 129; 128, 149; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:day_end; 132, call; 132, 133; 132, 134; 133, identifier:find_day_by_weekday_offset; 134, argument_list; 134, 135; 134, 140; 134, 143; 134, 146; 135, binary_operator:+; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:eyear; 139, integer:1; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:emon; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:ewday; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:ewday_offset; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:end_time; 152, call; 152, 153; 152, 154; 153, identifier:get_end_of_day; 154, argument_list; 154, 155; 154, 160; 154, 163; 155, binary_operator:+; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:eyear; 159, integer:1; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:emon; 163, identifier:day_end; 164, else_clause; 164, 165; 165, block; 165, 166; 165, 186; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:day_start; 169, call; 169, 170; 169, 171; 170, identifier:find_day_by_weekday_offset; 171, argument_list; 171, 172; 171, 177; 171, 180; 171, 183; 172, binary_operator:-; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:syear; 176, integer:1; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:smon; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:swday; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:swday_offset; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:start_time; 189, call; 189, 190; 189, 191; 190, identifier:get_start_of_day; 191, argument_list; 191, 192; 191, 197; 191, 200; 192, binary_operator:-; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:syear; 196, integer:1; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:smon; 200, identifier:day_start; 201, else_clause; 201, 202; 202, block; 202, 203; 203, if_statement; 203, 204; 203, 207; 204, comparison_operator:>; 204, 205; 204, 206; 205, identifier:now_epoch; 206, identifier:end_time; 207, block; 207, 208; 207, 228; 207, 243; 207, 263; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:day_start; 211, call; 211, 212; 211, 213; 212, identifier:find_day_by_weekday_offset; 213, argument_list; 213, 214; 213, 219; 213, 222; 213, 225; 214, binary_operator:+; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:syear; 218, integer:1; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:smon; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:swday; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:swday_offset; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:start_time; 231, call; 231, 232; 231, 233; 232, identifier:get_start_of_day; 233, argument_list; 233, 234; 233, 239; 233, 242; 234, binary_operator:+; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:syear; 238, integer:1; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:smon; 242, identifier:day_start; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:day_end; 246, call; 246, 247; 246, 248; 247, identifier:find_day_by_weekday_offset; 248, argument_list; 248, 249; 248, 254; 248, 257; 248, 260; 249, binary_operator:+; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:eyear; 253, integer:1; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:emon; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:ewday; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:ewday_offset; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:end_time; 266, call; 266, 267; 266, 268; 267, identifier:get_end_of_day; 268, argument_list; 268, 269; 268, 274; 268, 277; 269, binary_operator:+; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:self; 272, identifier:eyear; 273, integer:1; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:emon; 277, identifier:day_end; 278, return_statement; 278, 279; 279, tuple; 279, 280; 279, 281; 280, identifier:start_time; 281, identifier:end_time | def get_start_and_end_time(self, ref=None):
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:
if now_epoch > end_time:
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:
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:
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, 18; 8, 33; 8, 48; 8, 61; 8, 76; 8, 91; 8, 104; 8, 113; 8, 260; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:now; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:time; 15, identifier:localtime; 16, argument_list; 16, 17; 17, identifier:ref; 18, if_statement; 18, 19; 18, 24; 19, comparison_operator:==; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:syear; 23, integer:0; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:syear; 30, attribute; 30, 31; 30, 32; 31, identifier:now; 32, identifier:tm_year; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:day_start; 36, call; 36, 37; 36, 38; 37, identifier:find_day_by_offset; 38, argument_list; 38, 39; 38, 42; 38, 45; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:syear; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:smon; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:smday; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:start_time; 51, call; 51, 52; 51, 53; 52, identifier:get_start_of_day; 53, argument_list; 53, 54; 53, 57; 53, 60; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:syear; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:smon; 60, identifier:day_start; 61, if_statement; 61, 62; 61, 67; 62, comparison_operator:==; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:eyear; 66, integer:0; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:eyear; 73, attribute; 73, 74; 73, 75; 74, identifier:now; 75, identifier:tm_year; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:day_end; 79, call; 79, 80; 79, 81; 80, identifier:find_day_by_offset; 81, argument_list; 81, 82; 81, 85; 81, 88; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:eyear; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:emon; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:emday; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:end_time; 94, call; 94, 95; 94, 96; 95, identifier:get_end_of_day; 96, argument_list; 96, 97; 96, 100; 96, 103; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:eyear; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:emon; 103, identifier:day_end; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:now_epoch; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:time; 110, identifier:mktime; 111, argument_list; 111, 112; 112, identifier:now; 113, if_statement; 113, 114; 113, 117; 113, 189; 114, comparison_operator:>; 114, 115; 114, 116; 115, identifier:start_time; 116, identifier:end_time; 117, block; 117, 118; 118, if_statement; 118, 119; 118, 122; 118, 155; 119, comparison_operator:>; 119, 120; 119, 121; 120, identifier:now_epoch; 121, identifier:end_time; 122, block; 122, 123; 122, 140; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:day_end; 126, call; 126, 127; 126, 128; 127, identifier:find_day_by_offset; 128, argument_list; 128, 129; 128, 134; 128, 137; 129, binary_operator:+; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:eyear; 133, integer:1; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:emon; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:emday; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:end_time; 143, call; 143, 144; 143, 145; 144, identifier:get_end_of_day; 145, argument_list; 145, 146; 145, 151; 145, 154; 146, binary_operator:+; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:eyear; 150, integer:1; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:emon; 154, identifier:day_end; 155, else_clause; 155, 156; 156, block; 156, 157; 156, 174; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:day_start; 160, call; 160, 161; 160, 162; 161, identifier:find_day_by_offset; 162, argument_list; 162, 163; 162, 168; 162, 171; 163, binary_operator:-; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:syear; 167, integer:1; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:smon; 171, attribute; 171, 172; 171, 173; 172, identifier:self; 173, identifier:emday; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:start_time; 177, call; 177, 178; 177, 179; 178, identifier:get_start_of_day; 179, argument_list; 179, 180; 179, 185; 179, 188; 180, binary_operator:-; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:syear; 184, integer:1; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:smon; 188, identifier:day_start; 189, else_clause; 189, 190; 190, block; 190, 191; 191, if_statement; 191, 192; 191, 195; 192, comparison_operator:>; 192, 193; 192, 194; 193, identifier:now_epoch; 194, identifier:end_time; 195, block; 195, 196; 195, 213; 195, 228; 195, 245; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:day_start; 199, call; 199, 200; 199, 201; 200, identifier:find_day_by_offset; 201, argument_list; 201, 202; 201, 207; 201, 210; 202, binary_operator:+; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:self; 205, identifier:syear; 206, integer:1; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:smon; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:smday; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:start_time; 216, call; 216, 217; 216, 218; 217, identifier:get_start_of_day; 218, argument_list; 218, 219; 218, 224; 218, 227; 219, binary_operator:+; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:syear; 223, integer:1; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:smon; 227, identifier:day_start; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:day_end; 231, call; 231, 232; 231, 233; 232, identifier:find_day_by_offset; 233, argument_list; 233, 234; 233, 239; 233, 242; 234, binary_operator:+; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:eyear; 238, integer:1; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:emon; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:emday; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:end_time; 248, call; 248, 249; 248, 250; 249, identifier:get_end_of_day; 250, argument_list; 250, 251; 250, 256; 250, 259; 251, binary_operator:+; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:self; 254, identifier:eyear; 255, integer:1; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:emon; 259, identifier:day_end; 260, return_statement; 260, 261; 261, tuple; 261, 262; 261, 263; 262, identifier:start_time; 263, identifier:end_time | def get_start_and_end_time(self, ref=None):
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:
if now_epoch > end_time:
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:
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:
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, 18; 8, 33; 8, 39; 8, 55; 8, 66; 8, 81; 8, 87; 8, 103; 8, 114; 8, 165; 8, 174; 8, 271; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:now; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:time; 15, identifier:localtime; 16, argument_list; 16, 17; 17, identifier:ref; 18, if_statement; 18, 19; 18, 24; 19, comparison_operator:==; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:syear; 23, integer:0; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:syear; 30, attribute; 30, 31; 30, 32; 31, identifier:now; 32, identifier:tm_year; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:month_start_id; 36, attribute; 36, 37; 36, 38; 37, identifier:now; 38, identifier:tm_mon; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:day_start; 42, call; 42, 43; 42, 44; 43, identifier:find_day_by_weekday_offset; 44, argument_list; 44, 45; 44, 48; 44, 49; 44, 52; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:syear; 48, identifier:month_start_id; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:swday; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:swday_offset; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:start_time; 58, call; 58, 59; 58, 60; 59, identifier:get_start_of_day; 60, argument_list; 60, 61; 60, 64; 60, 65; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:syear; 64, identifier:month_start_id; 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:month_end_id; 84, attribute; 84, 85; 84, 86; 85, identifier:now; 86, identifier:tm_mon; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:day_end; 90, call; 90, 91; 90, 92; 91, identifier:find_day_by_weekday_offset; 92, argument_list; 92, 93; 92, 96; 92, 97; 92, 100; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:eyear; 96, identifier:month_end_id; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:ewday; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:ewday_offset; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:end_time; 106, call; 106, 107; 106, 108; 107, identifier:get_end_of_day; 108, argument_list; 108, 109; 108, 112; 108, 113; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:eyear; 112, identifier:month_end_id; 113, identifier:day_end; 114, if_statement; 114, 115; 114, 118; 115, comparison_operator:>; 115, 116; 115, 117; 116, identifier:start_time; 117, identifier:end_time; 118, block; 118, 119; 118, 123; 118, 138; 118, 154; 119, expression_statement; 119, 120; 120, augmented_assignment:+=; 120, 121; 120, 122; 121, identifier:month_end_id; 122, integer:1; 123, if_statement; 123, 124; 123, 127; 124, comparison_operator:>; 124, 125; 124, 126; 125, identifier:month_end_id; 126, integer:12; 127, block; 127, 128; 127, 132; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:month_end_id; 131, integer:1; 132, expression_statement; 132, 133; 133, augmented_assignment:+=; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:eyear; 137, integer:1; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:day_end; 141, call; 141, 142; 141, 143; 142, identifier:find_day_by_weekday_offset; 143, argument_list; 143, 144; 143, 147; 143, 148; 143, 151; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:eyear; 147, identifier:month_end_id; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:ewday; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:ewday_offset; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:end_time; 157, call; 157, 158; 157, 159; 158, identifier:get_end_of_day; 159, argument_list; 159, 160; 159, 163; 159, 164; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:eyear; 163, identifier:month_end_id; 164, identifier:day_end; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:now_epoch; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:time; 171, identifier:mktime; 172, argument_list; 172, 173; 173, identifier:now; 174, if_statement; 174, 175; 174, 178; 175, comparison_operator:<; 175, 176; 175, 177; 176, identifier:end_time; 177, identifier:now_epoch; 178, block; 178, 179; 178, 183; 178, 187; 178, 202; 178, 217; 178, 233; 178, 244; 178, 260; 179, expression_statement; 179, 180; 180, augmented_assignment:+=; 180, 181; 180, 182; 181, identifier:month_end_id; 182, integer:1; 183, expression_statement; 183, 184; 184, augmented_assignment:+=; 184, 185; 184, 186; 185, identifier:month_start_id; 186, integer:1; 187, if_statement; 187, 188; 187, 191; 188, comparison_operator:>; 188, 189; 188, 190; 189, identifier:month_end_id; 190, integer:12; 191, block; 191, 192; 191, 196; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:month_end_id; 195, integer:1; 196, expression_statement; 196, 197; 197, augmented_assignment:+=; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:eyear; 201, integer:1; 202, if_statement; 202, 203; 202, 206; 203, comparison_operator:>; 203, 204; 203, 205; 204, identifier:month_start_id; 205, integer:12; 206, block; 206, 207; 206, 211; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:month_start_id; 210, integer:1; 211, expression_statement; 211, 212; 212, augmented_assignment:+=; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:self; 215, identifier:syear; 216, integer:1; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:day_start; 220, call; 220, 221; 220, 222; 221, identifier:find_day_by_weekday_offset; 222, argument_list; 222, 223; 222, 226; 222, 227; 222, 230; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:syear; 226, identifier:month_start_id; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:swday; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:swday_offset; 233, expression_statement; 233, 234; 234, assignment; 234, 235; 234, 236; 235, identifier:start_time; 236, call; 236, 237; 236, 238; 237, identifier:get_start_of_day; 238, argument_list; 238, 239; 238, 242; 238, 243; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:syear; 242, identifier:month_start_id; 243, identifier:day_start; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:day_end; 247, call; 247, 248; 247, 249; 248, identifier:find_day_by_weekday_offset; 249, argument_list; 249, 250; 249, 253; 249, 254; 249, 257; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:eyear; 253, identifier:month_end_id; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:ewday; 257, attribute; 257, 258; 257, 259; 258, identifier:self; 259, identifier:ewday_offset; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 263; 262, identifier:end_time; 263, call; 263, 264; 263, 265; 264, identifier:get_end_of_day; 265, argument_list; 265, 266; 265, 269; 265, 270; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:eyear; 269, identifier:month_end_id; 270, identifier:day_end; 271, return_statement; 271, 272; 272, tuple; 272, 273; 272, 274; 273, identifier:start_time; 274, identifier:end_time | def get_start_and_end_time(self, ref=None):
now = time.localtime(ref)
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)
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)
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)
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
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)
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, 24; 8, 35; 8, 98; 8, 264; 9, if_statement; 9, 10; 9, 14; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:my_metrics; 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:debug; 20, argument_list; 20, 21; 21, string:"Flushing - no metrics to send"; 22, return_statement; 22, 23; 23, True; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:now; 27, call; 27, 28; 27, 29; 28, identifier:int; 29, argument_list; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:time; 33, identifier:time; 34, argument_list; 35, if_statement; 35, 36; 35, 49; 36, boolean_operator:and; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:last_failure; 40, comparison_operator:>; 40, 41; 40, 48; 41, binary_operator:+; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:last_failure; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:metrics_flush_pause; 48, identifier:now; 49, block; 49, 50; 49, 96; 50, if_statement; 50, 51; 50, 55; 51, not_operator; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:log_metrics_flush_pause; 55, block; 55, 56; 55, 76; 55, 90; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:date; 59, call; 59, 60; 59, 72; 60, attribute; 60, 61; 60, 71; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:datetime; 65, identifier:datetime; 66, identifier:fromtimestamp; 67, argument_list; 67, 68; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:last_failure; 71, identifier:strftime; 72, argument_list; 72, 73; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:date_fmt; 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, 86; 81, 87; 82, concatenated_string; 82, 83; 82, 84; 82, 85; 83, string:"Metrics flush paused on connection error "; 84, string:"(last failed: %s). "; 85, string:"Inner stored metric: %d. Trying to send..."; 86, identifier:date; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:metrics_count; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:log_metrics_flush_pause; 95, True; 96, return_statement; 96, 97; 97, True; 98, try_statement; 98, 99; 98, 185; 99, block; 99, 100; 99, 110; 99, 156; 99, 173; 99, 179; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:logger; 104, identifier:debug; 105, argument_list; 105, 106; 105, 107; 106, string:"Flushing %d metrics to Graphite/carbon"; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:metrics_count; 110, if_statement; 110, 111; 110, 118; 110, 125; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:carbon; 116, identifier:send_data; 117, argument_list; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:my_metrics; 124, list:[]; 125, else_clause; 125, 126; 126, block; 126, 127; 126, 139; 126, 154; 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, 136; 133, concatenated_string; 133, 134; 133, 135; 134, string:"Failed sending metrics to Graphite/carbon. "; 135, string:"Inner stored metric: %d"; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:metrics_count; 139, if_statement; 139, 140; 139, 141; 140, identifier:log; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:logger; 146, identifier:warning; 147, argument_list; 147, 148; 147, 151; 148, concatenated_string; 148, 149; 148, 150; 149, string:"Failed sending metrics to Graphite/carbon. "; 150, string:"Inner stored metric: %d"; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:metrics_count; 154, return_statement; 154, 155; 155, False; 156, if_statement; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:log_metrics_flush_pause; 160, block; 160, 161; 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:"Metrics flush restored. "; 169, string:"Remaining stored metric: %d"; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:metrics_count; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:last_failure; 178, integer:0; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:log_metrics_flush_pause; 184, False; 185, except_clause; 185, 186; 185, 190; 186, as_pattern; 186, 187; 186, 188; 187, identifier:Exception; 188, as_pattern_target; 188, 189; 189, identifier:exp; 190, block; 190, 191; 190, 245; 190, 256; 190, 262; 191, if_statement; 191, 192; 191, 196; 191, 209; 192, not_operator; 192, 193; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:log_metrics_flush_pause; 196, block; 196, 197; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:logger; 201, identifier:warning; 202, argument_list; 202, 203; 202, 206; 203, concatenated_string; 203, 204; 203, 205; 204, string:"Failed sending metrics to Graphite/carbon. "; 205, string:"Inner stored metric: %d"; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:metrics_count; 209, else_clause; 209, 210; 210, block; 210, 211; 210, 231; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:date; 214, call; 214, 215; 214, 227; 215, attribute; 215, 216; 215, 226; 216, call; 216, 217; 216, 222; 217, attribute; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:datetime; 220, identifier:datetime; 221, identifier:fromtimestamp; 222, argument_list; 222, 223; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:last_failure; 226, identifier:strftime; 227, argument_list; 227, 228; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:date_fmt; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:logger; 235, identifier:warning; 236, argument_list; 236, 237; 236, 241; 236, 242; 237, concatenated_string; 237, 238; 237, 239; 237, 240; 238, string:"Metrics flush paused on connection error "; 239, string:"(last failed: %s). "; 240, string:"Inner stored metric: %d. Trying to send..."; 241, identifier:date; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:metrics_count; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:logger; 249, identifier:warning; 250, argument_list; 250, 251; 250, 252; 251, string:"Exception: %s"; 252, call; 252, 253; 252, 254; 253, identifier:str; 254, argument_list; 254, 255; 255, identifier:exp; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:last_failure; 261, identifier:now; 262, return_statement; 262, 263; 263, False; 264, return_statement; 264, 265; 265, True | def flush(self, log=False):
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:
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, ERROR; 1, 2; 1, 252; 1, 317; 2, function_definition; 2, 3; 2, 4; 2, 11; 3, function_name:counter; 4, parameters; 4, 5; 4, 6; 4, 7; 4, 8; 5, identifier:self; 6, identifier:key; 7, identifier:value; 8, default_parameter; 8, 9; 8, 10; 9, identifier:timestamp; 10, None; 11, block; 11, 12; 11, 32; 11, 36; 11, 40; 11, 53; 11, 66; 11, 78; 11, 134; 11, 154; 11, 239; 11, 241; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 19; 14, pattern_list; 14, 15; 14, 16; 14, 17; 14, 18; 15, identifier:_min; 16, identifier:_max; 17, identifier:count; 18, identifier:_sum; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:stats; 24, identifier:get; 25, argument_list; 25, 26; 25, 27; 26, identifier:key; 27, tuple; 27, 28; 27, 29; 27, 30; 27, 31; 28, None; 29, None; 30, integer:0; 31, integer:0; 32, expression_statement; 32, 33; 33, augmented_assignment:+=; 33, 34; 33, 35; 34, identifier:count; 35, integer:1; 36, expression_statement; 36, 37; 37, augmented_assignment:+=; 37, 38; 37, 39; 38, identifier:_sum; 39, identifier:value; 40, if_statement; 40, 41; 40, 48; 41, boolean_operator:or; 41, 42; 41, 45; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:_min; 44, None; 45, comparison_operator:<; 45, 46; 45, 47; 46, identifier:value; 47, identifier:_min; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:_min; 52, identifier:value; 53, if_statement; 53, 54; 53, 61; 54, boolean_operator:or; 54, 55; 54, 58; 55, comparison_operator:is; 55, 56; 55, 57; 56, identifier:_max; 57, None; 58, comparison_operator:>; 58, 59; 58, 60; 59, identifier:value; 60, identifier:_max; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:_max; 65, identifier:value; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:stats; 72, identifier:key; 73, tuple; 73, 74; 73, 75; 73, 76; 73, 77; 74, identifier:_min; 75, identifier:_max; 76, identifier:count; 77, identifier:_sum; 78, if_statement; 78, 79; 78, 86; 79, boolean_operator:and; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:statsd_enabled; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:statsd_sock; 86, block; 86, 87; 86, 101; 86, 110; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:packet; 90, binary_operator:%; 90, 91; 90, 92; 91, string:'%s.%s.%s:%d|c'; 92, tuple; 92, 93; 92, 96; 92, 99; 92, 100; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:statsd_prefix; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:name; 99, identifier:key; 100, identifier:value; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:packet; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:packet; 107, identifier:encode; 108, argument_list; 108, 109; 109, string:'utf-8'; 110, try_statement; 110, 111; 110, 124; 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:self; 117, identifier:statsd_sock; 118, identifier:sendto; 119, argument_list; 119, 120; 119, 121; 120, identifier:packet; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:statsd_addr; 124, except_clause; 124, 125; 124, 132; 125, tuple; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:socket; 128, identifier:error; 129, attribute; 129, 130; 129, 131; 130, identifier:socket; 131, identifier:gaierror; 132, block; 132, 133; 133, pass_statement; 134, if_statement; 134, 135; 134, 142; 135, boolean_operator:and; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:statsd_enabled; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:carbon; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:send_to_graphite; 148, argument_list; 148, 149; 148, 150; 148, 151; 149, identifier:key; 150, identifier:value; 151, keyword_argument; 151, 152; 151, 153; 152, identifier:timestamp; 153, identifier:timestamp; 154, if_statement; 154, 155; 154, 162; 154, 229; 155, boolean_operator:and; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:statsd_enabled; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:file_d; 162, ERROR; 162, 163; 162, 179; 162, 185; 162, 217; 162, 218; 162, 221; 162, 223; 162, 224; 162, 227; 162, 228; 163, if_statement; 163, 164; 163, 167; 164, comparison_operator:is; 164, 165; 164, 166; 165, identifier:timestamp; 166, None; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:timestamp; 171, call; 171, 172; 171, 173; 172, identifier:int; 173, argument_list; 173, 174; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:time; 177, identifier:time; 178, argument_list; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:packet; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:line_fmt; 185, if_statement; 185, 186; 185, 190; 185, 197; 186, not_operator; 186, 187; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:date_fmt; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:date; 194, binary_operator:%; 194, 195; 194, 196; 195, string:"%s"; 196, identifier:timestamp; 197, else_clause; 197, 198; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:date; 202, call; 202, 203; 202, 213; 203, attribute; 203, 204; 203, 212; 204, call; 204, 205; 204, 210; 205, attribute; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:datetime; 208, identifier:datetime; 209, identifier:fromtimestamp; 210, argument_list; 210, 211; 211, identifier:timestamp; 212, identifier:strftime; 213, argument_list; 213, 214; 214, attribute; 214, 215; 214, 216; 215, identifier:self; 216, identifier:date_fmt; 217, identifier:packet; 218, attribute; 218, 219; 218, 220; 219, identifier:packet; 220, identifier:replace; 221, ERROR; 221, 222; 222, string:"
packet = packet.replace("; 223, identifier:packet; 224, attribute; 224, 225; 224, 226; 225, identifier:packet; 226, identifier:replace; 227, string:"
packet = packet.replace("; 228, identifier:try; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 237; 232, attribute; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:file_d; 236, identifier:write; 237, argument_list; 237, 238; 238, identifier:packet; 239, ERROR; 239, 240; 240, identifier:except; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:IOError; 244, type; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:logger; 248, identifier:warning; 249, argument_list; 249, 250; 249, 251; 250, string:"Could not write to the file: %s"; 251, identifier:packet; 252, if_statement; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:broks_enabled; 256, block; 256, 257; 256, 266; 256, 282; 257, expression_statement; 257, 258; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:logger; 261, identifier:debug; 262, argument_list; 262, 263; 262, 264; 262, 265; 263, string:"alignak stat brok: %s = %s"; 264, identifier:key; 265, identifier:value; 266, if_statement; 266, 267; 266, 270; 267, comparison_operator:is; 267, 268; 267, 269; 268, identifier:timestamp; 269, None; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 274; 273, identifier:timestamp; 274, call; 274, 275; 274, 276; 275, identifier:int; 276, argument_list; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:time; 280, identifier:time; 281, argument_list; 282, return_statement; 282, 283; 283, call; 283, 284; 283, 285; 284, identifier:Brok; 285, argument_list; 285, 286; 286, dictionary; 286, 287; 286, 290; 287, pair; 287, 288; 287, 289; 288, string:'type'; 289, string:'alignak_stat'; 290, pair; 290, 291; 290, 292; 291, string:'data'; 292, dictionary; 292, 293; 292, 296; 292, 299; 292, 311; 292, 314; 293, pair; 293, 294; 293, 295; 294, string:'ts'; 295, identifier:timestamp; 296, pair; 296, 297; 296, 298; 297, string:'type'; 298, string:'counter'; 299, pair; 299, 300; 299, 301; 300, string:'metric'; 301, binary_operator:%; 301, 302; 301, 303; 302, string:'%s.%s.%s'; 303, tuple; 303, 304; 303, 307; 303, 310; 304, attribute; 304, 305; 304, 306; 305, identifier:self; 306, identifier:statsd_prefix; 307, attribute; 307, 308; 307, 309; 308, identifier:self; 309, identifier:name; 310, identifier:key; 311, pair; 311, 312; 311, 313; 312, string:'value'; 313, identifier:value; 314, pair; 314, 315; 314, 316; 315, string:'uom'; 316, string:'c'; 317, return_statement; 317, 318; 318, None | def counter(self, key, value, timestamp=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)
if self.statsd_enabled and self.statsd_sock:
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
if self.statsd_enabled and self.carbon:
self.send_to_graphite(key, value, timestamp=timestamp)
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("
packet = packet.replace("
packet = packet.replace("
packet = packet.replace("
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, 17; 8, 21; 8, 25; 8, 99; 8, 105; 8, 132; 8, 144; 8, 158; 8, 164; 9, expression_statement; 9, 10; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:logger; 13, identifier:info; 14, argument_list; 14, 15; 14, 16; 15, string:"Allocating new '%s' worker..."; 16, identifier:module_name; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:target; 20, None; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:__warned; 24, list:[]; 25, if_statement; 25, 26; 25, 29; 25, 34; 26, comparison_operator:==; 26, 27; 26, 28; 27, identifier:module_name; 28, string:'fork'; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:target; 33, None; 34, else_clause; 34, 35; 35, block; 35, 36; 35, 73; 36, for_statement; 36, 37; 36, 38; 36, 43; 37, identifier:module; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:modules_manager; 42, identifier:instances; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 52; 45, comparison_operator:==; 45, 46; 45, 51; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:module; 49, identifier:get_name; 50, argument_list; 51, identifier:module_name; 52, block; 52, 53; 52, 67; 53, if_statement; 53, 54; 53, 64; 54, not_operator; 54, 55; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:module; 59, identifier:properties; 60, identifier:get; 61, argument_list; 61, 62; 61, 63; 62, string:'worker_capable'; 63, False; 64, block; 64, 65; 65, raise_statement; 65, 66; 66, identifier:NotWorkerMod; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:target; 70, attribute; 70, 71; 70, 72; 71, identifier:module; 72, identifier:work; 73, if_statement; 73, 74; 73, 77; 74, comparison_operator:is; 74, 75; 74, 76; 75, identifier:target; 76, None; 77, block; 77, 78; 77, 98; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:not; 79, 80; 79, 81; 80, identifier:module_name; 81, identifier:__warned; 82, block; 82, 83; 82, 91; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:logger; 87, identifier:warning; 88, argument_list; 88, 89; 88, 90; 89, string:"No target found for %s, NOT creating a worker for it..."; 90, identifier:module_name; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:__warned; 95, identifier:append; 96, argument_list; 96, 97; 97, identifier:module_name; 98, return_statement; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:queue; 102, call; 102, 103; 102, 104; 103, identifier:Queue; 104, argument_list; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:worker; 108, call; 108, 109; 108, 110; 109, identifier:Worker; 110, argument_list; 110, 111; 110, 112; 110, 113; 110, 116; 110, 119; 110, 124; 110, 127; 111, identifier:module_name; 112, identifier:queue; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:returns_queue; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:processes_by_worker; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:max_plugins_output_length; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:max_plugins_output_length; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:target; 126, identifier:target; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:loaded_into; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:name; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 143; 134, subscript; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:workers; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:worker; 141, identifier:get_id; 142, argument_list; 143, identifier:worker; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 157; 146, subscript; 146, 147; 146, 152; 147, subscript; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:q_by_mod; 151, identifier:module_name; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:worker; 155, identifier:get_id; 156, argument_list; 157, identifier:queue; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:worker; 162, identifier:start; 163, argument_list; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:logger; 168, identifier:info; 169, argument_list; 169, 170; 169, 171; 169, 172; 169, 177; 170, string:"Started '%s' worker: %s (pid=%d)"; 171, identifier:module_name; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:worker; 175, identifier:get_id; 176, argument_list; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:worker; 180, identifier:get_pid; 181, argument_list | def create_and_launch_worker(self, module_name='fork'):
logger.info("Allocating new '%s' worker...", module_name)
target = None
__warned = []
if module_name == 'fork':
target = None
else:
for module in self.modules_manager.instances:
if module.get_name() == module_name:
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
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)
self.workers[worker.get_id()] = worker
self.q_by_mod[module_name][worker.get_id()] = queue
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; 2, function_name:check_and_del_zombie_workers; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 20; 5, 24; 5, 110; 6, for_statement; 6, 7; 6, 8; 6, 11; 7, identifier:p; 8, call; 8, 9; 8, 10; 9, identifier:active_children; 10, argument_list; 11, block; 11, 12; 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; 18, string:"got child: %s"; 19, identifier:p; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:w_to_del; 23, list:[]; 24, for_statement; 24, 25; 24, 26; 24, 36; 25, identifier:worker; 26, call; 26, 27; 26, 28; 27, identifier:list; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:workers; 34, identifier:values; 35, argument_list; 36, block; 36, 37; 36, 54; 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; 42, 49; 43, string:"checking if worker %s (pid=%d) is alive"; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:worker; 47, identifier:get_id; 48, argument_list; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:worker; 52, identifier:get_pid; 53, argument_list; 54, if_statement; 54, 55; 54, 66; 55, boolean_operator:and; 55, 56; 55, 60; 56, not_operator; 56, 57; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:interrupted; 60, not_operator; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:worker; 64, identifier:is_alive; 65, argument_list; 66, block; 66, 67; 66, 84; 66, 90; 66, 99; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:logger; 71, identifier:warning; 72, argument_list; 72, 73; 72, 74; 72, 79; 73, string:"The worker %s (pid=%d) went down unexpectedly!"; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:worker; 77, identifier:get_id; 78, argument_list; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:worker; 82, identifier:get_pid; 83, argument_list; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:worker; 88, identifier:terminate; 89, argument_list; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:worker; 94, identifier:join; 95, argument_list; 95, 96; 96, keyword_argument; 96, 97; 96, 98; 97, identifier:timeout; 98, integer:1; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:w_to_del; 103, identifier:append; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:worker; 108, identifier:get_id; 109, argument_list; 110, for_statement; 110, 111; 110, 112; 110, 113; 111, identifier:worker_id; 112, identifier:w_to_del; 113, block; 113, 114; 113, 122; 113, 136; 113, 183; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:worker; 117, subscript; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:workers; 121, identifier:worker_id; 122, delete_statement; 122, 123; 123, subscript; 123, 124; 123, 131; 124, subscript; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:q_by_mod; 128, attribute; 128, 129; 128, 130; 129, identifier:worker; 130, identifier:module_name; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:worker; 134, identifier:get_id; 135, argument_list; 136, for_statement; 136, 137; 136, 138; 136, 141; 137, identifier:scheduler_uuid; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:schedulers; 141, block; 141, 142; 141, 150; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:sched; 145, subscript; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:schedulers; 149, identifier:scheduler_uuid; 150, for_statement; 150, 151; 150, 152; 150, 162; 151, identifier:act; 152, call; 152, 153; 152, 154; 153, identifier:list; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 161; 156, attribute; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:sched; 159, identifier:actions; 160, identifier:values; 161, argument_list; 162, block; 162, 163; 163, if_statement; 163, 164; 163, 175; 164, boolean_operator:and; 164, 165; 164, 170; 165, comparison_operator:==; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:act; 168, identifier:status; 169, identifier:ACT_STATUS_QUEUED; 170, comparison_operator:==; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:act; 173, identifier:my_worker; 174, identifier:worker_id; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:assign_to_a_queue; 181, argument_list; 181, 182; 182, identifier:act; 183, delete_statement; 183, 184; 184, subscript; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:workers; 188, identifier:worker_id | def check_and_del_zombie_workers(self):
for p in active_children():
logger.debug("got child: %s", p)
w_to_del = []
for worker in list(self.workers.values()):
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())
worker.terminate()
worker.join(timeout=1)
w_to_del.append(worker.get_id())
for worker_id in w_to_del:
worker = self.workers[worker_id]
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:
self.assign_to_a_queue(act)
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, 12; 7, 61; 7, 77; 7, 85; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:scheduler_link; 11, None; 12, for_statement; 12, 13; 12, 14; 12, 17; 12, 50; 13, identifier:scheduler_id; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:schedulers; 17, block; 17, 18; 17, 30; 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:"Trying to add an action, scheduler: %s"; 25, subscript; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:schedulers; 29, identifier:scheduler_id; 30, if_statement; 30, 31; 30, 40; 31, comparison_operator:==; 31, 32; 31, 33; 32, identifier:scheduler_instance_id; 33, attribute; 33, 34; 33, 39; 34, subscript; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:schedulers; 38, identifier:scheduler_id; 39, identifier:instance_id; 40, block; 40, 41; 40, 49; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:scheduler_link; 44, subscript; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:schedulers; 48, identifier:scheduler_id; 49, break_statement; 50, else_clause; 50, 51; 51, block; 51, 52; 51, 60; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:logger; 56, identifier:error; 57, argument_list; 57, 58; 57, 59; 58, string:"Trying to add actions from an unknwown scheduler: %s"; 59, identifier:scheduler_instance_id; 60, return_statement; 61, if_statement; 61, 62; 61, 64; 62, not_operator; 62, 63; 63, identifier:scheduler_link; 64, block; 64, 65; 64, 76; 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, 75; 71, concatenated_string; 71, 72; 71, 73; 72, string:"Trying to add actions, but scheduler link is not found for: %s, "; 73, string:"actions: %s"; 74, identifier:scheduler_instance_id; 75, identifier:actions_list; 76, return_statement; 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; 82, 84; 83, string:"Found scheduler link: %s"; 84, identifier:scheduler_link; 85, for_statement; 85, 86; 85, 87; 85, 88; 86, identifier:action; 87, identifier:actions_list; 88, block; 88, 89; 88, 98; 88, 133; 88, 141; 88, 149; 88, 159; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:uuid; 92, call; 92, 93; 92, 94; 93, identifier:getattr; 94, argument_list; 94, 95; 94, 96; 94, 97; 95, identifier:action; 96, string:'uuid'; 97, None; 98, if_statement; 98, 99; 98, 102; 99, comparison_operator:is; 99, 100; 99, 101; 100, identifier:uuid; 101, None; 102, block; 102, 103; 103, try_statement; 103, 104; 103, 121; 104, block; 104, 105; 104, 115; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:action; 108, call; 108, 109; 108, 110; 109, identifier:unserialize; 110, argument_list; 110, 111; 110, 112; 111, identifier:action; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:no_load; 114, True; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:uuid; 118, attribute; 118, 119; 118, 120; 119, identifier:action; 120, identifier:uuid; 121, except_clause; 121, 122; 121, 123; 122, identifier:AlignakClassLookupException; 123, block; 123, 124; 123, 132; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:logger; 128, identifier:error; 129, argument_list; 129, 130; 129, 131; 130, string:'Cannot un-serialize action: %s'; 131, identifier:action; 132, continue_statement; 133, if_statement; 133, 134; 133, 139; 134, comparison_operator:in; 134, 135; 134, 136; 135, identifier:uuid; 136, attribute; 136, 137; 136, 138; 137, identifier:scheduler_link; 138, identifier:actions; 139, block; 139, 140; 140, continue_statement; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:action; 145, identifier:my_scheduler; 146, attribute; 146, 147; 146, 148; 147, identifier:scheduler_link; 148, identifier:uuid; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 158; 151, subscript; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:scheduler_link; 154, identifier:actions; 155, attribute; 155, 156; 155, 157; 156, identifier:action; 157, identifier:uuid; 158, identifier:action; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:assign_to_a_queue; 164, argument_list; 164, 165; 165, identifier:action | def add_actions(self, actions_list, scheduler_instance_id):
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:
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 uuid in scheduler_link.actions:
continue
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, 20; 8, 27; 8, 40; 8, 44; 8, 127; 9, expression_statement; 9, 10; 10, identifier:r; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:split_line; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:line; 17, identifier:split; 18, argument_list; 18, 19; 19, string:';'; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:split_line_size; 23, call; 23, 24; 23, 25; 24, identifier:len; 25, argument_list; 25, 26; 26, identifier:split_line; 27, if_statement; 27, 28; 27, 35; 28, boolean_operator:or; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:maxsplit; 31, None; 32, comparison_operator:<; 32, 33; 32, 34; 33, identifier:maxsplit; 34, integer:0; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:maxsplit; 39, identifier:split_line_size; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:i; 43, integer:0; 44, while_statement; 44, 45; 44, 50; 45, comparison_operator:<; 45, 46; 45, 47; 46, identifier:i; 47, binary_operator:-; 47, 48; 47, 49; 48, identifier:split_line_size; 49, integer:1; 50, block; 50, 51; 50, 62; 50, 78; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:ends; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, subscript; 56, 57; 56, 58; 57, identifier:split_line; 58, identifier:i; 59, identifier:endswith; 60, argument_list; 60, 61; 61, string:'\\'; 62, if_statement; 62, 63; 62, 64; 63, identifier:ends; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:split_line; 69, identifier:i; 70, subscript; 70, 71; 70, 74; 71, subscript; 71, 72; 71, 73; 72, identifier:split_line; 73, identifier:i; 74, slice; 74, 75; 74, 76; 75, colon; 76, unary_operator:-; 76, 77; 77, integer:1; 78, if_statement; 78, 79; 78, 91; 78, 121; 79, boolean_operator:and; 79, 80; 79, 86; 80, parenthesized_expression; 80, 81; 81, boolean_operator:or; 81, 82; 81, 83; 82, identifier:ends; 83, comparison_operator:>=; 83, 84; 83, 85; 84, identifier:i; 85, identifier:maxsplit; 86, comparison_operator:<; 86, 87; 86, 88; 87, identifier:i; 88, binary_operator:-; 88, 89; 88, 90; 89, identifier:split_line_size; 90, integer:1; 91, block; 91, 92; 91, 111; 91, 117; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:split_line; 96, identifier:i; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, string:";"; 100, identifier:join; 101, argument_list; 101, 102; 102, list:[split_line[i], split_line[i + 1]]; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:split_line; 105, identifier:i; 106, subscript; 106, 107; 106, 108; 107, identifier:split_line; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:i; 110, integer:1; 111, delete_statement; 111, 112; 112, subscript; 112, 113; 112, 114; 113, identifier:split_line; 114, binary_operator:+; 114, 115; 114, 116; 115, identifier:i; 116, integer:1; 117, expression_statement; 117, 118; 118, augmented_assignment:-=; 118, 119; 118, 120; 119, identifier:split_line_size; 120, integer:1; 121, else_clause; 121, 122; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, augmented_assignment:+=; 124, 125; 124, 126; 125, identifier:i; 126, integer:1; 127, return_statement; 127, 128; 128, identifier:split_line | def split_semicolon(line, maxsplit=None):
r
split_line = line.split(';')
split_line_size = len(split_line)
if maxsplit is None or maxsplit < 0:
maxsplit = split_line_size
i = 0
while i < split_line_size - 1:
ends = split_line[i].endswith('\\')
if ends:
split_line[i] = split_line[i][:-1]
if (ends or i >= maxsplit) and i < split_line_size - 1:
split_line[i] = ";".join([split_line[i], split_line[i + 1]])
del split_line[i + 1]
split_line_size -= 1
else:
i += 1
return split_line |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_by_number_values; 3, parameters; 3, 4; 3, 5; 4, identifier:x00; 5, identifier:y00; 6, block; 6, 7; 6, 20; 6, 34; 7, if_statement; 7, 8; 7, 17; 8, comparison_operator:<; 8, 9; 8, 13; 9, call; 9, 10; 9, 11; 10, identifier:len; 11, argument_list; 11, 12; 12, identifier:x00; 13, call; 13, 14; 13, 15; 14, identifier:len; 15, argument_list; 15, 16; 16, identifier:y00; 17, block; 17, 18; 18, return_statement; 18, 19; 19, integer:1; 20, if_statement; 20, 21; 20, 30; 21, comparison_operator:>; 21, 22; 21, 26; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, identifier:x00; 26, call; 26, 27; 26, 28; 27, identifier:len; 28, argument_list; 28, 29; 29, identifier:y00; 30, block; 30, 31; 31, return_statement; 31, 32; 32, unary_operator:-; 32, 33; 33, integer:1; 34, return_statement; 34, 35; 35, integer:0 | def sort_by_number_values(x00, y00):
if len(x00) < len(y00):
return 1
if len(x00) > len(y00):
return -1
return 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 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, block; 9, 10; 9, 21; 9, 25; 9, 296; 9, 371; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:name_property; 13, call; 13, 14; 13, 15; 14, identifier:getattr; 15, argument_list; 15, 16; 15, 19; 15, 20; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:__class__; 19, string:"name_property"; 20, None; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:generated_hosts; 24, list:[]; 25, if_statement; 25, 26; 25, 27; 26, identifier:name_property; 27, block; 27, 28; 27, 37; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:name; 31, call; 31, 32; 31, 33; 32, identifier:getattr; 33, argument_list; 33, 34; 33, 35; 33, 36; 34, identifier:item; 35, identifier:name_property; 36, None; 37, if_statement; 37, 38; 37, 47; 38, boolean_operator:and; 38, 39; 38, 44; 39, boolean_operator:and; 39, 40; 39, 41; 40, identifier:name; 41, comparison_operator:in; 41, 42; 41, 43; 42, string:'['; 43, identifier:name; 44, comparison_operator:in; 44, 45; 44, 46; 45, string:']'; 46, identifier:name; 47, block; 47, 48; 47, 69; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:pattern; 51, subscript; 51, 52; 51, 53; 52, identifier:name; 53, slice; 53, 54; 53, 62; 53, 63; 54, binary_operator:+; 54, 55; 54, 61; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:name; 58, identifier:find; 59, argument_list; 59, 60; 60, string:"["; 61, integer:1; 62, colon; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:name; 66, identifier:find; 67, argument_list; 67, 68; 68, string:"]"; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:in; 70, 71; 70, 72; 71, string:'-'; 72, identifier:pattern; 73, block; 73, 74; 73, 82; 73, 91; 73, 95; 73, 99; 73, 103; 73, 156; 73, 171; 73, 186; 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:"Found an host with a patterned name: %s"; 81, identifier:pattern; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:limits; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:pattern; 88, identifier:split; 89, argument_list; 89, 90; 90, string:'-'; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:fmt; 94, string:"%d"; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:min_v; 98, integer:1; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:max_v; 102, integer:1; 103, if_statement; 103, 104; 103, 110; 103, 136; 104, comparison_operator:==; 104, 105; 104, 109; 105, call; 105, 106; 105, 107; 106, identifier:len; 107, argument_list; 107, 108; 108, identifier:limits; 109, integer:3; 110, block; 110, 111; 110, 117; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:fmt; 114, subscript; 114, 115; 114, 116; 115, identifier:limits; 116, integer:2; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:new_name; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:name; 123, identifier:replace; 124, argument_list; 124, 125; 124, 135; 125, binary_operator:%; 125, 126; 125, 127; 126, string:'[%s-%s-%s]'; 127, tuple; 127, 128; 127, 131; 127, 134; 128, subscript; 128, 129; 128, 130; 129, identifier:limits; 130, integer:0; 131, subscript; 131, 132; 131, 133; 132, identifier:limits; 133, integer:1; 134, identifier:fmt; 135, string:'***'; 136, else_clause; 136, 137; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:new_name; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:name; 144, identifier:replace; 145, argument_list; 145, 146; 145, 155; 146, binary_operator:%; 146, 147; 146, 148; 147, string:'[%s-%s]'; 148, tuple; 148, 149; 148, 152; 149, subscript; 149, 150; 149, 151; 150, identifier:limits; 151, integer:0; 152, subscript; 152, 153; 152, 154; 153, identifier:limits; 154, integer:1; 155, string:'***'; 156, try_statement; 156, 157; 156, 167; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:min_v; 161, call; 161, 162; 161, 163; 162, identifier:int; 163, argument_list; 163, 164; 164, subscript; 164, 165; 164, 166; 165, identifier:limits; 166, integer:0; 167, except_clause; 167, 168; 167, 169; 168, identifier:ValueError; 169, block; 169, 170; 170, pass_statement; 171, try_statement; 171, 172; 171, 182; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:max_v; 176, call; 176, 177; 176, 178; 177, identifier:int; 178, argument_list; 178, 179; 179, subscript; 179, 180; 179, 181; 180, identifier:limits; 181, integer:1; 182, except_clause; 182, 183; 182, 184; 183, identifier:ValueError; 184, block; 184, 185; 185, pass_statement; 186, for_statement; 186, 187; 186, 188; 186, 195; 187, identifier:idx; 188, call; 188, 189; 188, 190; 189, identifier:range; 190, argument_list; 190, 191; 190, 192; 191, identifier:min_v; 192, binary_operator:+; 192, 193; 192, 194; 193, identifier:max_v; 194, integer:1; 195, block; 195, 196; 195, 212; 195, 219; 195, 227; 195, 241; 195, 289; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:logger; 200, identifier:debug; 201, argument_list; 201, 202; 201, 203; 202, string:"- cloning host: %s"; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:new_name; 206, identifier:replace; 207, argument_list; 207, 208; 207, 209; 208, string:'***'; 209, binary_operator:%; 209, 210; 209, 211; 210, identifier:fmt; 211, identifier:idx; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:new_host; 215, call; 215, 216; 215, 217; 216, identifier:deepcopy; 217, argument_list; 217, 218; 218, identifier:item; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:new_host; 223, identifier:uuid; 224, call; 224, 225; 224, 226; 225, identifier:get_a_new_object_id; 226, argument_list; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:new_host; 231, identifier:host_name; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:new_name; 235, identifier:replace; 236, argument_list; 236, 237; 236, 238; 237, string:'***'; 238, binary_operator:%; 238, 239; 238, 240; 239, identifier:fmt; 240, identifier:idx; 241, for_statement; 241, 242; 241, 243; 241, 249; 242, identifier:prop; 243, list:['display_name', 'alias', 'notes', 'notes_url', 'action_url']; 243, 244; 243, 245; 243, 246; 243, 247; 243, 248; 244, string:'display_name'; 245, string:'alias'; 246, string:'notes'; 247, string:'notes_url'; 248, string:'action_url'; 249, block; 249, 250; 249, 261; 249, 269; 250, if_statement; 250, 251; 250, 259; 251, comparison_operator:is; 251, 252; 251, 258; 252, call; 252, 253; 252, 254; 253, identifier:getattr; 254, argument_list; 254, 255; 254, 256; 254, 257; 255, identifier:new_host; 256, identifier:prop; 257, None; 258, None; 259, block; 259, 260; 260, continue_statement; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:value; 264, call; 264, 265; 264, 266; 265, identifier:getattr; 266, argument_list; 266, 267; 266, 268; 267, identifier:new_host; 268, identifier:prop; 269, if_statement; 269, 270; 269, 273; 270, comparison_operator:in; 270, 271; 270, 272; 271, string:'$HOSTNAME$'; 272, identifier:value; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 277; 276, identifier:setattr; 277, argument_list; 277, 278; 277, 279; 277, 280; 278, identifier:new_host; 279, identifier:prop; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:value; 283, identifier:replace; 284, argument_list; 284, 285; 284, 286; 285, string:'$HOSTNAME$'; 286, attribute; 286, 287; 286, 288; 287, identifier:new_host; 288, identifier:host_name; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:generated_hosts; 293, identifier:append; 294, argument_list; 294, 295; 295, identifier:new_host; 296, if_statement; 296, 297; 296, 298; 296, 343; 297, identifier:generated_hosts; 298, block; 298, 299; 298, 327; 299, for_statement; 299, 300; 299, 301; 299, 302; 300, identifier:new_host; 301, identifier:generated_hosts; 302, block; 302, 303; 302, 317; 303, if_statement; 303, 304; 303, 307; 304, comparison_operator:is; 304, 305; 304, 306; 305, identifier:index; 306, True; 307, block; 307, 308; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:new_host; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:index_item; 315, argument_list; 315, 316; 316, identifier:new_host; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 326; 319, subscript; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:self; 322, identifier:items; 323, attribute; 323, 324; 323, 325; 324, identifier:new_host; 325, identifier:uuid; 326, identifier:new_host; 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, 338; 333, string:" cloned %d hosts from %s"; 334, call; 334, 335; 334, 336; 335, identifier:len; 336, argument_list; 336, 337; 337, identifier:generated_hosts; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, identifier:item; 341, identifier:get_name; 342, argument_list; 343, else_clause; 343, 344; 344, block; 344, 345; 344, 361; 345, if_statement; 345, 346; 345, 351; 346, boolean_operator:and; 346, 347; 346, 350; 347, comparison_operator:is; 347, 348; 347, 349; 348, identifier:index; 349, True; 350, identifier:name_property; 351, block; 351, 352; 352, expression_statement; 352, 353; 353, assignment; 353, 354; 353, 355; 354, identifier:item; 355, call; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:index_item; 359, argument_list; 359, 360; 360, identifier:item; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 370; 363, subscript; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:items; 367, attribute; 367, 368; 367, 369; 368, identifier:item; 369, identifier:uuid; 370, identifier:item; 371, return_statement; 371, 372; 372, identifier:generated_hosts | def add_item(self, item, index=True):
name_property = getattr(self.__class__, "name_property", None)
generated_hosts = []
if name_property:
name = getattr(item, name_property, None)
if name and '[' in name and ']' in name:
pattern = name[name.find("[")+1:name.find("]")]
if '-' in pattern:
logger.debug("Found an host with a patterned name: %s", pattern)
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)
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, 16; 6, 20; 6, 53; 6, 60; 7, if_statement; 7, 8; 7, 14; 8, not_operator; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:hasattr; 11, argument_list; 11, 12; 11, 13; 12, identifier:item; 13, string:'contact_groups'; 14, block; 14, 15; 15, return_statement; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:cgnames; 19, string:''; 20, if_statement; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:item; 23, identifier:contact_groups; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 33; 25, 40; 26, call; 26, 27; 26, 28; 27, identifier:isinstance; 28, argument_list; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:item; 31, identifier:contact_groups; 32, identifier:list; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:cgnames; 37, attribute; 37, 38; 37, 39; 38, identifier:item; 39, identifier:contact_groups; 40, else_clause; 40, 41; 41, block; 41, 42; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:cgnames; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:item; 49, identifier:contact_groups; 50, identifier:split; 51, argument_list; 51, 52; 52, string:','; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:cgnames; 56, call; 56, 57; 56, 58; 57, identifier:strip_and_uniq; 58, argument_list; 58, 59; 59, identifier:cgnames; 60, for_statement; 60, 61; 60, 62; 60, 63; 61, identifier:cgname; 62, identifier:cgnames; 63, block; 63, 64; 63, 73; 63, 98; 63, 107; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:contactgroup; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:contactgroups; 70, identifier:find_by_name; 71, argument_list; 71, 72; 72, identifier:cgname; 73, if_statement; 73, 74; 73, 76; 74, not_operator; 74, 75; 75, identifier:contactgroup; 76, block; 76, 77; 76, 97; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:item; 81, identifier:add_error; 82, argument_list; 82, 83; 83, binary_operator:%; 83, 84; 83, 85; 84, string:"The contact group '%s' defined on the %s '%s' do not exist"; 85, tuple; 85, 86; 85, 87; 85, 92; 86, identifier:cgname; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:item; 90, identifier:__class__; 91, identifier:my_type; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:item; 95, identifier:get_name; 96, argument_list; 97, continue_statement; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:cnames; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:contactgroups; 104, identifier:get_members_of_group; 105, argument_list; 105, 106; 106, identifier:cgname; 107, if_statement; 107, 108; 107, 109; 108, identifier:cnames; 109, block; 109, 110; 110, if_statement; 110, 111; 110, 116; 110, 127; 111, call; 111, 112; 111, 113; 112, identifier:hasattr; 113, argument_list; 113, 114; 113, 115; 114, identifier:item; 115, string:'contacts'; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:item; 121, identifier:contacts; 122, binary_operator:+; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:item; 125, identifier:contacts; 126, identifier:cnames; 127, else_clause; 127, 128; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:item; 133, identifier:contacts; 134, identifier:cnames | def explode_contact_groups_into_contacts(item, contactgroups):
if not hasattr(item, 'contact_groups'):
return
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)
if cnames:
if hasattr(item, 'contacts'):
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, 17; 6, 122; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 16; 9, subscript; 9, 10; 9, 15; 10, subscript; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:nodes; 14, identifier:root; 15, string:'dfs_loop_status'; 16, string:'DFS_TEMPORARY_CHECKED'; 17, for_statement; 17, 18; 17, 19; 17, 26; 18, identifier:child; 19, subscript; 19, 20; 19, 25; 20, subscript; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:nodes; 24, identifier:root; 25, string:"sons"; 26, block; 26, 27; 26, 37; 26, 59; 26, 84; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:child_status; 30, subscript; 30, 31; 30, 36; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:nodes; 35, identifier:child; 36, string:'dfs_loop_status'; 37, if_statement; 37, 38; 37, 41; 38, comparison_operator:==; 38, 39; 38, 40; 39, identifier:child_status; 40, string:'DFS_UNCHECKED'; 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:self; 46, identifier:dfs_loop_search; 47, argument_list; 47, 48; 48, identifier:child; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:child_status; 52, subscript; 52, 53; 52, 58; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:nodes; 57, identifier:child; 58, string:'dfs_loop_status'; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:==; 60, 61; 60, 62; 61, identifier:child_status; 62, string:'DFS_TEMPORARY_CHECKED'; 63, block; 63, 64; 63, 74; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 73; 66, subscript; 66, 67; 66, 72; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:nodes; 71, identifier:child; 72, string:'dfs_loop_status'; 73, string:'DFS_LOOP_INSIDE'; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 83; 76, subscript; 76, 77; 76, 82; 77, subscript; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:nodes; 81, identifier:root; 82, string:'dfs_loop_status'; 83, string:'DFS_LOOP_INSIDE'; 84, if_statement; 84, 85; 84, 90; 85, comparison_operator:in; 85, 86; 85, 87; 86, identifier:child_status; 87, tuple; 87, 88; 87, 89; 88, string:'DFS_NEAR_LOOP'; 89, string:'DFS_LOOP_INSIDE'; 90, block; 90, 91; 90, 112; 91, if_statement; 91, 92; 91, 101; 92, comparison_operator:!=; 92, 93; 92, 100; 93, subscript; 93, 94; 93, 99; 94, subscript; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:nodes; 98, identifier:root; 99, string:'dfs_loop_status'; 100, string:'DFS_LOOP_INSIDE'; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 111; 104, subscript; 104, 105; 104, 110; 105, subscript; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:nodes; 109, identifier:root; 110, string:'dfs_loop_status'; 111, string:'DFS_NEAR_LOOP'; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 121; 114, subscript; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:nodes; 119, identifier:child; 120, string:'dfs_loop_status'; 121, string:'DFS_LOOP_INSIDE'; 122, if_statement; 122, 123; 122, 132; 123, comparison_operator:==; 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:root; 130, string:'dfs_loop_status'; 131, string:'DFS_TEMPORARY_CHECKED'; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 142; 135, subscript; 135, 136; 135, 141; 136, subscript; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:nodes; 140, identifier:root; 141, string:'dfs_loop_status'; 142, string:'DFS_OK' | def dfs_loop_search(self, root):
self.nodes[root]['dfs_loop_status'] = 'DFS_TEMPORARY_CHECKED'
for child in self.nodes[root]["sons"]:
child_status = self.nodes[child]['dfs_loop_status']
if child_status == 'DFS_UNCHECKED':
self.dfs_loop_search(child)
child_status = self.nodes[child]['dfs_loop_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 child_status in ('DFS_NEAR_LOOP', 'DFS_LOOP_INSIDE'):
if self.nodes[root]['dfs_loop_status'] != 'DFS_LOOP_INSIDE':
self.nodes[root]['dfs_loop_status'] = 'DFS_NEAR_LOOP'
self.nodes[child]['dfs_loop_status'] = 'DFS_LOOP_INSIDE'
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; 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, block; 13, 14; 13, 20; 13, 30; 13, 34; 13, 38; 13, 42; 13, 46; 13, 321; 13, 329; 13, 370; 13, 376; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:node; 17, call; 17, 18; 17, 19; 18, identifier:DependencyNode; 19, argument_list; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:pattern; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:eval_xof_pattern; 27, argument_list; 27, 28; 27, 29; 28, identifier:node; 29, identifier:pattern; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:in_par; 33, False; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:tmp; 37, string:''; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:son_is_not; 41, False; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:stacked_parenthesis; 45, integer:0; 46, for_statement; 46, 47; 46, 48; 46, 49; 47, identifier:char; 48, identifier:pattern; 49, block; 49, 50; 50, if_statement; 50, 51; 50, 54; 50, 96; 50, 180; 50, 187; 50, 221; 50, 315; 51, comparison_operator:==; 51, 52; 51, 53; 52, identifier:char; 53, string:'('; 54, block; 54, 55; 54, 59; 54, 63; 54, 71; 54, 87; 55, expression_statement; 55, 56; 56, augmented_assignment:+=; 56, 57; 56, 58; 57, identifier:stacked_parenthesis; 58, integer:1; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:in_par; 62, True; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:tmp; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:tmp; 69, identifier:strip; 70, argument_list; 71, if_statement; 71, 72; 71, 79; 72, boolean_operator:and; 72, 73; 72, 76; 73, comparison_operator:==; 73, 74; 73, 75; 74, identifier:stacked_parenthesis; 75, integer:1; 76, comparison_operator:!=; 76, 77; 76, 78; 77, identifier:tmp; 78, string:''; 79, block; 79, 80; 79, 86; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:print; 83, argument_list; 83, 84; 83, 85; 84, string:"ERROR : bad expression near"; 85, identifier:tmp; 86, continue_statement; 87, if_statement; 87, 88; 87, 91; 88, comparison_operator:>; 88, 89; 88, 90; 89, identifier:stacked_parenthesis; 90, integer:1; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, augmented_assignment:+=; 93, 94; 93, 95; 94, identifier:tmp; 95, identifier:char; 96, elif_clause; 96, 97; 96, 100; 97, comparison_operator:==; 97, 98; 97, 99; 98, identifier:char; 99, string:')'; 100, block; 100, 101; 100, 105; 100, 118; 100, 176; 101, expression_statement; 101, 102; 102, augmented_assignment:-=; 102, 103; 102, 104; 103, identifier:stacked_parenthesis; 104, integer:1; 105, if_statement; 105, 106; 105, 109; 106, comparison_operator:<; 106, 107; 106, 108; 107, identifier:stacked_parenthesis; 108, integer:0; 109, block; 109, 110; 109, 117; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:print; 113, argument_list; 113, 114; 113, 115; 113, 116; 114, string:"Error : bad expression near"; 115, identifier:tmp; 116, string:"too much ')'"; 117, continue_statement; 118, if_statement; 118, 119; 118, 122; 119, comparison_operator:==; 119, 120; 119, 121; 120, identifier:stacked_parenthesis; 121, integer:0; 122, block; 122, 123; 122, 131; 122, 145; 122, 158; 122, 167; 122, 171; 122, 175; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:tmp; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:tmp; 129, identifier:strip; 130, argument_list; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:son; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:eval_cor_pattern; 138, argument_list; 138, 139; 138, 140; 138, 141; 138, 142; 138, 143; 138, 144; 139, identifier:tmp; 140, identifier:hosts; 141, identifier:services; 142, identifier:hostgroups; 143, identifier:servicegroups; 144, identifier:running; 145, if_statement; 145, 146; 145, 147; 146, identifier:son_is_not; 147, block; 147, 148; 147, 154; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:son; 152, identifier:not_value; 153, True; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:son_is_not; 157, False; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 165; 160, attribute; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:node; 163, identifier:sons; 164, identifier:append; 165, argument_list; 165, 166; 166, identifier:son; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:in_par; 170, False; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:tmp; 174, string:''; 175, continue_statement; 176, expression_statement; 176, 177; 177, augmented_assignment:+=; 177, 178; 177, 179; 178, identifier:tmp; 179, identifier:char; 180, elif_clause; 180, 181; 180, 182; 181, identifier:in_par; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, augmented_assignment:+=; 184, 185; 184, 186; 185, identifier:tmp; 186, identifier:char; 187, elif_clause; 187, 188; 187, 191; 188, comparison_operator:==; 188, 189; 188, 190; 189, identifier:char; 190, string:'!'; 191, block; 191, 192; 191, 200; 191, 217; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:tmp; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:tmp; 198, identifier:strip; 199, argument_list; 200, if_statement; 200, 201; 200, 208; 201, boolean_operator:and; 201, 202; 201, 203; 202, identifier:tmp; 203, comparison_operator:!=; 203, 204; 203, 207; 204, subscript; 204, 205; 204, 206; 205, identifier:tmp; 206, integer:0; 207, string:'!'; 208, block; 208, 209; 208, 216; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 212; 211, identifier:print; 212, argument_list; 212, 213; 212, 214; 212, 215; 213, string:"Error : bad expression near"; 214, identifier:tmp; 215, string:"wrong position for '!'"; 216, continue_statement; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:son_is_not; 220, True; 221, elif_clause; 221, 222; 221, 227; 222, comparison_operator:in; 222, 223; 222, 224; 223, identifier:char; 224, list:['&', '|']; 224, 225; 224, 226; 225, string:'&'; 226, string:'|'; 227, block; 227, 228; 227, 236; 227, 257; 227, 270; 227, 311; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:tmp; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:tmp; 234, identifier:strip; 235, argument_list; 236, if_statement; 236, 237; 236, 254; 237, boolean_operator:and; 237, 238; 237, 249; 238, boolean_operator:and; 238, 239; 238, 244; 239, comparison_operator:is; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:node; 242, identifier:operand; 243, None; 244, comparison_operator:!=; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:node; 247, identifier:operand; 248, string:'of:'; 249, comparison_operator:!=; 249, 250; 249, 251; 250, identifier:char; 251, attribute; 251, 252; 251, 253; 252, identifier:node; 253, identifier:operand; 254, block; 254, 255; 255, return_statement; 255, 256; 256, None; 257, if_statement; 257, 258; 257, 263; 258, comparison_operator:!=; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:node; 261, identifier:operand; 262, string:'of:'; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:node; 268, identifier:operand; 269, identifier:char; 270, if_statement; 270, 271; 270, 274; 271, comparison_operator:!=; 271, 272; 271, 273; 272, identifier:tmp; 273, string:''; 274, block; 274, 275; 274, 289; 274, 302; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:son; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:eval_cor_pattern; 282, argument_list; 282, 283; 282, 284; 282, 285; 282, 286; 282, 287; 282, 288; 283, identifier:tmp; 284, identifier:hosts; 285, identifier:services; 286, identifier:hostgroups; 287, identifier:servicegroups; 288, identifier:running; 289, if_statement; 289, 290; 289, 291; 290, identifier:son_is_not; 291, block; 291, 292; 291, 298; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:son; 296, identifier:not_value; 297, True; 298, expression_statement; 298, 299; 299, assignment; 299, 300; 299, 301; 300, identifier:son_is_not; 301, False; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 309; 304, attribute; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:node; 307, identifier:sons; 308, identifier:append; 309, argument_list; 309, 310; 310, identifier:son; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:tmp; 314, string:''; 315, else_clause; 315, 316; 316, block; 316, 317; 317, expression_statement; 317, 318; 318, augmented_assignment:+=; 318, 319; 318, 320; 319, identifier:tmp; 320, identifier:char; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:tmp; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:tmp; 327, identifier:strip; 328, argument_list; 329, if_statement; 329, 330; 329, 333; 330, comparison_operator:!=; 330, 331; 330, 332; 331, identifier:tmp; 332, string:''; 333, block; 333, 334; 333, 348; 333, 361; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 337; 336, identifier:son; 337, call; 337, 338; 337, 341; 338, attribute; 338, 339; 338, 340; 339, identifier:self; 340, identifier:eval_cor_pattern; 341, argument_list; 341, 342; 341, 343; 341, 344; 341, 345; 341, 346; 341, 347; 342, identifier:tmp; 343, identifier:hosts; 344, identifier:services; 345, identifier:hostgroups; 346, identifier:servicegroups; 347, identifier:running; 348, if_statement; 348, 349; 348, 350; 349, identifier:son_is_not; 350, block; 350, 351; 350, 357; 351, expression_statement; 351, 352; 352, assignment; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:son; 355, identifier:not_value; 356, True; 357, expression_statement; 357, 358; 358, assignment; 358, 359; 358, 360; 359, identifier:son_is_not; 360, False; 361, expression_statement; 361, 362; 362, call; 362, 363; 362, 368; 363, attribute; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:node; 366, identifier:sons; 367, identifier:append; 368, argument_list; 368, 369; 369, identifier:son; 370, expression_statement; 370, 371; 371, call; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:node; 374, identifier:switch_zeros_of_values; 375, argument_list; 376, return_statement; 376, 377; 377, identifier:node | def eval_complex_cor_pattern(self, pattern, hosts, services,
hostgroups, servicegroups, running=False):
node = DependencyNode()
pattern = self.eval_xof_pattern(node, pattern)
in_par = False
tmp = ''
son_is_not = False
stacked_parenthesis = 0
for char in pattern:
if char == '(':
stacked_parenthesis += 1
in_par = True
tmp = tmp.strip()
if stacked_parenthesis == 1 and tmp != '':
print("ERROR : bad expression near", tmp)
continue
if stacked_parenthesis > 1:
tmp += char
elif char == ')':
stacked_parenthesis -= 1
if stacked_parenthesis < 0:
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)
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
in_par = False
tmp = ''
continue
tmp += char
elif in_par:
tmp += char
elif char == '!':
tmp = tmp.strip()
if tmp and tmp[0] != '!':
print("Error : bad expression near", tmp, "wrong position for '!'")
continue
son_is_not = True
elif char in ['&', '|']:
tmp = tmp.strip()
if node.operand is not None and node.operand != 'of:' and char != node.operand:
return None
if node.operand != 'of:':
node.operand = char
if tmp != '':
son = self.eval_cor_pattern(tmp, hosts, services,
hostgroups, servicegroups, running)
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
tmp = ''
else:
tmp += char
tmp = tmp.strip()
if tmp != '':
son = self.eval_cor_pattern(tmp, hosts, services,
hostgroups, servicegroups, running)
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
node.switch_zeros_of_values()
return node |
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, 14; 6, 18; 6, 27; 6, 34; 6, 38; 6, 225; 6, 233; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:timestamp; 10, call; 10, 11; 10, 12; 11, identifier:int; 12, argument_list; 12, 13; 13, identifier:timestamp; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:original_t; 17, identifier:timestamp; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:res_from_cache; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:find_next_valid_time_from_cache; 25, argument_list; 25, 26; 26, identifier:timestamp; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:res_from_cache; 30, None; 31, block; 31, 32; 32, return_statement; 32, 33; 33, identifier:res_from_cache; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:still_loop; 37, True; 38, while_statement; 38, 39; 38, 40; 39, identifier:still_loop; 40, block; 40, 41; 40, 45; 40, 49; 40, 67; 40, 82; 40, 129; 40, 189; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:local_min; 44, None; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:dr_mins; 48, list:[]; 49, for_statement; 49, 50; 49, 51; 49, 54; 50, identifier:daterange; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:dateranges; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:dr_mins; 59, identifier:append; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:daterange; 64, identifier:get_next_valid_time_from_t; 65, argument_list; 65, 66; 66, identifier:timestamp; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:s_dr_mins; 70, call; 70, 71; 70, 72; 71, identifier:sorted; 72, argument_list; 72, 73; 73, list_comprehension; 73, 74; 73, 75; 73, 78; 74, identifier:d; 75, for_in_clause; 75, 76; 75, 77; 76, identifier:d; 77, identifier:dr_mins; 78, if_clause; 78, 79; 79, comparison_operator:is; 79, 80; 79, 81; 80, identifier:d; 81, None; 82, for_statement; 82, 83; 82, 84; 82, 85; 83, identifier:t01; 84, identifier:s_dr_mins; 85, block; 85, 86; 86, if_statement; 86, 87; 86, 93; 86, 102; 87, boolean_operator:and; 87, 88; 87, 92; 88, not_operator; 88, 89; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:exclude; 92, identifier:still_loop; 93, block; 93, 94; 93, 98; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:local_min; 97, identifier:t01; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:still_loop; 101, False; 102, else_clause; 102, 103; 103, block; 103, 104; 104, for_statement; 104, 105; 104, 106; 104, 109; 105, identifier:timeperiod; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:exclude; 109, block; 109, 110; 110, if_statement; 110, 111; 110, 120; 111, boolean_operator:and; 111, 112; 111, 119; 112, not_operator; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:timeperiod; 116, identifier:is_time_valid; 117, argument_list; 117, 118; 118, identifier:t01; 119, identifier:still_loop; 120, block; 120, 121; 120, 125; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:local_min; 124, identifier:t01; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:still_loop; 128, False; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:is; 130, 131; 130, 132; 131, identifier:local_min; 132, None; 133, block; 133, 134; 133, 138; 133, 163; 133, 178; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:exc_mins; 137, list:[]; 138, if_statement; 138, 139; 138, 142; 139, comparison_operator:!=; 139, 140; 139, 141; 140, identifier:s_dr_mins; 141, list:[]; 142, block; 142, 143; 143, for_statement; 143, 144; 143, 145; 143, 148; 144, identifier:timeperiod; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:exclude; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:exc_mins; 153, identifier:append; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:timeperiod; 158, identifier:get_next_invalid_time_from_t; 159, argument_list; 159, 160; 160, subscript; 160, 161; 160, 162; 161, identifier:s_dr_mins; 162, integer:0; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:s_exc_mins; 166, call; 166, 167; 166, 168; 167, identifier:sorted; 168, argument_list; 168, 169; 169, list_comprehension; 169, 170; 169, 171; 169, 174; 170, identifier:d; 171, for_in_clause; 171, 172; 171, 173; 172, identifier:d; 173, identifier:exc_mins; 174, if_clause; 174, 175; 175, comparison_operator:is; 175, 176; 175, 177; 176, identifier:d; 177, None; 178, if_statement; 178, 179; 178, 182; 179, comparison_operator:!=; 179, 180; 179, 181; 180, identifier:s_exc_mins; 181, list:[]; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:local_min; 186, subscript; 186, 187; 186, 188; 187, identifier:s_exc_mins; 188, integer:0; 189, if_statement; 189, 190; 189, 193; 189, 198; 190, comparison_operator:is; 190, 191; 190, 192; 191, identifier:local_min; 192, None; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:still_loop; 197, False; 198, else_clause; 198, 199; 199, block; 199, 200; 199, 204; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:timestamp; 203, identifier:local_min; 204, if_statement; 204, 205; 204, 216; 205, comparison_operator:>; 205, 206; 205, 207; 206, identifier:timestamp; 207, binary_operator:+; 207, 208; 207, 215; 208, binary_operator:+; 208, 209; 208, 210; 209, identifier:original_t; 210, binary_operator:*; 210, 211; 210, 214; 211, binary_operator:*; 211, 212; 211, 213; 212, integer:3600; 213, integer:24; 214, integer:366; 215, integer:1; 216, block; 216, 217; 216, 221; 217, expression_statement; 217, 218; 218, assignment; 218, 219; 218, 220; 219, identifier:still_loop; 220, False; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:local_min; 224, None; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 232; 227, subscript; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:self; 230, identifier:cache; 231, identifier:original_t; 232, identifier:local_min; 233, return_statement; 233, 234; 234, identifier:local_min | def get_next_valid_time_from_t(self, timestamp):
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
while still_loop:
local_min = None
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:
local_min = t01
still_loop = False
else:
for timeperiod in self.exclude:
if not timeperiod.is_time_valid(t01) and still_loop:
local_min = t01
still_loop = False
if local_min is None:
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
if timestamp > original_t + 3600 * 24 * 366 + 1:
still_loop = False
local_min = None
self.cache[original_t] = local_min
return local_min |
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, 14; 6, 18; 6, 22; 6, 97; 6, 104; 6, 108; 6, 189; 6, 206; 6, 258; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:timestamp; 10, call; 10, 11; 10, 12; 11, identifier:int; 12, argument_list; 12, 13; 13, identifier:timestamp; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:original_t; 17, identifier:timestamp; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:dr_mins; 21, list:[]; 22, for_statement; 22, 23; 22, 24; 22, 27; 23, identifier:daterange; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:dateranges; 27, block; 27, 28; 27, 32; 27, 36; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:timestamp; 31, identifier:original_t; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:cont; 35, True; 36, while_statement; 36, 37; 36, 38; 37, identifier:cont; 38, block; 38, 39; 38, 48; 38, 81; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:start; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:daterange; 45, identifier:get_next_valid_time_from_t; 46, argument_list; 46, 47; 47, identifier:timestamp; 48, if_statement; 48, 49; 48, 52; 48, 75; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:start; 51, None; 52, block; 52, 53; 52, 62; 52, 71; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:end; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:daterange; 59, identifier:get_next_invalid_time_from_t; 60, argument_list; 60, 61; 61, identifier:start; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:dr_mins; 66, identifier:append; 67, argument_list; 67, 68; 68, tuple; 68, 69; 68, 70; 69, identifier:start; 70, identifier:end; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:timestamp; 74, identifier:end; 75, else_clause; 75, 76; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:cont; 80, False; 81, if_statement; 81, 82; 81, 92; 82, comparison_operator:>; 82, 83; 82, 84; 83, identifier:timestamp; 84, binary_operator:+; 84, 85; 84, 86; 85, identifier:original_t; 86, parenthesized_expression; 86, 87; 87, binary_operator:*; 87, 88; 87, 91; 88, binary_operator:*; 88, 89; 88, 90; 89, integer:3600; 90, integer:24; 91, integer:365; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:cont; 96, False; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:periods; 100, call; 100, 101; 100, 102; 101, identifier:merge_periods; 102, argument_list; 102, 103; 103, identifier:dr_mins; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:dr_mins; 107, list:[]; 108, for_statement; 108, 109; 108, 110; 108, 113; 109, identifier:exclude; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:exclude; 113, block; 113, 114; 114, for_statement; 114, 115; 114, 116; 114, 119; 115, identifier:daterange; 116, attribute; 116, 117; 116, 118; 117, identifier:exclude; 118, identifier:dateranges; 119, block; 119, 120; 119, 124; 119, 128; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:timestamp; 123, identifier:original_t; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:cont; 127, True; 128, while_statement; 128, 129; 128, 130; 129, identifier:cont; 130, block; 130, 131; 130, 140; 130, 173; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:start; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:daterange; 137, identifier:get_next_valid_time_from_t; 138, argument_list; 138, 139; 139, identifier:timestamp; 140, if_statement; 140, 141; 140, 144; 140, 167; 141, comparison_operator:is; 141, 142; 141, 143; 142, identifier:start; 143, None; 144, block; 144, 145; 144, 154; 144, 163; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:end; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:daterange; 151, identifier:get_next_invalid_time_from_t; 152, argument_list; 152, 153; 153, identifier:start; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:dr_mins; 158, identifier:append; 159, argument_list; 159, 160; 160, tuple; 160, 161; 160, 162; 161, identifier:start; 162, identifier:end; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:timestamp; 166, identifier:end; 167, else_clause; 167, 168; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:cont; 172, False; 173, if_statement; 173, 174; 173, 184; 174, comparison_operator:>; 174, 175; 174, 176; 175, identifier:timestamp; 176, binary_operator:+; 176, 177; 176, 178; 177, identifier:original_t; 178, parenthesized_expression; 178, 179; 179, binary_operator:*; 179, 180; 179, 183; 180, binary_operator:*; 180, 181; 180, 182; 181, integer:3600; 182, integer:24; 183, integer:365; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:cont; 188, False; 189, if_statement; 189, 190; 189, 192; 189, 197; 190, not_operator; 190, 191; 191, identifier:dr_mins; 192, block; 192, 193; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:periods_exclude; 196, list:[]; 197, else_clause; 197, 198; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 202; 201, identifier:periods_exclude; 202, call; 202, 203; 202, 204; 203, identifier:merge_periods; 204, argument_list; 204, 205; 205, identifier:dr_mins; 206, if_statement; 206, 207; 206, 213; 207, comparison_operator:>=; 207, 208; 207, 212; 208, call; 208, 209; 208, 210; 209, identifier:len; 210, argument_list; 210, 211; 211, identifier:periods; 212, integer:1; 213, block; 213, 214; 213, 225; 213, 252; 214, if_statement; 214, 215; 214, 222; 215, comparison_operator:>; 215, 216; 215, 221; 216, subscript; 216, 217; 216, 220; 217, subscript; 217, 218; 217, 219; 218, identifier:periods; 219, integer:0; 220, integer:0; 221, identifier:original_t; 222, block; 222, 223; 223, return_statement; 223, 224; 224, identifier:original_t; 225, if_statement; 225, 226; 225, 232; 226, comparison_operator:>=; 226, 227; 226, 231; 227, call; 227, 228; 227, 229; 228, identifier:len; 229, argument_list; 229, 230; 230, identifier:periods_exclude; 231, integer:1; 232, block; 232, 233; 233, if_statement; 233, 234; 233, 245; 234, comparison_operator:<; 234, 235; 234, 240; 235, subscript; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:periods_exclude; 238, integer:0; 239, integer:0; 240, subscript; 240, 241; 240, 244; 241, subscript; 241, 242; 241, 243; 242, identifier:periods; 243, integer:0; 244, integer:1; 245, block; 245, 246; 246, return_statement; 246, 247; 247, subscript; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:periods_exclude; 250, integer:0; 251, integer:0; 252, return_statement; 252, 253; 253, subscript; 253, 254; 253, 257; 254, subscript; 254, 255; 254, 256; 255, identifier:periods; 256, integer:0; 257, integer:1; 258, return_statement; 258, 259; 259, identifier:original_t | def get_next_invalid_time_from_t(self, timestamp):
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)
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 periods[0][0] > original_t:
return original_t
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, 10; 5, 29; 5, 71; 5, 147; 5, 161; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:valid; 9, True; 10, for_statement; 10, 11; 10, 12; 10, 22; 11, identifier:timeperiod; 12, call; 12, 13; 12, 14; 13, identifier:list; 14, argument_list; 14, 15; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:items; 20, identifier:values; 21, argument_list; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:timeperiod; 27, identifier:rec_tag; 28, False; 29, for_statement; 29, 30; 29, 31; 29, 41; 30, identifier:timeperiod; 31, call; 31, 32; 31, 33; 32, identifier:list; 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:items; 39, identifier:values; 40, argument_list; 41, block; 41, 42; 41, 61; 42, for_statement; 42, 43; 42, 44; 42, 54; 43, identifier:tmp_tp; 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:items; 52, identifier:values; 53, argument_list; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:tmp_tp; 59, identifier:rec_tag; 60, False; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:valid; 64, boolean_operator:and; 64, 65; 64, 70; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:timeperiod; 68, identifier:check_exclude_rec; 69, argument_list; 70, identifier:valid; 71, for_statement; 71, 72; 71, 73; 71, 83; 72, identifier:timeperiod; 73, call; 73, 74; 73, 75; 74, identifier:list; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:items; 81, identifier:values; 82, argument_list; 83, block; 83, 84; 83, 88; 83, 131; 83, 139; 84, delete_statement; 84, 85; 85, attribute; 85, 86; 85, 87; 86, identifier:timeperiod; 87, identifier:rec_tag; 88, if_statement; 88, 89; 88, 95; 89, not_operator; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:timeperiod; 93, identifier:is_correct; 94, argument_list; 95, block; 95, 96; 95, 100; 95, 109; 95, 124; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:valid; 99, False; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:source; 103, call; 103, 104; 103, 105; 104, identifier:getattr; 105, argument_list; 105, 106; 105, 107; 105, 108; 106, identifier:timeperiod; 107, string:'imported_from'; 108, string:"unknown source"; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:msg; 112, binary_operator:%; 112, 113; 112, 114; 113, string:"Configuration in %s::%s is incorrect; from: %s"; 114, tuple; 114, 115; 114, 118; 114, 123; 115, attribute; 115, 116; 115, 117; 116, identifier:timeperiod; 117, identifier:my_type; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:timeperiod; 121, identifier:get_name; 122, argument_list; 123, identifier:source; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:add_error; 129, argument_list; 129, 130; 130, identifier:msg; 131, expression_statement; 131, 132; 132, augmented_assignment:+=; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:configuration_errors; 136, attribute; 136, 137; 136, 138; 137, identifier:timeperiod; 138, identifier:configuration_errors; 139, expression_statement; 139, 140; 140, augmented_assignment:+=; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:configuration_warnings; 144, attribute; 144, 145; 144, 146; 145, identifier:timeperiod; 146, identifier:configuration_warnings; 147, for_statement; 147, 148; 147, 149; 147, 150; 148, identifier:timeperiod; 149, identifier:self; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:valid; 154, boolean_operator:and; 154, 155; 154, 160; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:timeperiod; 158, identifier:is_correct; 159, argument_list; 160, identifier:valid; 161, return_statement; 161, 162; 162, identifier:valid | def is_correct(self):
valid = True
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
for timeperiod in list(self.items.values()):
del timeperiod.rec_tag
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
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, 11; 6, 28; 6, 32; 6, 36; 6, 40; 6, 86; 6, 90; 6, 97; 6, 104; 6, 111; 6, 117; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:scheduler_links; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:scheduler_link_uuid; 13, attribute; 13, 14; 13, 15; 14, identifier:realm; 15, identifier:schedulers; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:scheduler_links; 21, identifier:append; 22, argument_list; 22, 23; 23, subscript; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:schedulers; 27, identifier:scheduler_link_uuid; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:alive; 31, list:[]; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:spare; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:deads; 39, list:[]; 40, for_statement; 40, 41; 40, 42; 40, 43; 41, identifier:sdata; 42, identifier:scheduler_links; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 53; 44, 61; 44, 77; 45, boolean_operator:and; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:sdata; 48, identifier:alive; 49, not_operator; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:sdata; 52, identifier:spare; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:alive; 58, identifier:append; 59, argument_list; 59, 60; 60, identifier:sdata; 61, elif_clause; 61, 62; 61, 69; 62, boolean_operator:and; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:sdata; 65, identifier:alive; 66, attribute; 66, 67; 66, 68; 67, identifier:sdata; 68, identifier:spare; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:spare; 74, identifier:append; 75, argument_list; 75, 76; 76, identifier:sdata; 77, else_clause; 77, 78; 78, block; 78, 79; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:deads; 83, identifier:append; 84, argument_list; 84, 85; 85, identifier:sdata; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:scheduler_links; 89, list:[]; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:scheduler_links; 94, identifier:extend; 95, argument_list; 95, 96; 96, identifier:alive; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:scheduler_links; 101, identifier:extend; 102, argument_list; 102, 103; 103, identifier:spare; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:scheduler_links; 108, identifier:extend; 109, argument_list; 109, 110; 110, identifier:deads; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:scheduler_links; 115, identifier:reverse; 116, argument_list; 117, return_statement; 117, 118; 118, identifier:scheduler_links | def get_scheduler_ordered_list(self, realm):
scheduler_links = []
for scheduler_link_uuid in realm.schedulers:
scheduler_links.append(self.schedulers[scheduler_link_uuid])
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()
return scheduler_links |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 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, block; 8, 9; 8, 22; 8, 34; 8, 47; 8, 54; 8, 60; 8, 172; 8, 263; 8, 363; 9, if_statement; 9, 10; 9, 14; 10, not_operator; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:new_to_dispatch; 14, block; 14, 15; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:DispatcherError; 18, argument_list; 18, 19; 19, concatenated_string; 19, 20; 19, 21; 20, string:"Dispatcher cannot dispatch, "; 21, string:"because no configuration is prepared!"; 22, if_statement; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:first_dispatch_done; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:DispatcherError; 30, argument_list; 30, 31; 31, concatenated_string; 31, 32; 31, 33; 32, string:"Dispatcher cannot dispatch, "; 33, string:"because the configuration is still dispatched!"; 34, if_statement; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:dispatch_ok; 38, block; 38, 39; 38, 46; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:logger; 43, identifier:info; 44, argument_list; 44, 45; 45, string:"Dispatching is already done and ok..."; 46, return_statement; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:logger; 51, identifier:info; 52, argument_list; 52, 53; 53, string:"Trying to send configuration to the satellites..."; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:dispatch_ok; 59, True; 60, for_statement; 60, 61; 60, 62; 60, 65; 61, identifier:link; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:arbiters; 65, block; 65, 66; 65, 74; 65, 81; 65, 88; 65, 104; 65, 121; 65, 131; 65, 141; 65, 153; 65, 159; 65, 166; 66, if_statement; 66, 67; 66, 72; 67, comparison_operator:==; 67, 68; 67, 69; 68, identifier:link; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:arbiter_link; 72, block; 72, 73; 73, continue_statement; 74, if_statement; 74, 75; 74, 79; 75, not_operator; 75, 76; 76, attribute; 76, 77; 76, 78; 77, identifier:link; 78, identifier:active; 79, block; 79, 80; 80, continue_statement; 81, if_statement; 81, 82; 81, 86; 82, not_operator; 82, 83; 83, attribute; 83, 84; 83, 85; 84, identifier:link; 85, identifier:spare; 86, block; 86, 87; 87, continue_statement; 88, if_statement; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:link; 91, identifier:configuration_sent; 92, block; 92, 93; 92, 103; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:logger; 97, identifier:debug; 98, argument_list; 98, 99; 98, 100; 99, string:"Arbiter %s already sent!"; 100, attribute; 100, 101; 100, 102; 101, identifier:link; 102, identifier:name; 103, continue_statement; 104, if_statement; 104, 105; 104, 109; 105, not_operator; 105, 106; 106, attribute; 106, 107; 106, 108; 107, identifier:link; 108, identifier:reachable; 109, block; 109, 110; 109, 120; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:logger; 114, identifier:debug; 115, argument_list; 115, 116; 115, 117; 116, string:"Arbiter %s is not reachable to receive its configuration"; 117, attribute; 117, 118; 117, 119; 118, identifier:link; 119, identifier:name; 120, continue_statement; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:logger; 125, identifier:info; 126, argument_list; 126, 127; 126, 128; 127, string:"Sending configuration to the arbiter %s"; 128, attribute; 128, 129; 128, 130; 129, identifier:link; 130, identifier:name; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:logger; 135, identifier:debug; 136, argument_list; 136, 137; 136, 138; 137, string:"- %s"; 138, attribute; 138, 139; 138, 140; 139, identifier:link; 140, identifier:cfg; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:link; 145, identifier:put_conf; 146, argument_list; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:link; 149, identifier:cfg; 150, keyword_argument; 150, 151; 150, 152; 151, identifier:test; 152, identifier:test; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:link; 157, identifier:configuration_sent; 158, True; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:logger; 163, identifier:info; 164, argument_list; 164, 165; 165, string:"- sent"; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:link; 170, identifier:do_not_run; 171, argument_list; 172, for_statement; 172, 173; 172, 174; 172, 177; 173, identifier:link; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:schedulers; 177, block; 177, 178; 177, 194; 177, 201; 177, 218; 177, 228; 177, 238; 177, 250; 177, 256; 178, if_statement; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:link; 181, identifier:configuration_sent; 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:debug; 188, argument_list; 188, 189; 188, 190; 189, string:"Scheduler %s already sent!"; 190, attribute; 190, 191; 190, 192; 191, identifier:link; 192, identifier:name; 193, continue_statement; 194, if_statement; 194, 195; 194, 199; 195, not_operator; 195, 196; 196, attribute; 196, 197; 196, 198; 197, identifier:link; 198, identifier:active; 199, block; 199, 200; 200, continue_statement; 201, if_statement; 201, 202; 201, 206; 202, not_operator; 202, 203; 203, attribute; 203, 204; 203, 205; 204, identifier:link; 205, identifier:reachable; 206, block; 206, 207; 206, 217; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:logger; 211, identifier:debug; 212, argument_list; 212, 213; 212, 214; 213, string:"Scheduler %s is not reachable to receive its configuration"; 214, attribute; 214, 215; 214, 216; 215, identifier:link; 216, identifier:name; 217, continue_statement; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:logger; 222, identifier:info; 223, argument_list; 223, 224; 223, 225; 224, string:"Sending configuration to the scheduler %s"; 225, attribute; 225, 226; 225, 227; 226, identifier:link; 227, identifier:name; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:logger; 232, identifier:debug; 233, argument_list; 233, 234; 233, 235; 234, string:"- %s"; 235, attribute; 235, 236; 235, 237; 236, identifier:link; 237, identifier:cfg; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:link; 242, identifier:put_conf; 243, argument_list; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:link; 246, identifier:cfg; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:test; 249, identifier:test; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:link; 254, identifier:configuration_sent; 255, True; 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:"- sent"; 263, for_statement; 263, 264; 263, 265; 263, 268; 264, identifier:link; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:satellites; 268, block; 268, 269; 268, 288; 268, 295; 268, 315; 268, 328; 268, 338; 268, 350; 268, 356; 269, if_statement; 269, 270; 269, 273; 270, attribute; 270, 271; 270, 272; 271, identifier:link; 272, identifier:configuration_sent; 273, block; 273, 274; 273, 287; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:logger; 278, identifier:debug; 279, argument_list; 279, 280; 279, 281; 279, 284; 280, string:"%s %s already sent!"; 281, attribute; 281, 282; 281, 283; 282, identifier:link; 283, identifier:type; 284, attribute; 284, 285; 284, 286; 285, identifier:link; 286, identifier:name; 287, continue_statement; 288, if_statement; 288, 289; 288, 293; 289, not_operator; 289, 290; 290, attribute; 290, 291; 290, 292; 291, identifier:link; 292, identifier:active; 293, block; 293, 294; 294, continue_statement; 295, if_statement; 295, 296; 295, 300; 296, not_operator; 296, 297; 297, attribute; 297, 298; 297, 299; 298, identifier:link; 299, identifier:reachable; 300, block; 300, 301; 300, 314; 301, expression_statement; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:logger; 305, identifier:warning; 306, argument_list; 306, 307; 306, 308; 306, 311; 307, string:"%s %s is not reachable to receive its configuration"; 308, attribute; 308, 309; 308, 310; 309, identifier:link; 310, identifier:type; 311, attribute; 311, 312; 311, 313; 312, identifier:link; 313, identifier:name; 314, continue_statement; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:logger; 319, identifier:info; 320, argument_list; 320, 321; 320, 322; 320, 325; 321, string:"Sending configuration to the %s %s"; 322, attribute; 322, 323; 322, 324; 323, identifier:link; 324, identifier:type; 325, attribute; 325, 326; 325, 327; 326, identifier:link; 327, identifier:name; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:logger; 332, identifier:debug; 333, argument_list; 333, 334; 333, 335; 334, string:"- %s"; 335, attribute; 335, 336; 335, 337; 336, identifier:link; 337, identifier:cfg; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:link; 342, identifier:put_conf; 343, argument_list; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:link; 346, identifier:cfg; 347, keyword_argument; 347, 348; 347, 349; 348, identifier:test; 349, identifier:test; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:link; 354, identifier:configuration_sent; 355, True; 356, expression_statement; 356, 357; 357, call; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:logger; 360, identifier:info; 361, argument_list; 361, 362; 362, string:"- sent"; 363, if_statement; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:dispatch_ok; 367, block; 367, 368; 367, 374; 368, expression_statement; 368, 369; 369, assignment; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:self; 372, identifier:new_to_dispatch; 373, False; 374, expression_statement; 374, 375; 375, assignment; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:self; 378, identifier:first_dispatch_done; 379, True | def dispatch(self, test=False):
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
for link in self.arbiters:
if link == self.arbiter_link:
continue
if not link.active:
continue
if not link.spare:
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")
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:
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:
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:
self.new_to_dispatch = False
self.first_dispatch_done = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 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, block; 7, 8; 7, 12; 7, 25; 7, 34; 7, 41; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:args; 11, None; 12, if_statement; 12, 13; 12, 18; 13, call; 13, 14; 13, 15; 14, identifier:isinstance; 15, argument_list; 15, 16; 15, 17; 16, identifier:prop; 17, identifier:tuple; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, pattern_list; 21, 22; 21, 23; 22, identifier:prop; 23, identifier:args; 24, identifier:prop; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:value; 28, call; 28, 29; 28, 30; 29, identifier:getattr; 30, argument_list; 30, 31; 30, 32; 30, 33; 31, identifier:elt; 32, identifier:prop; 33, None; 34, if_statement; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:value; 37, None; 38, block; 38, 39; 39, return_statement; 39, 40; 40, string:'n/a'; 41, try_statement; 41, 42; 41, 105; 41, 110; 42, block; 42, 43; 42, 59; 42, 71; 42, 79; 42, 83; 42, 99; 43, if_statement; 43, 44; 43, 49; 44, call; 44, 45; 44, 46; 45, identifier:isinstance; 46, argument_list; 46, 47; 46, 48; 47, identifier:value; 48, identifier:list; 49, block; 49, 50; 50, return_statement; 50, 51; 51, binary_operator:%; 51, 52; 51, 53; 52, string:"[%s]"; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, string:','; 56, identifier:join; 57, argument_list; 57, 58; 58, identifier:value; 59, if_statement; 59, 60; 59, 68; 60, not_operator; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:isinstance; 63, argument_list; 63, 64; 63, 65; 64, identifier:value; 65, attribute; 65, 66; 65, 67; 66, identifier:collections; 67, identifier:Callable; 68, block; 68, 69; 69, return_statement; 69, 70; 70, identifier:value; 71, if_statement; 71, 72; 71, 74; 72, not_operator; 72, 73; 73, identifier:args; 74, block; 74, 75; 75, return_statement; 75, 76; 76, call; 76, 77; 76, 78; 77, identifier:value; 78, argument_list; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:real_args; 82, list:[]; 83, for_statement; 83, 84; 83, 85; 83, 86; 84, identifier:arg; 85, identifier:args; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:real_args; 91, identifier:append; 92, argument_list; 92, 93; 93, call; 93, 94; 93, 95; 94, identifier:getattr; 95, argument_list; 95, 96; 95, 97; 95, 98; 96, identifier:self; 97, identifier:arg; 98, None; 99, return_statement; 99, 100; 100, call; 100, 101; 100, 102; 101, identifier:value; 102, argument_list; 102, 103; 103, list_splat; 103, 104; 104, identifier:real_args; 105, except_clause; 105, 106; 105, 107; 106, identifier:AttributeError; 107, block; 107, 108; 108, return_statement; 108, 109; 109, string:'n/a'; 110, except_clause; 110, 111; 110, 112; 111, identifier:UnicodeError; 112, block; 112, 113; 112, 129; 113, if_statement; 113, 114; 113, 119; 114, call; 114, 115; 114, 116; 115, identifier:isinstance; 116, argument_list; 116, 117; 116, 118; 117, identifier:value; 118, identifier:string_types; 119, block; 119, 120; 120, return_statement; 120, 121; 121, call; 121, 122; 121, 123; 122, identifier:str; 123, argument_list; 123, 124; 123, 125; 123, 126; 124, identifier:value; 125, string:'utf8'; 126, keyword_argument; 126, 127; 126, 128; 127, identifier:errors; 128, string:'ignore'; 129, return_statement; 129, 130; 130, string:'n/a' | def _get_value_from_element(self, elt, prop):
args = None
if isinstance(prop, tuple):
prop, args = prop
value = getattr(elt, prop, None)
if value is None:
return 'n/a'
try:
if isinstance(value, list):
return "[%s]" % ','.join(value)
if not isinstance(value, collections.Callable):
return value
if not args:
return value()
real_args = []
for arg in args:
real_args.append(getattr(self, arg, None))
return value(*real_args)
except AttributeError:
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, identifier:r; 9, for_statement; 9, 10; 9, 11; 9, 12; 10, identifier:macro; 11, identifier:macros; 12, block; 12, 13; 12, 131; 13, if_statement; 13, 14; 13, 21; 13, 31; 13, 57; 13, 83; 13, 109; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:re; 17, identifier:match; 18, argument_list; 18, 19; 18, 20; 19, string:r'ARG\d'; 20, identifier:macro; 21, block; 21, 22; 21, 30; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 29; 24, subscript; 24, 25; 24, 28; 25, subscript; 25, 26; 25, 27; 26, identifier:macros; 27, identifier:macro; 28, string:'type'; 29, string:'ARGN'; 30, continue_statement; 31, elif_clause; 31, 32; 31, 39; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:re; 35, identifier:match; 36, argument_list; 36, 37; 36, 38; 37, string:r'_HOST\w'; 38, identifier:macro; 39, block; 39, 40; 39, 48; 39, 56; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 47; 42, subscript; 42, 43; 42, 46; 43, subscript; 43, 44; 43, 45; 44, identifier:macros; 45, identifier:macro; 46, string:'type'; 47, string:'CUSTOM'; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 55; 50, subscript; 50, 51; 50, 54; 51, subscript; 51, 52; 51, 53; 52, identifier:macros; 53, identifier:macro; 54, string:'class'; 55, string:'HOST'; 56, continue_statement; 57, elif_clause; 57, 58; 57, 65; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:re; 61, identifier:match; 62, argument_list; 62, 63; 62, 64; 63, string:r'_SERVICE\w'; 64, identifier:macro; 65, block; 65, 66; 65, 74; 65, 82; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 72; 69, subscript; 69, 70; 69, 71; 70, identifier:macros; 71, identifier:macro; 72, string:'type'; 73, string:'CUSTOM'; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 81; 76, subscript; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:macros; 79, identifier:macro; 80, string:'class'; 81, string:'SERVICE'; 82, continue_statement; 83, elif_clause; 83, 84; 83, 91; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:re; 87, identifier:match; 88, argument_list; 88, 89; 88, 90; 89, string:r'_CONTACT\w'; 90, identifier:macro; 91, block; 91, 92; 91, 100; 91, 108; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 99; 94, subscript; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:macros; 97, identifier:macro; 98, string:'type'; 99, string:'CUSTOM'; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 107; 102, subscript; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:macros; 105, identifier:macro; 106, string:'class'; 107, string:'CONTACT'; 108, continue_statement; 109, elif_clause; 109, 110; 109, 121; 110, comparison_operator:>; 110, 111; 110, 120; 111, call; 111, 112; 111, 113; 112, identifier:len; 113, argument_list; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:macro; 117, identifier:split; 118, argument_list; 118, 119; 119, string:':'; 120, integer:1; 121, block; 121, 122; 121, 130; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 129; 124, subscript; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:macros; 127, identifier:macro; 128, string:'type'; 129, string:'ONDEMAND'; 130, continue_statement; 131, for_statement; 131, 132; 131, 133; 131, 134; 132, identifier:obj; 133, identifier:objs; 134, block; 134, 135; 135, if_statement; 135, 136; 135, 141; 136, comparison_operator:in; 136, 137; 136, 138; 137, identifier:macro; 138, attribute; 138, 139; 138, 140; 139, identifier:obj; 140, identifier:macros; 141, block; 141, 142; 141, 150; 141, 158; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 149; 144, subscript; 144, 145; 144, 148; 145, subscript; 145, 146; 145, 147; 146, identifier:macros; 147, identifier:macro; 148, string:'type'; 149, string:'object'; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 157; 152, subscript; 152, 153; 152, 156; 153, subscript; 153, 154; 153, 155; 154, identifier:macros; 155, identifier:macro; 156, string:'object'; 157, identifier:obj; 158, continue_statement | def _get_type_of_macro(macros, objs):
r
for macro in macros:
if re.match(r'ARG\d', macro):
macros[macro]['type'] = 'ARGN'
continue
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'
continue
elif re.match(r'_CONTACT\w', macro):
macros[macro]['type'] = 'CUSTOM'
macros[macro]['class'] = 'CONTACT'
continue
elif len(macro.split(':')) > 1:
macros[macro]['type'] = 'ONDEMAND'
continue
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; 2, function_name:_resolve_ondemand; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:macro; 6, identifier:data; 7, block; 7, 8; 7, 17; 7, 24; 7, 30; 7, 216; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:elts; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:macro; 14, identifier:split; 15, argument_list; 15, 16; 16, string:':'; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:nb_parts; 20, call; 20, 21; 20, 22; 21, identifier:len; 22, argument_list; 22, 23; 23, identifier:elts; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:macro_name; 27, subscript; 27, 28; 27, 29; 28, identifier:elts; 29, integer:0; 30, if_statement; 30, 31; 30, 34; 30, 122; 31, comparison_operator:==; 31, 32; 31, 33; 32, identifier:nb_parts; 33, integer:3; 34, block; 34, 35; 34, 39; 34, 51; 34, 79; 34, 91; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:val; 38, string:''; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 44; 41, tuple_pattern; 41, 42; 41, 43; 42, identifier:host_name; 43, identifier:service_description; 44, tuple; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:elts; 47, integer:1; 48, subscript; 48, 49; 48, 50; 49, identifier:elts; 50, integer:2; 51, if_statement; 51, 52; 51, 55; 52, comparison_operator:==; 52, 53; 52, 54; 53, identifier:host_name; 54, string:''; 55, block; 55, 56; 56, for_statement; 56, 57; 56, 58; 56, 59; 57, identifier:elt; 58, identifier:data; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 72; 61, boolean_operator:and; 61, 62; 61, 65; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:elt; 64, None; 65, comparison_operator:==; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:elt; 68, identifier:__class__; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:host_class; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:host_name; 76, attribute; 76, 77; 76, 78; 77, identifier:elt; 78, identifier:host_name; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:serv; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:services; 87, identifier:find_srv_by_name_and_hostname; 88, argument_list; 88, 89; 88, 90; 89, identifier:host_name; 90, identifier:service_description; 91, if_statement; 91, 92; 91, 95; 92, comparison_operator:is; 92, 93; 92, 94; 93, identifier:serv; 94, None; 95, block; 95, 96; 95, 102; 95, 110; 95, 120; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:cls; 99, attribute; 99, 100; 99, 101; 100, identifier:serv; 101, identifier:__class__; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:prop; 105, subscript; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:cls; 108, identifier:macros; 109, identifier:macro_name; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:val; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:_get_value_from_element; 117, argument_list; 117, 118; 117, 119; 118, identifier:serv; 119, identifier:prop; 120, return_statement; 120, 121; 121, identifier:val; 122, else_clause; 122, 123; 123, block; 123, 124; 123, 128; 123, 134; 123, 162; 123, 214; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:val; 127, string:''; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:elt_name; 131, subscript; 131, 132; 131, 133; 132, identifier:elts; 133, integer:1; 134, if_statement; 134, 135; 134, 138; 135, comparison_operator:==; 135, 136; 135, 137; 136, identifier:elt_name; 137, string:''; 138, block; 138, 139; 139, for_statement; 139, 140; 139, 141; 139, 142; 140, identifier:elt; 141, identifier:data; 142, block; 142, 143; 143, if_statement; 143, 144; 143, 155; 144, boolean_operator:and; 144, 145; 144, 148; 145, comparison_operator:is; 145, 146; 145, 147; 146, identifier:elt; 147, None; 148, comparison_operator:==; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:elt; 151, identifier:__class__; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:host_class; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:elt_name; 159, attribute; 159, 160; 159, 161; 160, identifier:elt; 161, identifier:host_name; 162, for_statement; 162, 163; 162, 164; 162, 167; 163, identifier:od_list; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:lists_on_demand; 167, block; 167, 168; 167, 174; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:cls; 171, attribute; 171, 172; 171, 173; 172, identifier:od_list; 173, identifier:inner_class; 174, if_statement; 174, 175; 174, 180; 175, comparison_operator:in; 175, 176; 175, 177; 176, identifier:macro_name; 177, attribute; 177, 178; 177, 179; 178, identifier:cls; 179, identifier:macros; 180, block; 180, 181; 180, 189; 180, 198; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:prop; 184, subscript; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:cls; 187, identifier:macros; 188, identifier:macro_name; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:i; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:od_list; 195, identifier:find_by_name; 196, argument_list; 196, 197; 197, identifier:elt_name; 198, if_statement; 198, 199; 198, 202; 199, comparison_operator:is; 199, 200; 199, 201; 200, identifier:i; 201, None; 202, block; 202, 203; 202, 213; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:val; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:_get_value_from_element; 210, argument_list; 210, 211; 210, 212; 211, identifier:i; 212, identifier:prop; 213, break_statement; 214, return_statement; 214, 215; 215, identifier:val; 216, return_statement; 216, 217; 217, string:'n/a' | def _resolve_ondemand(self, macro, data):
elts = macro.split(':')
nb_parts = len(elts)
macro_name = elts[0]
if nb_parts == 3:
val = ''
(host_name, service_description) = (elts[1], elts[2])
if host_name == '':
for elt in data:
if elt is not None and elt.__class__ == self.host_class:
host_name = elt.host_name
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
else:
val = ''
elt_name = elts[1]
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
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)
break
return val
return 'n/a' |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 23; 5, 35; 5, 44; 5, 101; 5, 110; 5, 120; 5, 340; 5, 350; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:sub_directory; 9, string:'alignak.d'; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:dir_name; 13, call; 13, 14; 13, 19; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:os; 17, identifier:path; 18, identifier:dirname; 19, argument_list; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:configuration_file; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:dir_name; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:os; 30, identifier:path; 31, identifier:join; 32, argument_list; 32, 33; 32, 34; 33, identifier:dir_name; 34, identifier:sub_directory; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:cfg_files; 40, list:[self.configuration_file]; 40, 41; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:configuration_file; 44, if_statement; 44, 45; 44, 53; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:os; 49, identifier:path; 50, identifier:exists; 51, argument_list; 51, 52; 52, identifier:dir_name; 53, block; 53, 54; 54, for_statement; 54, 55; 54, 59; 54, 68; 55, pattern_list; 55, 56; 55, 57; 55, 58; 56, identifier:root; 57, identifier:_; 58, identifier:walk_files; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:os; 62, identifier:walk; 63, argument_list; 63, 64; 63, 65; 64, identifier:dir_name; 65, keyword_argument; 65, 66; 65, 67; 66, identifier:followlinks; 67, True; 68, block; 68, 69; 69, for_statement; 69, 70; 69, 71; 69, 72; 70, identifier:found_file; 71, identifier:walk_files; 72, block; 72, 73; 72, 84; 73, if_statement; 73, 74; 73, 82; 74, not_operator; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:re; 78, identifier:search; 79, argument_list; 79, 80; 79, 81; 80, string:r"\.ini$"; 81, identifier:found_file; 82, block; 82, 83; 83, continue_statement; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 91; 86, attribute; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:cfg_files; 90, identifier:append; 91, argument_list; 91, 92; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:os; 96, identifier:path; 97, identifier:join; 98, argument_list; 98, 99; 98, 100; 99, identifier:root; 100, identifier:found_file; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:print; 104, argument_list; 104, 105; 105, binary_operator:%; 105, 106; 105, 107; 106, string:"Loading configuration files: %s "; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:cfg_files; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:config; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:configparser; 118, identifier:ConfigParser; 119, argument_list; 120, try_statement; 120, 121; 120, 273; 120, 308; 121, block; 121, 122; 121, 133; 121, 165; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:config; 128, identifier:read; 129, argument_list; 129, 130; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:cfg_files; 133, if_statement; 133, 134; 133, 141; 134, comparison_operator:==; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:config; 139, identifier:_sections; 140, dictionary; 141, block; 141, 142; 141, 151; 141, 158; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:print; 145, argument_list; 145, 146; 146, binary_operator:%; 146, 147; 146, 148; 147, string:"* bad formatted configuration file: %s "; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:configuration_file; 151, if_statement; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:embedded; 155, block; 155, 156; 156, raise_statement; 156, 157; 157, identifier:ValueError; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:sys; 162, identifier:exit; 163, argument_list; 163, 164; 164, integer:2; 165, for_statement; 165, 166; 165, 167; 165, 174; 166, identifier:section; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:config; 172, identifier:sections; 173, argument_list; 174, block; 174, 175; 174, 187; 175, if_statement; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:self; 178, identifier:verbose; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 183; 182, identifier:print; 183, argument_list; 183, 184; 184, binary_operator:%; 184, 185; 184, 186; 185, string:"- section: %s"; 186, identifier:section; 187, for_statement; 187, 188; 187, 191; 187, 199; 188, tuple_pattern; 188, 189; 188, 190; 189, identifier:key; 190, identifier:value; 191, call; 191, 192; 191, 197; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:config; 196, identifier:items; 197, argument_list; 197, 198; 198, identifier:section; 199, block; 199, 200; 199, 208; 199, 215; 199, 223; 199, 237; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:inner_property; 203, binary_operator:%; 203, 204; 203, 205; 204, string:"%s.%s"; 205, tuple; 205, 206; 205, 207; 206, identifier:section; 207, identifier:key; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:setattr; 211, argument_list; 211, 212; 211, 213; 211, 214; 212, identifier:self; 213, identifier:inner_property; 214, identifier:value; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 222; 217, subscript; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:os; 220, identifier:environ; 221, identifier:inner_property; 222, identifier:value; 223, if_statement; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:verbose; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:print; 231, argument_list; 231, 232; 232, binary_operator:%; 232, 233; 232, 234; 233, string:" %s = %s"; 234, tuple; 234, 235; 234, 236; 235, identifier:inner_property; 236, identifier:value; 237, if_statement; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:self; 240, identifier:export; 241, block; 241, 242; 241, 253; 241, 261; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:inner_property; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:re; 248, identifier:sub; 249, argument_list; 249, 250; 249, 251; 249, 252; 250, string:'[^0-9a-zA-Z]+'; 251, string:'_'; 252, identifier:inner_property; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:inner_property; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:inner_property; 259, identifier:upper; 260, argument_list; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 264; 263, identifier:print; 264, argument_list; 264, 265; 265, binary_operator:%; 265, 266; 265, 267; 266, string:"export %s=%s"; 267, tuple; 267, 268; 267, 269; 268, identifier:inner_property; 269, call; 269, 270; 269, 271; 270, identifier:cmd_quote; 271, argument_list; 271, 272; 272, identifier:value; 273, except_clause; 273, 274; 273, 280; 274, as_pattern; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:configparser; 277, identifier:ParsingError; 278, as_pattern_target; 278, 279; 279, identifier:exp; 280, block; 280, 281; 280, 294; 280, 301; 281, expression_statement; 281, 282; 282, call; 282, 283; 282, 284; 283, identifier:print; 284, argument_list; 284, 285; 285, binary_operator:%; 285, 286; 285, 287; 286, string:"* parsing error in config file : %s\n%s"; 287, tuple; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:configuration_file; 291, attribute; 291, 292; 291, 293; 292, identifier:exp; 293, identifier:message; 294, if_statement; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:self; 297, identifier:embedded; 298, block; 298, 299; 299, return_statement; 299, 300; 300, False; 301, expression_statement; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:sys; 305, identifier:exit; 306, argument_list; 306, 307; 307, integer:3; 308, except_clause; 308, 309; 308, 315; 309, as_pattern; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, identifier:configparser; 312, identifier:InterpolationMissingOptionError; 313, as_pattern_target; 313, 314; 314, identifier:exp; 315, block; 315, 316; 315, 326; 315, 333; 316, expression_statement; 316, 317; 317, call; 317, 318; 317, 319; 318, identifier:print; 319, argument_list; 319, 320; 320, binary_operator:%; 320, 321; 320, 322; 321, string:"* incorrect or missing variable: %s"; 322, call; 322, 323; 322, 324; 323, identifier:str; 324, argument_list; 324, 325; 325, identifier:exp; 326, if_statement; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:self; 329, identifier:embedded; 330, block; 330, 331; 331, return_statement; 331, 332; 332, False; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:sys; 337, identifier:exit; 338, argument_list; 338, 339; 339, integer:3; 340, if_statement; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:self; 343, identifier:verbose; 344, block; 344, 345; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 348; 347, identifier:print; 348, argument_list; 348, 349; 349, string:"Configuration file parsed correctly"; 350, return_statement; 350, 351; 351, True | def parse(self):
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)
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)
setattr(self, inner_property, value)
os.environ[inner_property] = value
if self.verbose:
print(" %s = %s" % (inner_property, value))
if self.export:
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, 46; 14, 114; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:name; 18, None; 19, block; 19, 20; 19, 31; 19, 44; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:sections; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_search_sections; 27, argument_list; 27, 28; 28, binary_operator:+; 28, 29; 28, 30; 29, string:'module.'; 30, identifier:name; 31, if_statement; 31, 32; 31, 37; 32, comparison_operator:in; 32, 33; 32, 36; 33, binary_operator:+; 33, 34; 33, 35; 34, string:'module.'; 35, identifier:name; 36, identifier:sections; 37, block; 37, 38; 38, return_statement; 38, 39; 39, subscript; 39, 40; 39, 41; 40, identifier:sections; 41, binary_operator:+; 41, 42; 41, 43; 42, string:'module.'; 43, identifier:name; 44, return_statement; 44, 45; 45, dictionary; 46, if_statement; 46, 47; 46, 50; 47, comparison_operator:is; 47, 48; 47, 49; 48, identifier:daemon_name; 49, None; 50, block; 50, 51; 50, 60; 50, 112; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:section; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:get_daemons; 58, argument_list; 58, 59; 59, identifier:daemon_name; 60, if_statement; 60, 61; 60, 68; 61, boolean_operator:and; 61, 62; 61, 65; 62, comparison_operator:in; 62, 63; 62, 64; 63, string:'modules'; 64, identifier:section; 65, subscript; 65, 66; 65, 67; 66, identifier:section; 67, string:'modules'; 68, block; 68, 69; 68, 73; 68, 110; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:modules; 72, list:[]; 73, for_statement; 73, 74; 73, 75; 73, 83; 74, identifier:module_name; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, subscript; 77, 78; 77, 79; 78, identifier:section; 79, string:'modules'; 80, identifier:split; 81, argument_list; 81, 82; 82, string:','; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 86; 84, 94; 85, identifier:names_only; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, call; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:modules; 91, identifier:append; 92, argument_list; 92, 93; 93, identifier:module_name; 94, else_clause; 94, 95; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:modules; 100, identifier:append; 101, argument_list; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:get_modules; 106, argument_list; 106, 107; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:name; 109, identifier:module_name; 110, return_statement; 110, 111; 111, identifier:modules; 112, return_statement; 112, 113; 113, list:[]; 114, return_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:_search_sections; 119, argument_list; 119, 120; 120, string:'module.' | def get_modules(self, name=None, daemon_name=None, names_only=True):
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, 23; 9, 44; 9, 50; 9, 63; 9, 69; 9, 75; 9, 79; 9, 127; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:logger; 14, identifier:debug; 15, argument_list; 15, 16; 15, 17; 15, 20; 16, string:"Daemon connection initialization: %s %s"; 17, attribute; 17, 18; 17, 19; 18, identifier:s_link; 19, identifier:type; 20, attribute; 20, 21; 20, 22; 21, identifier:s_link; 22, identifier:name; 23, if_statement; 23, 24; 23, 28; 24, not_operator; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:s_link; 27, identifier:active; 28, block; 28, 29; 28, 42; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:logger; 33, identifier:warning; 34, argument_list; 34, 35; 34, 36; 34, 39; 35, string:"%s '%s' is not active, do not initialize its connection!"; 36, attribute; 36, 37; 36, 38; 37, identifier:s_link; 38, identifier:type; 39, attribute; 39, 40; 39, 41; 40, identifier:s_link; 41, identifier:name; 42, return_statement; 42, 43; 43, False; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:s_link; 48, identifier:create_connection; 49, argument_list; 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; 55, 60; 56, string:"[%s] Getting running identifier for '%s'"; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:name; 60, attribute; 60, 61; 60, 62; 61, identifier:s_link; 62, identifier:name; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:s_link; 67, identifier:alive; 68, True; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:s_link; 73, identifier:reachable; 74, True; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:got_a_running_id; 78, None; 79, for_statement; 79, 80; 79, 81; 79, 88; 80, identifier:_; 81, call; 81, 82; 81, 83; 82, identifier:range; 83, argument_list; 83, 84; 83, 85; 84, integer:0; 85, attribute; 85, 86; 85, 87; 86, identifier:s_link; 87, identifier:max_check_attempts; 88, block; 88, 89; 88, 97; 88, 120; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:got_a_running_id; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:s_link; 95, identifier:get_running_id; 96, argument_list; 97, if_statement; 97, 98; 97, 99; 98, identifier:got_a_running_id; 99, block; 99, 100; 99, 110; 99, 119; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:s_link; 104, identifier:last_connection; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:time; 108, identifier:time; 109, argument_list; 110, if_statement; 110, 111; 110, 112; 111, identifier:set_wait_new_conf; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:s_link; 117, identifier:wait_new_conf; 118, argument_list; 119, break_statement; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:time; 124, identifier:sleep; 125, argument_list; 125, 126; 126, float:0.3; 127, return_statement; 127, 128; 128, identifier:got_a_running_id | def daemon_connection_init(self, s_link, set_wait_new_conf=False):
logger.debug("Daemon connection initialization: %s %s", s_link.type, s_link.name)
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
s_link.create_connection()
logger.debug("[%s] Getting running identifier for '%s'", self.name, s_link.name)
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, 21; 8, 27; 8, 33; 8, 39; 8, 74; 8, 80; 8, 97; 8, 107; 8, 114; 8, 136; 8, 144; 8, 152; 8, 159; 9, if_statement; 9, 10; 9, 11; 10, identifier:set_proc_title; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:set_proctitle; 17, argument_list; 17, 18; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:name; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:change_to_user_group; 26, argument_list; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:change_to_workdir; 32, argument_list; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:check_parallel_run; 38, argument_list; 39, if_statement; 39, 40; 39, 43; 39, 61; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:is_daemon; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 51; 45, not_operator; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:daemonize; 50, argument_list; 51, block; 51, 52; 51, 59; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:logger; 56, identifier:error; 57, argument_list; 57, 58; 58, string:"I could not daemonize myself :("; 59, return_statement; 59, 60; 60, False; 61, else_clause; 61, 62; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:write_pid; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:os; 72, identifier:getpid; 73, argument_list; 74, expression_statement; 74, 75; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:setup_alignak_logger; 79, argument_list; 80, if_statement; 80, 81; 80, 87; 81, not_operator; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:setup_communication_daemon; 86, argument_list; 87, block; 87, 88; 87, 95; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:logger; 92, identifier:error; 93, argument_list; 93, 94; 94, string:"I could not setup my communication daemon :("; 95, return_statement; 95, 96; 96, False; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:sync_manager; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_create_manager; 106, argument_list; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:logger; 111, identifier:info; 112, argument_list; 112, 113; 113, string:"Starting http_daemon thread"; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:http_thread; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:threading; 122, identifier:Thread; 123, argument_list; 123, 124; 123, 129; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:target; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:http_daemon_thread; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:name; 131, binary_operator:%; 131, 132; 131, 133; 132, string:'%s-http_thread'; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:name; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:http_thread; 142, identifier:daemon; 143, True; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:self; 149, identifier:http_thread; 150, identifier:start; 151, argument_list; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:logger; 156, identifier:info; 157, argument_list; 157, 158; 158, string:"HTTP daemon thread started"; 159, return_statement; 159, 160; 160, True | def do_daemon_init_and_start(self, set_proc_title=True):
if set_proc_title:
self.set_proctitle(self.name)
self.change_to_user_group()
self.change_to_workdir()
self.check_parallel_run()
if self.is_daemon:
if not self.daemonize():
logger.error("I could not daemonize myself :(")
return False
else:
self.write_pid(os.getpid())
self.setup_alignak_logger()
if not self.setup_communication_daemon():
logger.error("I could not setup my communication daemon :(")
return False
self.sync_manager = self._create_manager()
logger.info("Starting http_daemon thread")
self.http_thread = threading.Thread(target=self.http_daemon_thread,
name='%s-http_thread' % self.name)
self.http_thread.daemon = True
self.http_thread.start()
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, 21; 11, 42; 11, 50; 11, 58; 11, 66; 11, 72; 11, 81; 11, 90; 11, 94; 11, 106; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:==; 13, 14; 13, 15; 14, identifier:timeout; 15, integer:0; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:timeout; 20, float:0.0001; 21, if_statement; 21, 22; 21, 24; 22, not_operator; 22, 23; 23, identifier:check_time_change; 24, block; 24, 25; 24, 32; 24, 38; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:time; 29, identifier:sleep; 30, argument_list; 30, 31; 31, identifier:timeout; 32, expression_statement; 32, 33; 33, augmented_assignment:+=; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:sleep_time; 37, identifier:timeout; 38, return_statement; 38, 39; 39, expression_list; 39, 40; 39, 41; 40, integer:0; 41, integer:0; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:before; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:time; 48, identifier:time; 49, argument_list; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:time_changed; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:check_for_system_time_change; 57, argument_list; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:after; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:time; 64, identifier:time; 65, argument_list; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:elapsed; 69, binary_operator:-; 69, 70; 69, 71; 70, identifier:after; 71, identifier:before; 72, if_statement; 72, 73; 72, 76; 73, comparison_operator:>; 73, 74; 73, 75; 74, identifier:elapsed; 75, identifier:timeout; 76, block; 76, 77; 77, return_statement; 77, 78; 78, expression_list; 78, 79; 78, 80; 79, identifier:elapsed; 80, identifier:time_changed; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:time; 85, identifier:sleep; 86, argument_list; 86, 87; 87, binary_operator:-; 87, 88; 87, 89; 88, identifier:timeout; 89, identifier:elapsed; 90, expression_statement; 90, 91; 91, augmented_assignment:+=; 91, 92; 91, 93; 92, identifier:before; 93, identifier:time_changed; 94, expression_statement; 94, 95; 95, augmented_assignment:+=; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:sleep_time; 99, binary_operator:-; 99, 100; 99, 105; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:time; 103, identifier:time; 104, argument_list; 105, identifier:before; 106, return_statement; 106, 107; 107, expression_list; 107, 108; 107, 109; 108, identifier:elapsed; 109, identifier:time_changed | def make_a_pause(self, timeout=0.0001, check_time_change=True):
if timeout == 0:
timeout = 0.0001
if not check_time_change:
time.sleep(timeout)
self.sleep_time += timeout
return 0, 0
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.sleep(timeout - elapsed)
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; 2, function_name:explode_hostgroup; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:svc_dep; 6, identifier:hostgroups; 7, block; 7, 8; 7, 27; 7, 46; 7, 65; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:snames; 11, list_comprehension; 11, 12; 11, 17; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:d; 15, identifier:strip; 16, argument_list; 17, for_in_clause; 17, 18; 17, 19; 18, identifier:d; 19, call; 19, 20; 19, 25; 20, attribute; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:svc_dep; 23, identifier:service_description; 24, identifier:split; 25, argument_list; 25, 26; 26, string:','; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:dep_snames; 30, list_comprehension; 30, 31; 30, 36; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:d; 34, identifier:strip; 35, argument_list; 36, for_in_clause; 36, 37; 36, 38; 37, identifier:d; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:svc_dep; 42, identifier:dependent_service_description; 43, identifier:split; 44, argument_list; 44, 45; 45, string:','; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:hg_names; 49, list_comprehension; 49, 50; 49, 55; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:n; 53, identifier:strip; 54, argument_list; 55, for_in_clause; 55, 56; 55, 57; 56, identifier:n; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:svc_dep; 61, identifier:hostgroup_name; 62, identifier:split; 63, argument_list; 63, 64; 64, string:','; 65, for_statement; 65, 66; 65, 67; 65, 68; 66, identifier:hg_name; 67, identifier:hg_names; 68, block; 68, 69; 68, 78; 68, 97; 68, 101; 68, 120; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:hostgroup; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:hostgroups; 75, identifier:find_by_name; 76, argument_list; 76, 77; 77, identifier:hg_name; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:is; 79, 80; 79, 81; 80, identifier:hostgroup; 81, None; 82, block; 82, 83; 82, 89; 82, 96; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:err; 86, binary_operator:%; 86, 87; 86, 88; 87, string:"ERROR: the servicedependecy got an unknown hostgroup_name '%s'"; 88, identifier:hg_name; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:add_error; 94, argument_list; 94, 95; 95, identifier:err; 96, continue_statement; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:hnames; 100, list:[]; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:hnames; 105, identifier:extend; 106, argument_list; 106, 107; 107, list_comprehension; 107, 108; 107, 113; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:m; 111, identifier:strip; 112, argument_list; 113, for_in_clause; 113, 114; 113, 115; 114, identifier:m; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:hostgroup; 118, identifier:get_hosts; 119, argument_list; 120, for_statement; 120, 121; 120, 122; 120, 123; 121, identifier:hname; 122, identifier:hnames; 123, block; 123, 124; 124, for_statement; 124, 125; 124, 126; 124, 127; 125, identifier:dep_sname; 126, identifier:dep_snames; 127, block; 127, 128; 128, for_statement; 128, 129; 128, 130; 128, 131; 129, identifier:sname; 130, identifier:snames; 131, block; 131, 132; 131, 140; 131, 146; 131, 152; 131, 158; 131, 164; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:new_sd; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:svc_dep; 138, identifier:copy; 139, argument_list; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:new_sd; 144, identifier:host_name; 145, identifier:hname; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:new_sd; 150, identifier:service_description; 151, identifier:sname; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:new_sd; 156, identifier:dependent_host_name; 157, identifier:hname; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:new_sd; 162, identifier:dependent_service_description; 163, identifier:dep_sname; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:add_item; 169, argument_list; 169, 170; 170, identifier:new_sd | def explode_hostgroup(self, svc_dep, hostgroups):
snames = [d.strip() for d in svc_dep.service_description.split(',')]
dep_snames = [d.strip() for d in svc_dep.dependent_service_description.split(',')]
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, 12; 7, 18; 7, 24; 7, 234; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:to_del; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:errors; 15, attribute; 15, 16; 15, 17; 16, identifier:self; 17, identifier:configuration_errors; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:warns; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:configuration_warnings; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:servicedep; 26, identifier:self; 27, block; 27, 28; 28, try_statement; 28, 29; 28, 212; 29, block; 29, 30; 29, 36; 29, 42; 29, 52; 29, 113; 29, 121; 29, 127; 29, 133; 29, 143; 29, 204; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:s_name; 33, attribute; 33, 34; 33, 35; 34, identifier:servicedep; 35, identifier:dependent_service_description; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:hst_name; 39, attribute; 39, 40; 39, 41; 40, identifier:servicedep; 41, identifier:dependent_host_name; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:serv; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:services; 48, identifier:find_srv_by_name_and_hostname; 49, argument_list; 49, 50; 49, 51; 50, identifier:hst_name; 51, identifier:s_name; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:is; 53, 54; 53, 55; 54, identifier:serv; 55, None; 56, block; 56, 57; 56, 66; 56, 105; 56, 112; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:host; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:hosts; 63, identifier:find_by_name; 64, argument_list; 64, 65; 65, identifier:hst_name; 66, if_statement; 66, 67; 66, 77; 66, 89; 67, not_operator; 67, 68; 68, parenthesized_expression; 68, 69; 69, boolean_operator:and; 69, 70; 69, 71; 70, identifier:host; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:host; 74, identifier:is_excluded_for_sdesc; 75, argument_list; 75, 76; 76, identifier:s_name; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:errors; 82, identifier:append; 83, argument_list; 83, 84; 84, binary_operator:%; 84, 85; 84, 86; 85, string:"Service %s not found for host %s"; 86, tuple; 86, 87; 86, 88; 87, identifier:s_name; 88, identifier:hst_name; 89, elif_clause; 89, 90; 89, 91; 90, identifier:host; 91, block; 91, 92; 92, expression_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:warns; 96, identifier:append; 97, argument_list; 97, 98; 98, binary_operator:%; 98, 99; 98, 102; 99, concatenated_string; 99, 100; 99, 101; 100, string:"Service %s is excluded from host %s ; "; 101, string:"removing this servicedependency as it's unusuable."; 102, tuple; 102, 103; 102, 104; 103, identifier:s_name; 104, identifier:hst_name; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:to_del; 109, identifier:append; 110, argument_list; 110, 111; 111, identifier:servicedep; 112, continue_statement; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:servicedep; 117, identifier:dependent_service_description; 118, attribute; 118, 119; 118, 120; 119, identifier:serv; 120, identifier:uuid; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:s_name; 124, attribute; 124, 125; 124, 126; 125, identifier:servicedep; 126, identifier:service_description; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:hst_name; 130, attribute; 130, 131; 130, 132; 131, identifier:servicedep; 132, identifier:host_name; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:serv; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:services; 139, identifier:find_srv_by_name_and_hostname; 140, argument_list; 140, 141; 140, 142; 141, identifier:hst_name; 142, identifier:s_name; 143, if_statement; 143, 144; 143, 147; 144, comparison_operator:is; 144, 145; 144, 146; 145, identifier:serv; 146, None; 147, block; 147, 148; 147, 157; 147, 196; 147, 203; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:host; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:hosts; 154, identifier:find_by_name; 155, argument_list; 155, 156; 156, identifier:hst_name; 157, if_statement; 157, 158; 157, 168; 157, 180; 158, not_operator; 158, 159; 159, parenthesized_expression; 159, 160; 160, boolean_operator:and; 160, 161; 160, 162; 161, identifier:host; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:host; 165, identifier:is_excluded_for_sdesc; 166, argument_list; 166, 167; 167, identifier:s_name; 168, block; 168, 169; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:errors; 173, identifier:append; 174, argument_list; 174, 175; 175, binary_operator:%; 175, 176; 175, 177; 176, string:"Service %s not found for host %s"; 177, tuple; 177, 178; 177, 179; 178, identifier:s_name; 179, identifier:hst_name; 180, elif_clause; 180, 181; 180, 182; 181, identifier:host; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:warns; 187, identifier:append; 188, argument_list; 188, 189; 189, binary_operator:%; 189, 190; 189, 193; 190, concatenated_string; 190, 191; 190, 192; 191, string:"Service %s is excluded from host %s ; "; 192, string:"removing this servicedependency as it's unusuable."; 193, tuple; 193, 194; 193, 195; 194, identifier:s_name; 195, identifier:hst_name; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:to_del; 200, identifier:append; 201, argument_list; 201, 202; 202, identifier:servicedep; 203, continue_statement; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:servicedep; 208, identifier:service_description; 209, attribute; 209, 210; 209, 211; 210, identifier:serv; 211, identifier:uuid; 212, except_clause; 212, 213; 212, 217; 213, as_pattern; 213, 214; 213, 215; 214, identifier:AttributeError; 215, as_pattern_target; 215, 216; 216, identifier:err; 217, block; 217, 218; 217, 227; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:logger; 222, identifier:error; 223, argument_list; 223, 224; 223, 225; 223, 226; 224, string:"[servicedependency] fail to linkify by service %s: %s"; 225, identifier:servicedep; 226, identifier:err; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:to_del; 231, identifier:append; 232, argument_list; 232, 233; 233, identifier:servicedep; 234, for_statement; 234, 235; 234, 236; 234, 237; 235, identifier:servicedep; 236, identifier:to_del; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:remove_item; 243, argument_list; 243, 244; 244, identifier:servicedep | def linkify_sd_by_s(self, hosts, services):
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
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
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; 2, function_name:init; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 21; 5, 48; 5, 291; 6, if_statement; 6, 7; 6, 11; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:enabled; 11, block; 11, 12; 11, 19; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:logger; 16, identifier:info; 17, argument_list; 17, 18; 18, string:" the module is disabled."; 19, return_statement; 19, 20; 20, True; 21, try_statement; 21, 22; 21, 31; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:connections; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:test_connection; 30, argument_list; 31, except_clause; 31, 32; 31, 36; 32, as_pattern; 32, 33; 32, 34; 33, identifier:Exception; 34, as_pattern_target; 34, 35; 35, identifier:exp; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:logger; 41, identifier:error; 42, argument_list; 42, 43; 42, 44; 43, string:"initialization, test connection failed. Error: %s"; 44, call; 44, 45; 44, 46; 45, identifier:str; 46, argument_list; 46, 47; 47, identifier:exp; 48, if_statement; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:influxdb_enabled; 52, block; 52, 53; 53, try_statement; 53, 54; 53, 274; 54, block; 54, 55; 54, 65; 54, 115; 54, 197; 54, 268; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:dbs; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:influx; 63, identifier:get_list_database; 64, argument_list; 65, for_statement; 65, 66; 65, 67; 65, 68; 65, 92; 66, identifier:db; 67, identifier:dbs; 68, block; 68, 69; 69, if_statement; 69, 70; 69, 80; 70, comparison_operator:==; 70, 71; 70, 77; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:db; 74, identifier:get; 75, argument_list; 75, 76; 76, string:'name'; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:influxdb_database; 80, block; 80, 81; 80, 91; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:logger; 85, identifier:info; 86, argument_list; 86, 87; 86, 88; 87, string:"the database %s is existing."; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:influxdb_database; 91, break_statement; 92, else_clause; 92, 93; 93, block; 93, 94; 93, 104; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:logger; 98, identifier:info; 99, argument_list; 99, 100; 99, 101; 100, string:"creating database %s..."; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:influxdb_database; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:influx; 110, identifier:create_database; 111, argument_list; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:influxdb_database; 115, if_statement; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:influxdb_retention_name; 119, block; 119, 120; 119, 130; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:rps; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:influx; 128, identifier:get_list_retention_policies; 129, argument_list; 130, for_statement; 130, 131; 130, 132; 130, 133; 130, 157; 131, identifier:rp; 132, identifier:rps; 133, block; 133, 134; 134, if_statement; 134, 135; 134, 145; 135, comparison_operator:==; 135, 136; 135, 142; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:rp; 139, identifier:get; 140, argument_list; 140, 141; 141, string:'name'; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:influxdb_retention_name; 145, block; 145, 146; 145, 156; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:logger; 150, identifier:info; 151, argument_list; 151, 152; 151, 153; 152, string:"the retention policy %s is existing."; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:influxdb_retention_name; 156, break_statement; 157, else_clause; 157, 158; 158, block; 158, 159; 158, 175; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:logger; 163, identifier:info; 164, argument_list; 164, 165; 164, 166; 164, 169; 164, 172; 165, string:"creating database retention policy: %s - %s - %s..."; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:influxdb_retention_name; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:influxdb_retention_duration; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:influxdb_retention_replication; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 182; 177, attribute; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:influx; 181, identifier:create_retention_policy; 182, argument_list; 182, 183; 182, 186; 182, 189; 182, 192; 183, attribute; 183, 184; 183, 185; 184, identifier:self; 185, identifier:influxdb_retention_name; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:influxdb_retention_duration; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:influxdb_retention_replication; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:database; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:influxdb_database; 197, if_statement; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:influxdb_username; 201, block; 201, 202; 201, 212; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:users; 205, call; 205, 206; 205, 211; 206, attribute; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:influx; 210, identifier:get_list_users; 211, argument_list; 212, for_statement; 212, 213; 212, 214; 212, 215; 212, 239; 213, identifier:user; 214, identifier:users; 215, block; 215, 216; 216, if_statement; 216, 217; 216, 227; 217, comparison_operator:==; 217, 218; 217, 224; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:user; 221, identifier:get; 222, argument_list; 222, 223; 223, string:'user'; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:influxdb_username; 227, block; 227, 228; 227, 238; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:logger; 232, identifier:info; 233, argument_list; 233, 234; 233, 235; 234, string:"the user %s is existing."; 235, attribute; 235, 236; 235, 237; 236, identifier:self; 237, identifier:influxdb_username; 238, break_statement; 239, else_clause; 239, 240; 240, block; 240, 241; 240, 251; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:logger; 245, identifier:info; 246, argument_list; 246, 247; 246, 248; 247, string:"creating user: %s..."; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:influxdb_username; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 258; 253, attribute; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:influx; 257, identifier:create_user; 258, argument_list; 258, 259; 258, 262; 258, 265; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:influxdb_username; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:influxdb_password; 265, keyword_argument; 265, 266; 265, 267; 266, identifier:admin; 267, False; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:connections; 271, boolean_operator:or; 271, 272; 271, 273; 272, identifier:connections; 273, True; 274, except_clause; 274, 275; 274, 279; 275, as_pattern; 275, 276; 275, 277; 276, identifier:Exception; 277, as_pattern_target; 277, 278; 278, identifier:exp; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:logger; 284, identifier:error; 285, argument_list; 285, 286; 285, 287; 286, string:"InfluxDB, DB initialization failed. Error: %s"; 287, call; 287, 288; 287, 289; 288, identifier:str; 289, argument_list; 289, 290; 290, identifier:exp; 291, return_statement; 291, 292; 292, identifier:connections | def init(self):
if not self.enabled:
logger.info(" the module is disabled.")
return True
try:
connections = self.test_connection()
except Exception as exp:
logger.error("initialization, test connection failed. Error: %s", str(exp))
if self.influxdb_enabled:
try:
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:
logger.info("creating database %s...", self.influxdb_database)
self.influx.create_database(self.influxdb_database)
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:
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)
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:
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:
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, 12; 7, 19; 7, 189; 7, 198; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:result; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:metrics; 15, call; 15, 16; 15, 17; 16, identifier:PerfDatas; 17, argument_list; 17, 18; 18, identifier:perf_data; 19, for_statement; 19, 20; 19, 21; 19, 22; 20, identifier:metric; 21, identifier:metrics; 22, block; 22, 23; 22, 35; 22, 49; 22, 58; 22, 70; 22, 75; 22, 91; 22, 110; 22, 129; 22, 148; 22, 167; 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, 31; 28, 32; 29, string:"service: %s, metric: %s (%s)"; 30, identifier:service; 31, identifier:metric; 32, attribute; 32, 33; 32, 34; 33, identifier:metric; 34, identifier:__dict__; 35, if_statement; 35, 36; 35, 42; 36, comparison_operator:in; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:metric; 39, identifier:name; 40, list:['time']; 40, 41; 41, string:'time'; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:metric; 47, identifier:name; 48, string:"duration"; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:name; 52, call; 52, 53; 52, 54; 53, identifier:sanitize_name; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:metric; 57, identifier:name; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:name; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:multiple_values; 66, identifier:sub; 67, argument_list; 67, 68; 67, 69; 68, string:r'.\1'; 69, identifier:name; 70, if_statement; 70, 71; 70, 73; 71, not_operator; 71, 72; 72, identifier:name; 73, block; 73, 74; 74, continue_statement; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:name_value; 78, dictionary; 78, 79; 78, 84; 79, pair; 79, 80; 79, 81; 80, identifier:name; 81, attribute; 81, 82; 81, 83; 82, identifier:metric; 83, identifier:value; 84, pair; 84, 85; 84, 88; 85, binary_operator:+; 85, 86; 85, 87; 86, string:'uom_'; 87, identifier:name; 88, attribute; 88, 89; 88, 90; 89, identifier:metric; 90, identifier:uom; 91, if_statement; 91, 92; 91, 99; 92, boolean_operator:and; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:metric; 95, identifier:warning; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:send_warning; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 107; 102, subscript; 102, 103; 102, 104; 103, identifier:name_value; 104, binary_operator:+; 104, 105; 104, 106; 105, identifier:name; 106, string:'_warn'; 107, attribute; 107, 108; 107, 109; 108, identifier:metric; 109, identifier:warning; 110, if_statement; 110, 111; 110, 118; 111, boolean_operator:and; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:metric; 114, identifier:critical; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:send_critical; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 126; 121, subscript; 121, 122; 121, 123; 122, identifier:name_value; 123, binary_operator:+; 123, 124; 123, 125; 124, identifier:name; 125, string:'_crit'; 126, attribute; 126, 127; 126, 128; 127, identifier:metric; 128, identifier:critical; 129, if_statement; 129, 130; 129, 137; 130, boolean_operator:and; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:metric; 133, identifier:min; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:send_min; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 145; 140, subscript; 140, 141; 140, 142; 141, identifier:name_value; 142, binary_operator:+; 142, 143; 142, 144; 143, identifier:name; 144, string:'_min'; 145, attribute; 145, 146; 145, 147; 146, identifier:metric; 147, identifier:min; 148, if_statement; 148, 149; 148, 156; 149, boolean_operator:and; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:metric; 152, identifier:max; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:send_max; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 164; 159, subscript; 159, 160; 159, 161; 160, identifier:name_value; 161, binary_operator:+; 161, 162; 161, 163; 162, identifier:name; 163, string:'_max'; 164, attribute; 164, 165; 164, 166; 165, identifier:metric; 166, identifier:max; 167, for_statement; 167, 168; 167, 171; 167, 176; 168, pattern_list; 168, 169; 168, 170; 169, identifier:key; 170, identifier:value; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:name_value; 174, identifier:items; 175, argument_list; 176, block; 176, 177; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:result; 181, identifier:append; 182, argument_list; 182, 183; 183, tuple; 183, 184; 183, 185; 183, 186; 184, identifier:key; 185, identifier:value; 186, attribute; 186, 187; 186, 188; 187, identifier:metric; 188, identifier:uom; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:logger; 193, identifier:debug; 194, argument_list; 194, 195; 194, 196; 194, 197; 195, string:"Metrics: %s - %s"; 196, identifier:service; 197, identifier:result; 198, return_statement; 198, 199; 199, identifier:result | def get_metrics_from_perfdata(self, service, perf_data):
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
name_value = {
name: metric.value,
'uom_' + name: metric.uom
}
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; 2, function_name:manage_service_check_result_brok; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:b; 6, block; 6, 7; 6, 19; 6, 31; 6, 39; 6, 47; 6, 55; 6, 76; 6, 97; 6, 111; 6, 123; 6, 168; 6, 175; 6, 248; 6, 255; 6, 296; 6, 328; 6, 365; 6, 369; 6, 390; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:host_name; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:b; 14, identifier:data; 15, identifier:get; 16, argument_list; 16, 17; 16, 18; 17, string:'host_name'; 18, None; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:service_description; 22, call; 22, 23; 22, 28; 23, attribute; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:b; 26, identifier:data; 27, identifier:get; 28, argument_list; 28, 29; 28, 30; 29, string:'service_description'; 30, None; 31, if_statement; 31, 32; 31, 37; 32, boolean_operator:or; 32, 33; 32, 35; 33, not_operator; 33, 34; 34, identifier:host_name; 35, not_operator; 35, 36; 36, identifier:service_description; 37, block; 37, 38; 38, return_statement; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:service_id; 42, binary_operator:+; 42, 43; 42, 46; 43, binary_operator:+; 43, 44; 43, 45; 44, identifier:host_name; 45, string:"/"; 46, identifier:service_description; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:logger; 51, identifier:debug; 52, argument_list; 52, 53; 52, 54; 53, string:"service check result: %s"; 54, identifier:service_id; 55, if_statement; 55, 56; 55, 66; 56, boolean_operator:and; 56, 57; 56, 61; 57, not_operator; 57, 58; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:ignore_unknown; 61, comparison_operator:not; 61, 62; 61, 63; 62, identifier:host_name; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:hosts_cache; 66, block; 66, 67; 66, 75; 67, expression_statement; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:logger; 71, identifier:warning; 72, argument_list; 72, 73; 72, 74; 73, string:"received service check result for an unknown host: %s"; 74, identifier:service_id; 75, return_statement; 76, if_statement; 76, 77; 76, 87; 77, boolean_operator:and; 77, 78; 77, 83; 78, comparison_operator:not; 78, 79; 78, 80; 79, identifier:service_id; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:services_cache; 83, not_operator; 83, 84; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:ignore_unknown; 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:"received service check result for an unknown service: %s"; 95, identifier:service_id; 96, return_statement; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:metrics; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:self; 103, identifier:get_metrics_from_perfdata; 104, argument_list; 104, 105; 104, 106; 105, identifier:service_description; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:b; 109, identifier:data; 110, string:'perf_data'; 111, if_statement; 111, 112; 111, 114; 112, not_operator; 112, 113; 113, identifier:metrics; 114, block; 114, 115; 114, 122; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:logger; 119, identifier:debug; 120, argument_list; 120, 121; 121, string:"no metrics to send ..."; 122, return_statement; 123, if_statement; 123, 124; 123, 134; 123, 155; 124, comparison_operator:>=; 124, 125; 124, 128; 124, 133; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:ignore_latency_limit; 128, subscript; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:b; 131, identifier:data; 132, string:'latency'; 133, integer:0; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:check_time; 138, binary_operator:-; 138, 139; 138, 147; 139, call; 139, 140; 139, 141; 140, identifier:int; 141, argument_list; 141, 142; 142, subscript; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:b; 145, identifier:data; 146, string:'last_chk'; 147, call; 147, 148; 147, 149; 148, identifier:int; 149, argument_list; 149, 150; 150, subscript; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:b; 153, identifier:data; 154, string:'latency'; 155, else_clause; 155, 156; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:check_time; 160, call; 160, 161; 160, 162; 161, identifier:int; 162, argument_list; 162, 163; 163, subscript; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:b; 166, identifier:data; 167, string:'last_chk'; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:hname; 171, call; 171, 172; 171, 173; 172, identifier:sanitize_name; 173, argument_list; 173, 174; 174, identifier:host_name; 175, if_statement; 175, 176; 175, 181; 176, comparison_operator:in; 176, 177; 176, 178; 177, identifier:host_name; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:hosts_cache; 181, block; 181, 182; 181, 215; 182, if_statement; 182, 183; 182, 194; 183, call; 183, 184; 183, 191; 184, attribute; 184, 185; 184, 190; 185, subscript; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:hosts_cache; 189, identifier:host_name; 190, identifier:get; 191, argument_list; 191, 192; 191, 193; 192, string:'_GRAPHITE_GROUP'; 193, None; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:hname; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, string:"."; 201, identifier:join; 202, argument_list; 202, 203; 203, tuple; 203, 204; 203, 214; 204, call; 204, 205; 204, 212; 205, attribute; 205, 206; 205, 211; 206, subscript; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:hosts_cache; 210, identifier:host_name; 211, identifier:get; 212, argument_list; 212, 213; 213, string:'_GRAPHITE_GROUP'; 214, identifier:hname; 215, if_statement; 215, 216; 215, 227; 216, call; 216, 217; 216, 224; 217, attribute; 217, 218; 217, 223; 218, subscript; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:hosts_cache; 222, identifier:host_name; 223, identifier:get; 224, argument_list; 224, 225; 224, 226; 225, string:'_GRAPHITE_PRE'; 226, None; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:hname; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, string:"."; 234, identifier:join; 235, argument_list; 235, 236; 236, tuple; 236, 237; 236, 247; 237, call; 237, 238; 237, 245; 238, attribute; 238, 239; 238, 244; 239, subscript; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:hosts_cache; 243, identifier:host_name; 244, identifier:get; 245, argument_list; 245, 246; 246, string:'_GRAPHITE_PRE'; 247, identifier:hname; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:desc; 251, call; 251, 252; 251, 253; 252, identifier:sanitize_name; 253, argument_list; 253, 254; 254, identifier:service_description; 255, if_statement; 255, 256; 255, 261; 256, comparison_operator:in; 256, 257; 256, 258; 257, identifier:service_id; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:services_cache; 261, block; 261, 262; 262, if_statement; 262, 263; 262, 274; 263, call; 263, 264; 263, 271; 264, attribute; 264, 265; 264, 270; 265, subscript; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:services_cache; 269, identifier:service_id; 270, identifier:get; 271, argument_list; 271, 272; 271, 273; 272, string:'_GRAPHITE_POST'; 273, None; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:desc; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, string:"."; 281, identifier:join; 282, argument_list; 282, 283; 283, tuple; 283, 284; 283, 285; 284, identifier:desc; 285, call; 285, 286; 285, 293; 286, attribute; 286, 287; 286, 292; 287, subscript; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:self; 290, identifier:services_cache; 291, identifier:service_id; 292, identifier:get; 293, argument_list; 293, 294; 293, 295; 294, string:'_GRAPHITE_POST'; 295, None; 296, if_statement; 296, 297; 296, 300; 296, 315; 297, attribute; 297, 298; 297, 299; 298, identifier:self; 299, identifier:graphite_data_source; 300, block; 300, 301; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:path; 304, call; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, string:'.'; 307, identifier:join; 308, argument_list; 308, 309; 309, tuple; 309, 310; 309, 311; 309, 314; 310, identifier:hname; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:graphite_data_source; 314, identifier:desc; 315, else_clause; 315, 316; 316, block; 316, 317; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:path; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, string:'.'; 323, identifier:join; 324, argument_list; 324, 325; 325, tuple; 325, 326; 325, 327; 326, identifier:hname; 327, identifier:desc; 328, if_statement; 328, 329; 328, 344; 329, boolean_operator:and; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:realms_prefix; 333, call; 333, 334; 333, 341; 334, attribute; 334, 335; 334, 340; 335, subscript; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:hosts_cache; 339, identifier:host_name; 340, identifier:get; 341, argument_list; 341, 342; 341, 343; 342, string:'realm_name'; 343, None; 344, block; 344, 345; 345, expression_statement; 345, 346; 346, assignment; 346, 347; 346, 348; 347, identifier:path; 348, call; 348, 349; 348, 352; 349, attribute; 349, 350; 349, 351; 350, string:'.'; 351, identifier:join; 352, argument_list; 352, 353; 353, tuple; 353, 354; 353, 364; 354, call; 354, 355; 354, 362; 355, attribute; 355, 356; 355, 361; 356, subscript; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:self; 359, identifier:hosts_cache; 360, identifier:host_name; 361, identifier:get; 362, argument_list; 362, 363; 363, string:'realm_name'; 364, identifier:path; 365, expression_statement; 365, 366; 366, assignment; 366, 367; 366, 368; 367, identifier:realm_name; 368, None; 369, if_statement; 369, 370; 369, 375; 370, comparison_operator:in; 370, 371; 370, 372; 371, identifier:host_name; 372, attribute; 372, 373; 372, 374; 373, identifier:self; 374, identifier:hosts_cache; 375, block; 375, 376; 376, expression_statement; 376, 377; 377, assignment; 377, 378; 377, 379; 378, identifier:realm_name; 379, call; 379, 380; 379, 387; 380, attribute; 380, 381; 380, 386; 381, subscript; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, identifier:self; 384, identifier:hosts_cache; 385, identifier:host_name; 386, identifier:get; 387, argument_list; 387, 388; 387, 389; 388, string:'realm_name'; 389, None; 390, expression_statement; 390, 391; 391, call; 391, 392; 391, 395; 392, attribute; 392, 393; 392, 394; 393, identifier:self; 394, identifier:send_to_tsdb; 395, argument_list; 395, 396; 395, 397; 395, 398; 395, 399; 395, 400; 395, 401; 396, identifier:realm_name; 397, identifier:host_name; 398, identifier:service_description; 399, identifier:metrics; 400, identifier:check_time; 401, identifier:path | def manage_service_check_result_brok(self, b):
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 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
metrics = self.get_metrics_from_perfdata(service_description, b.data['perf_data'])
if not metrics:
logger.debug("no metrics to send ...")
return
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'])
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))
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)))
if self.graphite_data_source:
path = '.'.join((hname, self.graphite_data_source, desc))
else:
path = '.'.join((hname, desc))
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)
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; 2, function_name:manage_host_check_result_brok; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:b; 6, block; 6, 7; 6, 19; 6, 24; 6, 32; 6, 53; 6, 67; 6, 79; 6, 124; 6, 131; 6, 204; 6, 258; 6, 295; 6, 299; 6, 320; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:host_name; 10, call; 10, 11; 10, 16; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:b; 14, identifier:data; 15, identifier:get; 16, argument_list; 16, 17; 16, 18; 17, string:'host_name'; 18, None; 19, if_statement; 19, 20; 19, 22; 20, not_operator; 20, 21; 21, identifier:host_name; 22, block; 22, 23; 23, return_statement; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:logger; 28, identifier:debug; 29, argument_list; 29, 30; 29, 31; 30, string:"host check result: %s"; 31, identifier:host_name; 32, if_statement; 32, 33; 32, 43; 33, boolean_operator:and; 33, 34; 33, 39; 34, comparison_operator:not; 34, 35; 34, 36; 35, identifier:host_name; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:hosts_cache; 39, not_operator; 39, 40; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:ignore_unknown; 43, block; 43, 44; 43, 52; 44, expression_statement; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:logger; 48, identifier:warning; 49, argument_list; 49, 50; 49, 51; 50, string:"received host check result for an unknown host: %s"; 51, identifier:host_name; 52, return_statement; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:metrics; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:get_metrics_from_perfdata; 60, argument_list; 60, 61; 60, 62; 61, string:'host_check'; 62, subscript; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:b; 65, identifier:data; 66, string:'perf_data'; 67, if_statement; 67, 68; 67, 70; 68, not_operator; 68, 69; 69, identifier:metrics; 70, block; 70, 71; 70, 78; 71, expression_statement; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:logger; 75, identifier:debug; 76, argument_list; 76, 77; 77, string:"no metrics to send ..."; 78, return_statement; 79, if_statement; 79, 80; 79, 90; 79, 111; 80, comparison_operator:>=; 80, 81; 80, 84; 80, 89; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:ignore_latency_limit; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:b; 87, identifier:data; 88, string:'latency'; 89, integer:0; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:check_time; 94, binary_operator:-; 94, 95; 94, 103; 95, call; 95, 96; 95, 97; 96, identifier:int; 97, argument_list; 97, 98; 98, subscript; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:b; 101, identifier:data; 102, string:'last_chk'; 103, call; 103, 104; 103, 105; 104, identifier:int; 105, argument_list; 105, 106; 106, subscript; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:b; 109, identifier:data; 110, string:'latency'; 111, else_clause; 111, 112; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:check_time; 116, call; 116, 117; 116, 118; 117, identifier:int; 118, argument_list; 118, 119; 119, subscript; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:b; 122, identifier:data; 123, string:'last_chk'; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:hname; 127, call; 127, 128; 127, 129; 128, identifier:sanitize_name; 129, argument_list; 129, 130; 130, identifier:host_name; 131, if_statement; 131, 132; 131, 137; 132, comparison_operator:in; 132, 133; 132, 134; 133, identifier:host_name; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:hosts_cache; 137, block; 137, 138; 137, 171; 138, if_statement; 138, 139; 138, 150; 139, call; 139, 140; 139, 147; 140, attribute; 140, 141; 140, 146; 141, subscript; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:hosts_cache; 145, identifier:host_name; 146, identifier:get; 147, argument_list; 147, 148; 147, 149; 148, string:'_GRAPHITE_GROUP'; 149, None; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:hname; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, string:"."; 157, identifier:join; 158, argument_list; 158, 159; 159, tuple; 159, 160; 159, 170; 160, call; 160, 161; 160, 168; 161, attribute; 161, 162; 161, 167; 162, subscript; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:hosts_cache; 166, identifier:host_name; 167, identifier:get; 168, argument_list; 168, 169; 169, string:'_GRAPHITE_GROUP'; 170, identifier:hname; 171, if_statement; 171, 172; 171, 183; 172, call; 172, 173; 172, 180; 173, attribute; 173, 174; 173, 179; 174, subscript; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:hosts_cache; 178, identifier:host_name; 179, identifier:get; 180, argument_list; 180, 181; 180, 182; 181, string:'_GRAPHITE_PRE'; 182, None; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:hname; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, string:"."; 190, identifier:join; 191, argument_list; 191, 192; 192, tuple; 192, 193; 192, 203; 193, call; 193, 194; 193, 201; 194, attribute; 194, 195; 194, 200; 195, subscript; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:hosts_cache; 199, identifier:host_name; 200, identifier:get; 201, argument_list; 201, 202; 202, string:'_GRAPHITE_PRE'; 203, identifier:hname; 204, if_statement; 204, 205; 204, 208; 204, 243; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:graphite_data_source; 208, block; 208, 209; 208, 222; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:path; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, string:'.'; 215, identifier:join; 216, argument_list; 216, 217; 217, tuple; 217, 218; 217, 219; 218, identifier:hname; 219, attribute; 219, 220; 219, 221; 220, identifier:self; 221, identifier:graphite_data_source; 222, if_statement; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:hostcheck; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:path; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, string:'.'; 233, identifier:join; 234, argument_list; 234, 235; 235, tuple; 235, 236; 235, 237; 235, 240; 236, identifier:hname; 237, attribute; 237, 238; 237, 239; 238, identifier:self; 239, identifier:graphite_data_source; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:hostcheck; 243, else_clause; 243, 244; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:path; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, string:'.'; 251, identifier:join; 252, argument_list; 252, 253; 253, tuple; 253, 254; 253, 255; 254, identifier:hname; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:hostcheck; 258, if_statement; 258, 259; 258, 274; 259, boolean_operator:and; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:self; 262, identifier:realms_prefix; 263, call; 263, 264; 263, 271; 264, attribute; 264, 265; 264, 270; 265, subscript; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:hosts_cache; 269, identifier:host_name; 270, identifier:get; 271, argument_list; 271, 272; 271, 273; 272, string:'realm_name'; 273, None; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:path; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, string:'.'; 281, identifier:join; 282, argument_list; 282, 283; 283, tuple; 283, 284; 283, 294; 284, call; 284, 285; 284, 292; 285, attribute; 285, 286; 285, 291; 286, subscript; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:hosts_cache; 290, identifier:host_name; 291, identifier:get; 292, argument_list; 292, 293; 293, string:'realm_name'; 294, identifier:path; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 298; 297, identifier:realm_name; 298, None; 299, if_statement; 299, 300; 299, 305; 300, comparison_operator:in; 300, 301; 300, 302; 301, identifier:host_name; 302, attribute; 302, 303; 302, 304; 303, identifier:self; 304, identifier:hosts_cache; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:realm_name; 309, call; 309, 310; 309, 317; 310, attribute; 310, 311; 310, 316; 311, subscript; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:hosts_cache; 315, identifier:host_name; 316, identifier:get; 317, argument_list; 317, 318; 317, 319; 318, string:'realm_name'; 319, None; 320, expression_statement; 320, 321; 321, call; 321, 322; 321, 325; 322, attribute; 322, 323; 322, 324; 323, identifier:self; 324, identifier:send_to_tsdb; 325, argument_list; 325, 326; 325, 327; 325, 328; 325, 331; 325, 332; 325, 333; 326, identifier:realm_name; 327, identifier:host_name; 328, attribute; 328, 329; 328, 330; 329, identifier:self; 330, identifier:hostcheck; 331, identifier:metrics; 332, identifier:check_time; 333, identifier:path | def manage_host_check_result_brok(self, b):
host_name = b.data.get('host_name', None)
if not host_name:
return
logger.debug("host check result: %s", host_name)
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
metrics = self.get_metrics_from_perfdata('host_check', b.data['perf_data'])
if not metrics:
logger.debug("no metrics to send ...")
return
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'])
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))
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))
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)
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, 28; 5, 42; 5, 57; 5, 69; 5, 75; 5, 79; 5, 138; 5, 159; 6, if_statement; 6, 7; 6, 10; 7, attribute; 7, 8; 7, 9; 8, identifier:self; 9, identifier:leaf; 10, block; 10, 11; 10, 21; 11, if_statement; 11, 12; 11, 16; 12, not_operator; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:content; 16, block; 16, 17; 17, return_statement; 17, 18; 18, call; 18, 19; 18, 20; 19, identifier:set; 20, argument_list; 21, return_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:set; 24, argument_list; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:content; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:not_nodes; 31, list_comprehension; 31, 32; 31, 33; 31, 38; 32, identifier:s; 33, for_in_clause; 33, 34; 33, 35; 34, identifier:s; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:sons; 38, if_clause; 38, 39; 39, attribute; 39, 40; 39, 41; 40, identifier:s; 41, identifier:not_value; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:positiv_nodes; 45, list_comprehension; 45, 46; 45, 47; 45, 52; 46, identifier:s; 47, for_in_clause; 47, 48; 47, 49; 48, identifier:s; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:sons; 52, if_clause; 52, 53; 53, not_operator; 53, 54; 54, attribute; 54, 55; 54, 56; 55, identifier:s; 56, identifier:not_value; 57, if_statement; 57, 58; 57, 62; 58, not_operator; 58, 59; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:operand; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:self; 67, identifier:operand; 68, string:'|'; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:res; 72, call; 72, 73; 72, 74; 73, identifier:set; 74, argument_list; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:i; 78, integer:0; 79, for_statement; 79, 80; 79, 81; 79, 82; 80, identifier:node; 81, identifier:positiv_nodes; 82, block; 82, 83; 82, 91; 82, 134; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:node_members; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:node; 89, identifier:resolve_elements; 90, argument_list; 91, if_statement; 91, 92; 91, 97; 91, 107; 92, comparison_operator:==; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:operand; 96, string:'|'; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:res; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:res; 104, identifier:union; 105, argument_list; 105, 106; 106, identifier:node_members; 107, elif_clause; 107, 108; 107, 113; 108, comparison_operator:==; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:operand; 112, string:'&'; 113, block; 113, 114; 114, if_statement; 114, 115; 114, 118; 114, 123; 115, comparison_operator:==; 115, 116; 115, 117; 116, identifier:i; 117, integer:0; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:res; 122, identifier:node_members; 123, else_clause; 123, 124; 124, block; 124, 125; 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:res; 131, identifier:intersection; 132, argument_list; 132, 133; 133, identifier:node_members; 134, expression_statement; 134, 135; 135, augmented_assignment:+=; 135, 136; 135, 137; 136, identifier:i; 137, integer:1; 138, for_statement; 138, 139; 138, 140; 138, 141; 139, identifier:node; 140, identifier:not_nodes; 141, block; 141, 142; 141, 150; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:node_members; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:node; 148, identifier:resolve_elements; 149, argument_list; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:res; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:res; 156, identifier:difference; 157, argument_list; 157, 158; 158, identifier:node_members; 159, return_statement; 159, 160; 160, identifier:res | def resolve_elements(self):
if self.leaf:
if not self.content:
return set()
return set(self.content)
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]
if not self.operand:
self.operand = '|'
res = set()
i = 0
for node in positiv_nodes:
node_members = node.resolve_elements()
if self.operand == '|':
res = res.union(node_members)
elif self.operand == '&':
if i == 0:
res = node_members
else:
res = res.intersection(node_members)
i += 1
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; 2, function_name:eval_cor_pattern; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:pattern; 6, block; 6, 7; 6, 15; 6, 19; 6, 32; 6, 38; 6, 113; 6, 117; 6, 121; 6, 125; 6, 361; 6, 369; 6, 392; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:pattern; 10, call; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:pattern; 13, identifier:strip; 14, argument_list; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:complex_node; 18, False; 19, for_statement; 19, 20; 19, 21; 19, 22; 20, identifier:char; 21, string:'()+&|,'; 22, block; 22, 23; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:in; 24, 25; 24, 26; 25, identifier:char; 26, identifier:pattern; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:complex_node; 31, True; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:node; 35, call; 35, 36; 35, 37; 36, identifier:ComplexExpressionNode; 37, argument_list; 38, if_statement; 38, 39; 38, 41; 39, not_operator; 39, 40; 40, identifier:complex_node; 41, block; 41, 42; 41, 64; 41, 72; 41, 78; 41, 89; 41, 111; 42, if_statement; 42, 43; 42, 49; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:pattern; 46, identifier:startswith; 47, argument_list; 47, 48; 48, string:'!'; 49, block; 49, 50; 49, 56; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:node; 54, identifier:not_value; 55, True; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:pattern; 59, subscript; 59, 60; 59, 61; 60, identifier:pattern; 61, slice; 61, 62; 61, 63; 62, integer:1; 63, colon; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:node; 68, identifier:operand; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:ctx; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:node; 76, identifier:leaf; 77, True; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, pattern_list; 80, 81; 80, 82; 81, identifier:obj; 82, identifier:error; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:find_object; 87, argument_list; 87, 88; 88, identifier:pattern; 89, if_statement; 89, 90; 89, 93; 89, 100; 90, comparison_operator:is; 90, 91; 90, 92; 91, identifier:obj; 92, None; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:node; 98, identifier:content; 99, identifier:obj; 100, else_clause; 100, 101; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:node; 107, identifier:configuration_errors; 108, identifier:append; 109, argument_list; 109, 110; 110, identifier:error; 111, return_statement; 111, 112; 112, identifier:node; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:in_par; 116, False; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:tmp; 120, string:''; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:stacked_par; 124, integer:0; 125, for_statement; 125, 126; 125, 127; 125, 128; 126, identifier:char; 127, identifier:pattern; 128, block; 128, 129; 129, if_statement; 129, 130; 129, 135; 129, 186; 129, 243; 129, 289; 129, 355; 130, comparison_operator:in; 130, 131; 130, 132; 131, identifier:char; 132, tuple; 132, 133; 132, 134; 133, string:','; 134, string:'|'; 135, block; 135, 136; 136, if_statement; 136, 137; 136, 138; 136, 143; 137, identifier:in_par; 138, block; 138, 139; 139, expression_statement; 139, 140; 140, augmented_assignment:+=; 140, 141; 140, 142; 141, identifier:tmp; 142, identifier:char; 143, else_clause; 143, 144; 144, block; 144, 145; 144, 153; 144, 159; 144, 182; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:tmp; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:tmp; 151, identifier:strip; 152, argument_list; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:node; 157, identifier:operand; 158, string:'|'; 159, if_statement; 159, 160; 159, 163; 160, comparison_operator:!=; 160, 161; 160, 162; 161, identifier:tmp; 162, string:''; 163, block; 163, 164; 163, 173; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 167; 166, identifier:son; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:eval_cor_pattern; 171, argument_list; 171, 172; 172, identifier:tmp; 173, expression_statement; 173, 174; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:node; 178, identifier:sons; 179, identifier:append; 180, argument_list; 180, 181; 181, identifier:son; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:tmp; 185, string:''; 186, elif_clause; 186, 187; 186, 192; 187, comparison_operator:in; 187, 188; 187, 189; 188, identifier:char; 189, tuple; 189, 190; 189, 191; 190, string:'&'; 191, string:'+'; 192, block; 192, 193; 193, if_statement; 193, 194; 193, 195; 193, 200; 194, identifier:in_par; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, augmented_assignment:+=; 197, 198; 197, 199; 198, identifier:tmp; 199, identifier:char; 200, else_clause; 200, 201; 201, block; 201, 202; 201, 210; 201, 216; 201, 239; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:tmp; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:tmp; 208, identifier:strip; 209, argument_list; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:node; 214, identifier:operand; 215, string:'&'; 216, if_statement; 216, 217; 216, 220; 217, comparison_operator:!=; 217, 218; 217, 219; 218, identifier:tmp; 219, string:''; 220, block; 220, 221; 220, 230; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:son; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:self; 227, identifier:eval_cor_pattern; 228, argument_list; 228, 229; 229, identifier:tmp; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 237; 232, attribute; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:node; 235, identifier:sons; 236, identifier:append; 237, argument_list; 237, 238; 238, identifier:son; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:tmp; 242, string:''; 243, elif_clause; 243, 244; 243, 247; 244, comparison_operator:==; 244, 245; 244, 246; 245, identifier:char; 246, string:'('; 247, block; 247, 248; 247, 252; 247, 256; 247, 264; 247, 280; 248, expression_statement; 248, 249; 249, augmented_assignment:+=; 249, 250; 249, 251; 250, identifier:stacked_par; 251, integer:1; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:in_par; 255, True; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:tmp; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:tmp; 262, identifier:strip; 263, argument_list; 264, if_statement; 264, 265; 264, 272; 265, boolean_operator:and; 265, 266; 265, 269; 266, comparison_operator:==; 266, 267; 266, 268; 267, identifier:stacked_par; 268, integer:1; 269, comparison_operator:!=; 269, 270; 269, 271; 270, identifier:tmp; 271, string:''; 272, block; 272, 273; 272, 279; 273, expression_statement; 273, 274; 274, call; 274, 275; 274, 276; 275, identifier:print; 276, argument_list; 276, 277; 276, 278; 277, string:"ERROR : bad expression near"; 278, identifier:tmp; 279, continue_statement; 280, if_statement; 280, 281; 280, 284; 281, comparison_operator:>; 281, 282; 281, 283; 282, identifier:stacked_par; 283, integer:1; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, augmented_assignment:+=; 286, 287; 286, 288; 287, identifier:tmp; 288, identifier:char; 289, elif_clause; 289, 290; 289, 293; 290, comparison_operator:==; 290, 291; 290, 292; 291, identifier:char; 292, string:')'; 293, block; 293, 294; 293, 298; 293, 311; 293, 351; 294, expression_statement; 294, 295; 295, augmented_assignment:-=; 295, 296; 295, 297; 296, identifier:stacked_par; 297, integer:1; 298, if_statement; 298, 299; 298, 302; 299, comparison_operator:<; 299, 300; 299, 301; 300, identifier:stacked_par; 301, integer:0; 302, block; 302, 303; 302, 310; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:print; 306, argument_list; 306, 307; 306, 308; 306, 309; 307, string:"Error : bad expression near"; 308, identifier:tmp; 309, string:"too much ')'"; 310, continue_statement; 311, if_statement; 311, 312; 311, 315; 312, comparison_operator:==; 312, 313; 312, 314; 313, identifier:stacked_par; 314, integer:0; 315, block; 315, 316; 315, 324; 315, 333; 315, 342; 315, 346; 315, 350; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:tmp; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:tmp; 322, identifier:strip; 323, argument_list; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:son; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:self; 330, identifier:eval_cor_pattern; 331, argument_list; 331, 332; 332, identifier:tmp; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 340; 335, attribute; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:node; 338, identifier:sons; 339, identifier:append; 340, argument_list; 340, 341; 341, identifier:son; 342, expression_statement; 342, 343; 343, assignment; 343, 344; 343, 345; 344, identifier:in_par; 345, False; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 349; 348, identifier:tmp; 349, string:''; 350, continue_statement; 351, expression_statement; 351, 352; 352, augmented_assignment:+=; 352, 353; 352, 354; 353, identifier:tmp; 354, identifier:char; 355, else_clause; 355, 356; 356, block; 356, 357; 357, expression_statement; 357, 358; 358, augmented_assignment:+=; 358, 359; 358, 360; 359, identifier:tmp; 360, identifier:char; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:tmp; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:tmp; 367, identifier:strip; 368, argument_list; 369, if_statement; 369, 370; 369, 373; 370, comparison_operator:!=; 370, 371; 370, 372; 371, identifier:tmp; 372, string:''; 373, block; 373, 374; 373, 383; 374, expression_statement; 374, 375; 375, assignment; 375, 376; 375, 377; 376, identifier:son; 377, call; 377, 378; 377, 381; 378, attribute; 378, 379; 378, 380; 379, identifier:self; 380, identifier:eval_cor_pattern; 381, argument_list; 381, 382; 382, identifier:tmp; 383, expression_statement; 383, 384; 384, call; 384, 385; 384, 390; 385, attribute; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:node; 388, identifier:sons; 389, identifier:append; 390, argument_list; 390, 391; 391, identifier:son; 392, return_statement; 392, 393; 393, identifier:node | def eval_cor_pattern(self, pattern):
pattern = pattern.strip()
complex_node = False
for char in '()+&|,':
if char in pattern:
complex_node = True
node = ComplexExpressionNode()
if not complex_node:
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 (',', '|'):
if in_par:
tmp += char
else:
tmp = tmp.strip()
node.operand = '|'
if tmp != '':
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
tmp = ''
elif char in ('&', '+'):
if in_par:
tmp += char
else:
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()
if stacked_par == 1 and tmp != '':
print("ERROR : bad expression near", tmp)
continue
if stacked_par > 1:
tmp += char
elif char == ')':
stacked_par -= 1
if stacked_par < 0:
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
tmp = ''
continue
tmp += char
else:
tmp += char
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, 11; 6, 15; 6, 23; 6, 69; 6, 176; 6, 187; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:obj; 10, None; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:error; 14, None; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:pattern; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:pattern; 21, identifier:strip; 22, argument_list; 23, if_statement; 23, 24; 23, 27; 24, comparison_operator:==; 24, 25; 24, 26; 25, identifier:pattern; 26, string:'*'; 27, block; 27, 28; 27, 65; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:obj; 31, list_comprehension; 31, 32; 31, 35; 31, 49; 32, attribute; 32, 33; 32, 34; 33, identifier:h; 34, identifier:host_name; 35, for_in_clause; 35, 36; 35, 37; 36, identifier:h; 37, call; 37, 38; 37, 39; 38, identifier:list; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 48; 41, attribute; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:all_elements; 46, identifier:items; 47, identifier:values; 48, argument_list; 49, if_clause; 49, 50; 50, boolean_operator:and; 50, 51; 50, 59; 51, comparison_operator:!=; 51, 52; 51, 58; 52, call; 52, 53; 52, 54; 53, identifier:getattr; 54, argument_list; 54, 55; 54, 56; 54, 57; 55, identifier:h; 56, string:'host_name'; 57, string:''; 58, string:''; 59, not_operator; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:h; 63, identifier:is_tpl; 64, argument_list; 65, return_statement; 65, 66; 66, expression_list; 66, 67; 66, 68; 67, identifier:obj; 68, identifier:error; 69, if_statement; 69, 70; 69, 75; 70, comparison_operator:==; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:ctx; 74, string:'hostgroups'; 75, block; 75, 76; 75, 87; 75, 105; 75, 113; 75, 120; 75, 172; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:hgr; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:grps; 84, identifier:find_by_name; 85, argument_list; 85, 86; 86, identifier:pattern; 87, if_statement; 87, 88; 87, 90; 88, not_operator; 88, 89; 89, identifier:hgr; 90, block; 90, 91; 90, 101; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:error; 94, binary_operator:%; 94, 95; 94, 96; 95, string:"Error : cannot find the %s of the expression '%s'"; 96, tuple; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:ctx; 100, identifier:pattern; 101, return_statement; 101, 102; 102, expression_list; 102, 103; 102, 104; 103, identifier:hgr; 104, identifier:error; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:elts; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:hgr; 111, identifier:get_hosts; 112, argument_list; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:elts; 116, call; 116, 117; 116, 118; 117, identifier:strip_and_uniq; 118, argument_list; 118, 119; 119, identifier:elts; 120, if_statement; 120, 121; 120, 124; 121, comparison_operator:in; 121, 122; 121, 123; 122, string:'*'; 123, identifier:elts; 124, block; 124, 125; 124, 165; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:elts; 129, identifier:extend; 130, argument_list; 130, 131; 131, list_comprehension; 131, 132; 131, 135; 131, 149; 132, attribute; 132, 133; 132, 134; 133, identifier:h; 134, identifier:host_name; 135, for_in_clause; 135, 136; 135, 137; 136, identifier:h; 137, call; 137, 138; 137, 139; 138, identifier:list; 139, argument_list; 139, 140; 140, call; 140, 141; 140, 148; 141, attribute; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:all_elements; 146, identifier:items; 147, identifier:values; 148, argument_list; 149, if_clause; 149, 150; 150, boolean_operator:and; 150, 151; 150, 159; 151, comparison_operator:!=; 151, 152; 151, 158; 152, call; 152, 153; 152, 154; 153, identifier:getattr; 154, argument_list; 154, 155; 154, 156; 154, 157; 155, identifier:h; 156, string:'host_name'; 157, string:''; 158, string:''; 159, not_operator; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:h; 163, identifier:is_tpl; 164, argument_list; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:elts; 169, identifier:remove; 170, argument_list; 170, 171; 171, string:'*'; 172, return_statement; 172, 173; 173, expression_list; 173, 174; 173, 175; 174, identifier:elts; 175, identifier:error; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:obj; 179, call; 179, 180; 179, 185; 180, attribute; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:grps; 184, identifier:find_hosts_that_use_template; 185, argument_list; 185, 186; 186, identifier:pattern; 187, return_statement; 187, 188; 188, expression_list; 188, 189; 188, 190; 189, identifier:obj; 190, identifier:error | def find_object(self, pattern):
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
if self.ctx == 'hostgroups':
hgr = self.grps.find_by_name(pattern)
if not hgr:
error = "Error : cannot find the %s of the expression '%s'" % (self.ctx, pattern)
return hgr, error
elts = hgr.get_hosts()
elts = strip_and_uniq(elts)
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()])
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; 2, function_name:clean_queues; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 26; 5, 45; 5, 64; 5, 90; 5, 96; 5, 245; 5, 251; 5, 323; 5, 329; 6, if_statement; 6, 7; 6, 17; 7, comparison_operator:==; 7, 8; 7, 16; 8, call; 8, 9; 8, 10; 9, identifier:getattr; 10, argument_list; 10, 11; 10, 14; 10, 15; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:pushed_conf; 14, string:'tick_clean_queues'; 15, integer:0; 16, integer:0; 17, block; 17, 18; 17, 25; 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; 24, string:"No queues cleaning..."; 25, return_statement; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:max_checks; 29, binary_operator:*; 29, 30; 29, 31; 30, identifier:MULTIPLIER_MAX_CHECKS; 31, parenthesized_expression; 31, 32; 32, binary_operator:+; 32, 33; 32, 39; 33, call; 33, 34; 33, 35; 34, identifier:len; 35, argument_list; 35, 36; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:hosts; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:services; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:max_broks; 48, binary_operator:*; 48, 49; 48, 50; 49, identifier:MULTIPLIER_MAX_BROKS; 50, parenthesized_expression; 50, 51; 51, binary_operator:+; 51, 52; 51, 58; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:hosts; 58, call; 58, 59; 58, 60; 59, identifier:len; 60, argument_list; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:services; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:max_actions; 67, binary_operator:*; 67, 68; 67, 76; 68, binary_operator:*; 68, 69; 68, 70; 69, identifier:MULTIPLIER_MAX_ACTIONS; 70, call; 70, 71; 70, 72; 71, identifier:len; 72, argument_list; 72, 73; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:contacts; 76, parenthesized_expression; 76, 77; 77, binary_operator:+; 77, 78; 77, 84; 78, call; 78, 79; 78, 80; 79, identifier:len; 80, argument_list; 80, 81; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:hosts; 84, call; 84, 85; 84, 86; 85, identifier:len; 86, argument_list; 86, 87; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:services; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:nb_checks_dropped; 95, integer:0; 96, if_statement; 96, 97; 96, 107; 97, boolean_operator:and; 97, 98; 97, 99; 98, identifier:max_checks; 99, comparison_operator:>; 99, 100; 99, 106; 100, call; 100, 101; 100, 102; 101, identifier:len; 102, argument_list; 102, 103; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:checks; 106, identifier:max_checks; 107, block; 107, 108; 107, 125; 107, 139; 107, 148; 107, 157; 107, 170; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:to_del_checks; 111, list_comprehension; 111, 112; 111, 113; 112, identifier:c; 113, for_in_clause; 113, 114; 113, 115; 114, identifier:c; 115, call; 115, 116; 115, 117; 116, identifier:list; 117, argument_list; 117, 118; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:checks; 123, identifier:values; 124, argument_list; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:to_del_checks; 129, identifier:sort; 130, argument_list; 130, 131; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:key; 133, lambda; 133, 134; 133, 136; 134, lambda_parameters; 134, 135; 135, identifier:x; 136, attribute; 136, 137; 136, 138; 137, identifier:x; 138, identifier:creation_time; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:to_del_checks; 142, subscript; 142, 143; 142, 144; 143, identifier:to_del_checks; 144, slice; 144, 145; 144, 146; 145, colon; 146, unary_operator:-; 146, 147; 147, identifier:max_checks; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:nb_checks_dropped; 153, call; 153, 154; 153, 155; 154, identifier:len; 155, argument_list; 155, 156; 156, identifier:to_del_checks; 157, if_statement; 157, 158; 157, 159; 158, identifier:to_del_checks; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:logger; 164, identifier:warning; 165, argument_list; 165, 166; 165, 167; 166, string:"I have to drop some checks (%d)..., sorry :("; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:nb_checks_dropped; 170, for_statement; 170, 171; 170, 172; 170, 173; 171, identifier:chk; 172, identifier:to_del_checks; 173, block; 173, 174; 173, 180; 173, 192; 173, 200; 173, 207; 173, 224; 173, 239; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:c_id; 177, attribute; 177, 178; 177, 179; 178, identifier:chk; 179, identifier:uuid; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:items; 183, call; 183, 184; 183, 185; 184, identifier:getattr; 185, argument_list; 185, 186; 185, 187; 186, identifier:self; 187, binary_operator:+; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:chk; 190, identifier:ref_type; 191, string:'s'; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:elt; 195, subscript; 195, 196; 195, 197; 196, identifier:items; 197, attribute; 197, 198; 197, 199; 198, identifier:chk; 199, identifier:ref; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:elt; 204, identifier:remove_in_progress_check; 205, argument_list; 205, 206; 206, identifier:chk; 207, for_statement; 207, 208; 207, 209; 207, 212; 208, identifier:dependent_checks; 209, attribute; 209, 210; 209, 211; 210, identifier:chk; 211, identifier:depend_on_me; 212, block; 212, 213; 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, for_statement; 224, 225; 224, 226; 224, 229; 225, identifier:c_temp; 226, attribute; 226, 227; 226, 228; 227, identifier:chk; 228, identifier:depend_on; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 237; 232, attribute; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:c_temp; 235, identifier:depend_on_me; 236, identifier:remove; 237, argument_list; 237, 238; 238, identifier:chk; 239, delete_statement; 239, 240; 240, subscript; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:checks; 244, identifier:c_id; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:self; 249, identifier:nb_broks_dropped; 250, integer:0; 251, for_statement; 251, 252; 251, 253; 251, 265; 252, identifier:broker_link; 253, call; 253, 254; 253, 255; 254, identifier:list; 255, argument_list; 255, 256; 256, call; 256, 257; 256, 264; 257, attribute; 257, 258; 257, 263; 258, attribute; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:self; 261, identifier:my_daemon; 262, identifier:brokers; 263, identifier:values; 264, argument_list; 265, block; 265, 266; 266, if_statement; 266, 267; 266, 277; 267, boolean_operator:and; 267, 268; 267, 269; 268, identifier:max_broks; 269, comparison_operator:>; 269, 270; 269, 276; 270, call; 270, 271; 270, 272; 271, identifier:len; 272, argument_list; 272, 273; 273, attribute; 273, 274; 273, 275; 274, identifier:broker_link; 275, identifier:broks; 276, identifier:max_broks; 277, block; 277, 278; 277, 295; 277, 312; 278, expression_statement; 278, 279; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:logger; 282, identifier:warning; 283, argument_list; 283, 284; 283, 287; 283, 293; 283, 294; 284, concatenated_string; 284, 285; 284, 286; 285, string:"I have to drop some broks (%d > %d) for the broker %s "; 286, string:"..., sorry :("; 287, call; 287, 288; 287, 289; 288, identifier:len; 289, argument_list; 289, 290; 290, attribute; 290, 291; 290, 292; 291, identifier:broker_link; 292, identifier:broks; 293, identifier:max_broks; 294, identifier:broker_link; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 298; 297, identifier:kept_broks; 298, call; 298, 299; 298, 300; 299, identifier:sorted; 300, argument_list; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:broker_link; 303, identifier:broks; 304, keyword_argument; 304, 305; 304, 306; 305, identifier:key; 306, lambda; 306, 307; 306, 309; 307, lambda_parameters; 307, 308; 308, identifier:x; 309, attribute; 309, 310; 309, 311; 310, identifier:x; 311, identifier:creation_time; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 317; 314, attribute; 314, 315; 314, 316; 315, identifier:broker_link; 316, identifier:broks; 317, subscript; 317, 318; 317, 319; 318, identifier:kept_broks; 319, slice; 319, 320; 319, 321; 319, 322; 320, integer:0; 321, colon; 322, identifier:max_broks; 323, expression_statement; 323, 324; 324, assignment; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:self; 327, identifier:nb_actions_dropped; 328, integer:0; 329, if_statement; 329, 330; 329, 340; 330, boolean_operator:and; 330, 331; 330, 332; 331, identifier:max_actions; 332, comparison_operator:>; 332, 333; 332, 339; 333, call; 333, 334; 333, 335; 334, identifier:len; 335, argument_list; 335, 336; 336, attribute; 336, 337; 336, 338; 337, identifier:self; 338, identifier:actions; 339, identifier:max_actions; 340, block; 340, 341; 340, 355; 340, 372; 340, 386; 340, 395; 340, 404; 341, expression_statement; 341, 342; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:logger; 345, identifier:warning; 346, argument_list; 346, 347; 346, 348; 346, 354; 347, string:"I have to del some actions (currently: %d, max: %d)..., sorry :("; 348, call; 348, 349; 348, 350; 349, identifier:len; 350, argument_list; 350, 351; 351, attribute; 351, 352; 351, 353; 352, identifier:self; 353, identifier:actions; 354, identifier:max_actions; 355, expression_statement; 355, 356; 356, assignment; 356, 357; 356, 358; 357, identifier:to_del_actions; 358, list_comprehension; 358, 359; 358, 360; 359, identifier:c; 360, for_in_clause; 360, 361; 360, 362; 361, identifier:c; 362, call; 362, 363; 362, 364; 363, identifier:list; 364, argument_list; 364, 365; 365, call; 365, 366; 365, 371; 366, attribute; 366, 367; 366, 370; 367, attribute; 367, 368; 367, 369; 368, identifier:self; 369, identifier:actions; 370, identifier:values; 371, argument_list; 372, expression_statement; 372, 373; 373, call; 373, 374; 373, 377; 374, attribute; 374, 375; 374, 376; 375, identifier:to_del_actions; 376, identifier:sort; 377, argument_list; 377, 378; 378, keyword_argument; 378, 379; 378, 380; 379, identifier:key; 380, lambda; 380, 381; 380, 383; 381, lambda_parameters; 381, 382; 382, identifier:x; 383, attribute; 383, 384; 383, 385; 384, identifier:x; 385, identifier:creation_time; 386, expression_statement; 386, 387; 387, assignment; 387, 388; 387, 389; 388, identifier:to_del_actions; 389, subscript; 389, 390; 389, 391; 390, identifier:to_del_actions; 391, slice; 391, 392; 391, 393; 392, colon; 393, unary_operator:-; 393, 394; 394, identifier:max_actions; 395, expression_statement; 395, 396; 396, assignment; 396, 397; 396, 400; 397, attribute; 397, 398; 397, 399; 398, identifier:self; 399, identifier:nb_actions_dropped; 400, call; 400, 401; 400, 402; 401, identifier:len; 402, argument_list; 402, 403; 403, identifier:to_del_actions; 404, for_statement; 404, 405; 404, 406; 404, 407; 405, identifier:act; 406, identifier:to_del_actions; 407, block; 407, 408; 407, 429; 408, if_statement; 408, 409; 408, 414; 409, comparison_operator:==; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, identifier:act; 412, identifier:is_a; 413, string:'notification'; 414, block; 414, 415; 415, expression_statement; 415, 416; 416, call; 416, 417; 416, 427; 417, attribute; 417, 418; 417, 426; 418, call; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:self; 421, identifier:find_item_by_id; 422, argument_list; 422, 423; 423, attribute; 423, 424; 423, 425; 424, identifier:act; 425, identifier:ref; 426, identifier:remove_in_progress_notification; 427, argument_list; 427, 428; 428, identifier:act; 429, delete_statement; 429, 430; 430, subscript; 430, 431; 430, 434; 431, attribute; 431, 432; 431, 433; 432, identifier:self; 433, identifier:actions; 434, attribute; 434, 435; 434, 436; 435, identifier:act; 436, identifier:uuid | def clean_queues(self):
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))
self.nb_checks_dropped = 0
if max_checks and len(self.checks) > max_checks:
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]
elt.remove_in_progress_check(chk)
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]
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)
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, 14; 5, 52; 5, 66; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:now; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:time; 12, identifier:time; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:notifications; 17, list_comprehension; 17, 18; 17, 19; 17, 28; 18, identifier:a; 19, for_in_clause; 19, 20; 19, 21; 20, identifier:a; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:actions; 26, identifier:values; 27, argument_list; 28, if_clause; 28, 29; 29, boolean_operator:and; 29, 30; 29, 46; 30, boolean_operator:and; 30, 31; 30, 42; 31, boolean_operator:and; 31, 32; 31, 37; 32, comparison_operator:==; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:a; 35, identifier:is_a; 36, string:u'notification'; 37, comparison_operator:==; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:a; 40, identifier:status; 41, identifier:ACT_STATUS_SCHEDULED; 42, not_operator; 42, 43; 43, attribute; 43, 44; 43, 45; 44, identifier:a; 45, identifier:contact; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:a; 49, identifier:is_launchable; 50, argument_list; 50, 51; 51, identifier:now; 52, if_statement; 52, 53; 52, 54; 53, identifier:notifications; 54, block; 54, 55; 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; 61, string:"Scatter master notification: %d notifications"; 62, call; 62, 63; 62, 64; 63, identifier:len; 64, argument_list; 64, 65; 65, identifier:notifications; 66, for_statement; 66, 67; 66, 68; 66, 69; 67, identifier:notification; 68, identifier:notifications; 69, block; 69, 70; 69, 78; 69, 89; 69, 93; 69, 97; 69, 117; 69, 196; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:logger; 74, identifier:debug; 75, argument_list; 75, 76; 75, 77; 76, string:"Scheduler got a master notification: %s"; 77, identifier:notification; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:item; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:find_item_by_id; 85, argument_list; 85, 86; 86, attribute; 86, 87; 86, 88; 87, identifier:notification; 88, identifier:ref; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:children; 92, list:[]; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:notification_period; 96, None; 97, if_statement; 97, 98; 97, 106; 98, comparison_operator:is; 98, 99; 98, 105; 99, call; 99, 100; 99, 101; 100, identifier:getattr; 101, argument_list; 101, 102; 101, 103; 101, 104; 102, identifier:item; 103, string:'notification_period'; 104, None; 105, None; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:notification_period; 110, subscript; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:timeperiods; 114, attribute; 114, 115; 114, 116; 115, identifier:item; 116, identifier:notification_period; 117, if_statement; 117, 118; 117, 135; 118, not_operator; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:item; 122, identifier:is_blocking_notifications; 123, argument_list; 123, 124; 123, 125; 123, 128; 123, 131; 123, 134; 124, identifier:notification_period; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:hosts; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:services; 131, attribute; 131, 132; 131, 133; 132, identifier:notification; 133, identifier:type; 134, identifier:now; 135, block; 135, 136; 135, 171; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:children; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:item; 142, identifier:scatter_notification; 143, argument_list; 143, 144; 143, 145; 143, 148; 143, 151; 143, 154; 143, 157; 143, 160; 144, identifier:notification; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:contacts; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:notificationways; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:timeperiods; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:macromodulations; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:escalations; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:find_item_by_id; 164, argument_list; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:getattr; 167, argument_list; 167, 168; 167, 169; 167, 170; 168, identifier:item; 169, string:"host"; 170, None; 171, for_statement; 171, 172; 171, 173; 171, 174; 172, identifier:notif; 173, identifier:children; 174, block; 174, 175; 174, 183; 174, 189; 175, expression_statement; 175, 176; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:logger; 179, identifier:debug; 180, argument_list; 180, 181; 180, 182; 181, string:" - child notification: %s"; 182, identifier:notif; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:notif; 187, identifier:status; 188, identifier:ACT_STATUS_SCHEDULED; 189, expression_statement; 189, 190; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:add; 194, argument_list; 194, 195; 195, identifier:notif; 196, if_statement; 196, 197; 196, 202; 196, 277; 197, comparison_operator:==; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:notification; 200, identifier:type; 201, string:u'PROBLEM'; 202, block; 202, 203; 202, 214; 203, if_statement; 203, 204; 203, 205; 204, identifier:children; 205, block; 205, 206; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:item; 210, identifier:current_notification_number; 211, attribute; 211, 212; 211, 213; 212, identifier:notification; 213, identifier:notif_nb; 214, if_statement; 214, 215; 214, 224; 214, 260; 215, boolean_operator:and; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:item; 218, identifier:notification_interval; 219, comparison_operator:is; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:notification; 222, identifier:t_to_go; 223, None; 224, block; 224, 225; 224, 242; 224, 252; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:notification; 229, identifier:t_to_go; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:item; 233, identifier:get_next_notification_time; 234, argument_list; 234, 235; 234, 236; 234, 239; 235, identifier:notification; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:escalations; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:timeperiods; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:notification; 246, identifier:notif_nb; 247, binary_operator:+; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:item; 250, identifier:current_notification_number; 251, integer:1; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:logger; 256, identifier:debug; 257, argument_list; 257, 258; 257, 259; 258, string:"Repeat master notification: %s"; 259, identifier:notification; 260, else_clause; 260, 261; 261, block; 261, 262; 261, 269; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:item; 266, identifier:remove_in_progress_notification; 267, argument_list; 267, 268; 268, identifier:notification; 269, expression_statement; 269, 270; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:logger; 273, identifier:debug; 274, argument_list; 274, 275; 274, 276; 275, string:"Remove master notification (no repeat): %s"; 276, identifier:notification; 277, else_clause; 277, 278; 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:logger; 283, identifier:debug; 284, argument_list; 284, 285; 284, 286; 285, string:"Remove master notification (no more a problem): %s"; 286, identifier:notification; 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 | def scatter_master_notifications(self):
now = time.time()
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)
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):
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
self.add(notif)
if notification.type == u'PROBLEM':
if children:
item.current_notification_number = notification.notif_nb
if item.notification_interval and notification.t_to_go is not None:
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:
item.remove_in_progress_notification(notification)
logger.debug("Remove master notification (no repeat): %s", notification)
else:
logger.debug("Remove master notification (no more a problem): %s", notification)
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, 18; 6, for_statement; 6, 7; 6, 8; 6, 11; 7, identifier:elt; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:hosts; 11, block; 11, 12; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:elt; 16, identifier:raise_initial_state; 17, argument_list; 18, for_statement; 18, 19; 18, 20; 18, 23; 19, identifier:elt; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:services; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:elt; 28, identifier:raise_initial_state; 29, argument_list | def log_initial_states(self):
for elt in self.hosts:
elt.raise_initial_state()
for elt in self.services:
elt.raise_initial_state() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_retention_data; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 16; 5, 106; 5, 119; 5, 213; 5, 226; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:retention_data; 9, dictionary; 9, 10; 9, 13; 10, pair; 10, 11; 10, 12; 11, string:'hosts'; 12, dictionary; 13, pair; 13, 14; 13, 15; 14, string:'services'; 15, dictionary; 16, for_statement; 16, 17; 16, 18; 16, 21; 17, identifier:host; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:hosts; 21, block; 21, 22; 21, 26; 21, 34; 21, 45; 21, 96; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:h_dict; 25, dictionary; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:properties; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:host; 32, identifier:__class__; 33, identifier:properties; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:properties; 38, identifier:update; 39, argument_list; 39, 40; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:host; 43, identifier:__class__; 44, identifier:running_properties; 45, for_statement; 45, 46; 45, 49; 45, 57; 46, pattern_list; 46, 47; 46, 48; 47, identifier:prop; 48, identifier:entry; 49, call; 49, 50; 49, 51; 50, identifier:list; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:properties; 55, identifier:items; 56, argument_list; 57, block; 57, 58; 57, 65; 57, 73; 57, 79; 57, 90; 58, if_statement; 58, 59; 58, 63; 59, not_operator; 59, 60; 60, attribute; 60, 61; 60, 62; 61, identifier:entry; 62, identifier:retention; 63, block; 63, 64; 64, continue_statement; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:val; 68, call; 68, 69; 68, 70; 69, identifier:getattr; 70, argument_list; 70, 71; 70, 72; 71, identifier:host; 72, identifier:prop; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:prepare_retention; 76, attribute; 76, 77; 76, 78; 77, identifier:entry; 78, identifier:retention_preparation; 79, if_statement; 79, 80; 79, 81; 80, identifier:prepare_retention; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:val; 85, call; 85, 86; 85, 87; 86, identifier:prepare_retention; 87, argument_list; 87, 88; 87, 89; 88, identifier:host; 89, identifier:val; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:h_dict; 94, identifier:prop; 95, identifier:val; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 105; 98, subscript; 98, 99; 98, 102; 99, subscript; 99, 100; 99, 101; 100, identifier:retention_data; 101, string:'hosts'; 102, attribute; 102, 103; 102, 104; 103, identifier:host; 104, identifier:host_name; 105, identifier:h_dict; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:logger; 110, identifier:info; 111, argument_list; 111, 112; 111, 113; 112, string:'%d hosts sent to retention'; 113, call; 113, 114; 113, 115; 114, identifier:len; 115, argument_list; 115, 116; 116, subscript; 116, 117; 116, 118; 117, identifier:retention_data; 118, string:'hosts'; 119, for_statement; 119, 120; 119, 121; 119, 124; 120, identifier:service; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:services; 124, block; 124, 125; 124, 129; 124, 137; 124, 148; 124, 199; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:s_dict; 128, dictionary; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:properties; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:service; 135, identifier:__class__; 136, identifier:properties; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:properties; 141, identifier:update; 142, argument_list; 142, 143; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:service; 146, identifier:__class__; 147, identifier:running_properties; 148, for_statement; 148, 149; 148, 152; 148, 160; 149, pattern_list; 149, 150; 149, 151; 150, identifier:prop; 151, identifier:entry; 152, call; 152, 153; 152, 154; 153, identifier:list; 154, argument_list; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:properties; 158, identifier:items; 159, argument_list; 160, block; 160, 161; 160, 168; 160, 176; 160, 182; 160, 193; 161, if_statement; 161, 162; 161, 166; 162, not_operator; 162, 163; 163, attribute; 163, 164; 163, 165; 164, identifier:entry; 165, identifier:retention; 166, block; 166, 167; 167, continue_statement; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:val; 171, call; 171, 172; 171, 173; 172, identifier:getattr; 173, argument_list; 173, 174; 173, 175; 174, identifier:service; 175, identifier:prop; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:prepare_retention; 179, attribute; 179, 180; 179, 181; 180, identifier:entry; 181, identifier:retention_preparation; 182, if_statement; 182, 183; 182, 184; 183, identifier:prepare_retention; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:val; 188, call; 188, 189; 188, 190; 189, identifier:prepare_retention; 190, argument_list; 190, 191; 190, 192; 191, identifier:service; 192, identifier:val; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, subscript; 195, 196; 195, 197; 196, identifier:s_dict; 197, identifier:prop; 198, identifier:val; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 212; 201, subscript; 201, 202; 201, 205; 202, subscript; 202, 203; 202, 204; 203, identifier:retention_data; 204, string:'services'; 205, tuple; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:service; 208, identifier:host_name; 209, attribute; 209, 210; 209, 211; 210, identifier:service; 211, identifier:service_description; 212, identifier:s_dict; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:logger; 217, identifier:info; 218, argument_list; 218, 219; 218, 220; 219, string:'%d services sent to retention'; 220, call; 220, 221; 220, 222; 221, identifier:len; 222, argument_list; 222, 223; 223, subscript; 223, 224; 223, 225; 224, identifier:retention_data; 225, string:'services'; 226, return_statement; 226, 227; 227, identifier:retention_data | def get_retention_data(self):
retention_data = {
'hosts': {}, 'services': {}
}
for host in self.hosts:
h_dict = {}
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)
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']))
for service in self.services:
s_dict = {}
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)
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; 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, block; 7, 8; 7, 16; 7, 27; 7, 86; 7, 132; 7, 138; 7, 224; 7, 256; 7, 284; 7, 290; 7, 296; 7, 334; 7, 340; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:properties; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:item; 14, identifier:__class__; 15, identifier:properties; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:properties; 20, identifier:update; 21, argument_list; 21, 22; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:item; 25, identifier:__class__; 26, identifier:running_properties; 27, for_statement; 27, 28; 27, 31; 27, 39; 28, pattern_list; 28, 29; 28, 30; 29, identifier:prop; 30, identifier:entry; 31, call; 31, 32; 31, 33; 32, identifier:list; 33, argument_list; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:properties; 37, identifier:items; 38, argument_list; 39, block; 39, 40; 39, 47; 39, 53; 39, 59; 40, if_statement; 40, 41; 40, 45; 41, not_operator; 41, 42; 42, attribute; 42, 43; 42, 44; 43, identifier:entry; 44, identifier:retention; 45, block; 45, 46; 46, continue_statement; 47, if_statement; 47, 48; 47, 51; 48, comparison_operator:not; 48, 49; 48, 50; 49, identifier:prop; 50, identifier:data; 51, block; 51, 52; 52, continue_statement; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:restore_retention; 56, attribute; 56, 57; 56, 58; 57, identifier:entry; 58, identifier:retention_restoration; 59, if_statement; 59, 60; 59, 61; 59, 75; 60, identifier:restore_retention; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:setattr; 65, argument_list; 65, 66; 65, 67; 65, 68; 66, identifier:item; 67, identifier:prop; 68, call; 68, 69; 68, 70; 69, identifier:restore_retention; 70, argument_list; 70, 71; 70, 72; 71, identifier:item; 72, subscript; 72, 73; 72, 74; 73, identifier:data; 74, identifier:prop; 75, else_clause; 75, 76; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:setattr; 80, argument_list; 80, 81; 80, 82; 80, 83; 81, identifier:item; 82, identifier:prop; 83, subscript; 83, 84; 83, 85; 84, identifier:data; 85, identifier:prop; 86, for_statement; 86, 87; 86, 88; 86, 91; 87, identifier:notification_uuid; 88, attribute; 88, 89; 88, 90; 89, identifier:item; 90, identifier:notifications_in_progress; 91, block; 91, 92; 91, 100; 91, 108; 91, 117; 91, 125; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:notification; 95, subscript; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:item; 98, identifier:notifications_in_progress; 99, identifier:notification_uuid; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, subscript; 102, 103; 102, 104; 103, identifier:notification; 104, string:'ref'; 105, attribute; 105, 106; 105, 107; 106, identifier:item; 107, identifier:uuid; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:my_notification; 111, call; 111, 112; 111, 113; 112, identifier:Notification; 113, argument_list; 113, 114; 114, keyword_argument; 114, 115; 114, 116; 115, identifier:params; 116, identifier:notification; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 124; 119, subscript; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:item; 122, identifier:notifications_in_progress; 123, identifier:notification_uuid; 124, identifier:my_notification; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:add; 130, argument_list; 130, 131; 131, identifier:my_notification; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:item; 136, identifier:update_in_checking; 137, argument_list; 138, for_statement; 138, 139; 138, 140; 138, 143; 139, identifier:downtime_uuid; 140, subscript; 140, 141; 140, 142; 141, identifier:data; 142, string:'downtimes'; 143, block; 143, 144; 143, 152; 143, 160; 143, 169; 143, 189; 143, 217; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:downtime; 147, subscript; 147, 148; 147, 151; 148, subscript; 148, 149; 148, 150; 149, identifier:data; 150, string:'downtimes'; 151, identifier:downtime_uuid; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 157; 154, subscript; 154, 155; 154, 156; 155, identifier:downtime; 156, string:'ref'; 157, attribute; 157, 158; 157, 159; 158, identifier:item; 159, identifier:uuid; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:my_downtime; 163, call; 163, 164; 163, 165; 164, identifier:Downtime; 165, argument_list; 165, 166; 166, keyword_argument; 166, 167; 166, 168; 167, identifier:params; 168, identifier:downtime; 169, if_statement; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:downtime; 172, string:'comment_id'; 173, block; 173, 174; 174, if_statement; 174, 175; 174, 182; 175, comparison_operator:not; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:downtime; 178, string:'comment_id'; 179, subscript; 179, 180; 179, 181; 180, identifier:data; 181, string:'comments'; 182, block; 182, 183; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, subscript; 185, 186; 185, 187; 186, identifier:downtime; 187, string:'comment_id'; 188, string:''; 189, if_statement; 189, 190; 189, 195; 190, comparison_operator:in; 190, 191; 190, 192; 191, string:'uuid'; 192, subscript; 192, 193; 192, 194; 193, identifier:downtime; 194, string:'comment_id'; 195, block; 195, 196; 195, 207; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 203; 198, attribute; 198, 199; 198, 202; 199, subscript; 199, 200; 199, 201; 200, identifier:data; 201, string:'comments'; 202, identifier:append; 203, argument_list; 203, 204; 204, subscript; 204, 205; 204, 206; 205, identifier:downtime; 206, string:'comment_id'; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:downtime; 211, string:'comment_id'; 212, subscript; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:downtime; 215, string:'comment_id'; 216, string:'uuid'; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:item; 221, identifier:add_downtime; 222, argument_list; 222, 223; 223, identifier:my_downtime; 224, for_statement; 224, 225; 224, 226; 224, 229; 225, identifier:comment_uuid; 226, subscript; 226, 227; 226, 228; 227, identifier:data; 228, string:'comments'; 229, block; 229, 230; 229, 238; 229, 246; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:comment; 233, subscript; 233, 234; 233, 237; 234, subscript; 234, 235; 234, 236; 235, identifier:data; 236, string:'comments'; 237, identifier:comment_uuid; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 243; 240, subscript; 240, 241; 240, 242; 241, identifier:comment; 242, string:'ref'; 243, attribute; 243, 244; 243, 245; 244, identifier:item; 245, identifier:uuid; 246, expression_statement; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:item; 250, identifier:add_comment; 251, argument_list; 251, 252; 252, call; 252, 253; 252, 254; 253, identifier:Comment; 254, argument_list; 254, 255; 255, identifier:comment; 256, if_statement; 256, 257; 256, 262; 257, comparison_operator:is; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:item; 260, identifier:acknowledgement; 261, None; 262, block; 262, 263; 262, 273; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 270; 265, subscript; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:item; 268, identifier:acknowledgement; 269, string:'ref'; 270, attribute; 270, 271; 270, 272; 271, identifier:item; 272, identifier:uuid; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 278; 275, attribute; 275, 276; 275, 277; 276, identifier:item; 277, identifier:acknowledgement; 278, call; 278, 279; 278, 280; 279, identifier:Acknowledge; 280, argument_list; 280, 281; 281, attribute; 281, 282; 281, 283; 282, identifier:item; 283, identifier:acknowledgement; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:new_notified_contacts; 287, call; 287, 288; 287, 289; 288, identifier:set; 289, argument_list; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:new_notified_contacts_ids; 293, call; 293, 294; 293, 295; 294, identifier:set; 295, argument_list; 296, for_statement; 296, 297; 296, 298; 296, 301; 297, identifier:contact_name; 298, attribute; 298, 299; 298, 300; 299, identifier:item; 300, identifier:notified_contacts; 301, block; 301, 302; 301, 313; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:contact; 305, call; 305, 306; 305, 311; 306, attribute; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:self; 309, identifier:contacts; 310, identifier:find_by_name; 311, argument_list; 311, 312; 312, identifier:contact_name; 313, if_statement; 313, 314; 313, 317; 314, comparison_operator:is; 314, 315; 314, 316; 315, identifier:contact; 316, None; 317, block; 317, 318; 317, 325; 318, expression_statement; 318, 319; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:new_notified_contacts; 322, identifier:add; 323, argument_list; 323, 324; 324, identifier:contact_name; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:new_notified_contacts_ids; 329, identifier:add; 330, argument_list; 330, 331; 331, attribute; 331, 332; 331, 333; 332, identifier:contact; 333, identifier:uuid; 334, expression_statement; 334, 335; 335, assignment; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:item; 338, identifier:notified_contacts; 339, identifier:new_notified_contacts; 340, expression_statement; 340, 341; 341, assignment; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:item; 344, identifier:notified_contacts_ids; 345, identifier:new_notified_contacts_ids | def restore_retention_data_item(self, data, item):
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
restore_retention = entry.retention_restoration
if restore_retention:
setattr(item, prop, restore_retention(item, data[prop]))
else:
setattr(item, prop, data[prop])
for notification_uuid in item.notifications_in_progress:
notification = item.notifications_in_progress[notification_uuid]
notification['ref'] = item.uuid
my_notification = Notification(params=notification)
item.notifications_in_progress[notification_uuid] = my_notification
self.add(my_notification)
item.update_in_checking()
for downtime_uuid in data['downtimes']:
downtime = data['downtimes'][downtime_uuid]
downtime['ref'] = item.uuid
my_downtime = Downtime(params=downtime)
if downtime['comment_id']:
if downtime['comment_id'] not in data['comments']:
downtime['comment_id'] = ''
if 'uuid' in downtime['comment_id']:
data['comments'].append(downtime['comment_id'])
downtime['comment_id'] = downtime['comment_id']['uuid']
item.add_downtime(my_downtime)
for comment_uuid in data['comments']:
comment = data['comments'][comment_uuid]
comment['ref'] = item.uuid
item.add_comment(Comment(comment))
if item.acknowledgement is not None:
item.acknowledgement['ref'] = item.uuid
item.acknowledgement = Acknowledge(item.acknowledgement)
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; 2, function_name:fill_initial_broks; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:broker_name; 6, block; 6, 7; 6, 11; 6, 23; 6, 96; 6, 117; 6, 132; 6, 140; 6, 148; 6, 176; 6, 191; 6, 206; 6, 309; 6, 327; 6, 335; 6, 350; 6, 362; 6, 368; 6, 374; 6, 385; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:broker_uuid; 10, None; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:logger; 15, identifier:debug; 16, argument_list; 16, 17; 16, 18; 17, string:"My brokers: %s"; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:my_daemon; 22, identifier:brokers; 23, for_statement; 23, 24; 23, 25; 23, 37; 23, 69; 24, identifier:broker_link; 25, call; 25, 26; 25, 27; 26, identifier:list; 27, argument_list; 27, 28; 28, call; 28, 29; 28, 36; 29, attribute; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:my_daemon; 34, identifier:brokers; 35, identifier:values; 36, argument_list; 37, block; 37, 38; 37, 46; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:logger; 42, identifier:debug; 43, argument_list; 43, 44; 43, 45; 44, string:"Searching broker: %s"; 45, identifier:broker_link; 46, if_statement; 46, 47; 46, 52; 47, comparison_operator:==; 47, 48; 47, 49; 48, identifier:broker_name; 49, attribute; 49, 50; 49, 51; 50, identifier:broker_link; 51, identifier:name; 52, block; 52, 53; 52, 59; 52, 68; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:broker_uuid; 56, attribute; 56, 57; 56, 58; 57, identifier:broker_link; 58, identifier:uuid; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:logger; 63, identifier:info; 64, argument_list; 64, 65; 64, 66; 64, 67; 65, string:"Filling initial broks for: %s (%s)"; 66, identifier:broker_name; 67, identifier:broker_uuid; 68, break_statement; 69, else_clause; 69, 70; 70, block; 70, 71; 70, 94; 71, if_statement; 71, 72; 71, 75; 71, 84; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:pushed_conf; 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:error; 81, argument_list; 81, 82; 81, 83; 82, string:"Requested initial broks for an unknown broker: %s"; 83, identifier:broker_name; 84, else_clause; 84, 85; 85, block; 85, 86; 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:"Requested initial broks for an unknown broker: %s"; 93, identifier:broker_name; 94, return_statement; 94, 95; 95, integer:0; 96, if_statement; 96, 97; 96, 106; 97, attribute; 97, 98; 97, 105; 98, subscript; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:my_daemon; 103, identifier:brokers; 104, identifier:broker_uuid; 105, identifier:initialized; 106, block; 106, 107; 106, 115; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:logger; 111, identifier:warning; 112, argument_list; 112, 113; 112, 114; 113, string:"The broker %s still got its initial broks..."; 114, identifier:broker_name; 115, return_statement; 115, 116; 116, integer:0; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:initial_broks_count; 120, call; 120, 121; 120, 122; 121, identifier:len; 122, argument_list; 122, 123; 123, attribute; 123, 124; 123, 131; 124, subscript; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:my_daemon; 129, identifier:brokers; 130, identifier:broker_uuid; 131, identifier:broks; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:brok; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:get_program_status_brok; 139, argument_list; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:add_brok; 145, argument_list; 145, 146; 145, 147; 146, identifier:brok; 147, identifier:broker_uuid; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:initial_status_types; 151, tuple; 151, 152; 151, 155; 151, 158; 151, 161; 151, 164; 151, 167; 151, 170; 151, 173; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:timeperiods; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:commands; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:contacts; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:contactgroups; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:hosts; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:hostgroups; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:services; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:servicegroups; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:pushed_conf; 182, identifier:skip_initial_broks; 183, call; 183, 184; 183, 185; 184, identifier:getattr; 185, argument_list; 185, 186; 185, 189; 185, 190; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:pushed_conf; 189, string:'skip_initial_broks'; 190, False; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:logger; 195, identifier:debug; 196, argument_list; 196, 197; 196, 198; 197, string:"Skipping initial broks? %s"; 198, call; 198, 199; 198, 200; 199, identifier:str; 200, argument_list; 200, 201; 201, attribute; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:pushed_conf; 205, identifier:skip_initial_broks; 206, if_statement; 206, 207; 206, 213; 207, not_operator; 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, block; 213, 214; 213, 257; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:initial_status_types; 217, tuple; 217, 218; 217, 221; 217, 224; 217, 227; 217, 230; 217, 233; 217, 236; 217, 239; 217, 242; 217, 245; 217, 248; 217, 251; 217, 254; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:realms; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:timeperiods; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:commands; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:notificationways; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:contacts; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:contactgroups; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:hosts; 239, attribute; 239, 240; 239, 241; 240, identifier:self; 241, identifier:hostgroups; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:hostdependencies; 245, attribute; 245, 246; 245, 247; 246, identifier:self; 247, identifier:services; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:servicegroups; 251, attribute; 251, 252; 251, 253; 252, identifier:self; 253, identifier:servicedependencies; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:escalations; 257, for_statement; 257, 258; 257, 259; 257, 260; 258, identifier:tab; 259, identifier:initial_status_types; 260, block; 260, 261; 261, for_statement; 261, 262; 261, 263; 261, 264; 262, identifier:item; 263, identifier:tab; 264, block; 264, 265; 264, 269; 264, 292; 264, 301; 265, expression_statement; 265, 266; 266, assignment; 266, 267; 266, 268; 267, identifier:member_items; 268, None; 269, if_statement; 269, 270; 269, 275; 270, call; 270, 271; 270, 272; 271, identifier:hasattr; 272, argument_list; 272, 273; 272, 274; 273, identifier:item; 274, string:'members'; 275, block; 275, 276; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:member_items; 279, call; 279, 280; 279, 281; 280, identifier:getattr; 281, argument_list; 281, 282; 281, 283; 282, identifier:self; 283, call; 283, 284; 283, 289; 284, attribute; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:item; 287, identifier:my_type; 288, identifier:replace; 289, argument_list; 289, 290; 289, 291; 290, string:"group"; 291, string:"s"; 292, expression_statement; 292, 293; 293, assignment; 293, 294; 293, 295; 294, identifier:brok; 295, call; 295, 296; 295, 299; 296, attribute; 296, 297; 296, 298; 297, identifier:item; 298, identifier:get_initial_status_brok; 299, argument_list; 299, 300; 300, identifier:member_items; 301, expression_statement; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:self; 305, identifier:add_brok; 306, argument_list; 306, 307; 306, 308; 307, identifier:brok; 308, identifier:broker_uuid; 309, expression_statement; 309, 310; 310, assignment; 310, 311; 310, 312; 311, identifier:brok; 312, call; 312, 313; 312, 314; 313, identifier:Brok; 314, argument_list; 314, 315; 315, dictionary; 315, 316; 315, 319; 316, pair; 316, 317; 316, 318; 317, string:'type'; 318, string:'initial_broks_done'; 319, pair; 319, 320; 319, 321; 320, string:'data'; 321, dictionary; 321, 322; 322, pair; 322, 323; 322, 324; 323, string:'instance_id'; 324, attribute; 324, 325; 324, 326; 325, identifier:self; 326, identifier:instance_id; 327, expression_statement; 327, 328; 328, call; 328, 329; 328, 332; 329, attribute; 329, 330; 329, 331; 330, identifier:self; 331, identifier:add_brok; 332, argument_list; 332, 333; 332, 334; 333, identifier:brok; 334, identifier:broker_uuid; 335, expression_statement; 335, 336; 336, assignment; 336, 337; 336, 338; 337, identifier:final_broks_count; 338, call; 338, 339; 338, 340; 339, identifier:len; 340, argument_list; 340, 341; 341, attribute; 341, 342; 341, 349; 342, subscript; 342, 343; 342, 348; 343, attribute; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:self; 346, identifier:my_daemon; 347, identifier:brokers; 348, identifier:broker_uuid; 349, identifier:broks; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 361; 352, attribute; 352, 353; 352, 360; 353, subscript; 353, 354; 353, 359; 354, attribute; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:self; 357, identifier:my_daemon; 358, identifier:brokers; 359, identifier:broker_uuid; 360, identifier:initialized; 361, True; 362, expression_statement; 362, 363; 363, call; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:self; 366, identifier:send_broks_to_modules; 367, argument_list; 368, expression_statement; 368, 369; 369, assignment; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:self; 372, identifier:raised_initial_broks; 373, True; 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; 379, 381; 379, 384; 380, string:"Created %d initial broks for %s"; 381, binary_operator:-; 381, 382; 381, 383; 382, identifier:final_broks_count; 383, identifier:initial_broks_count; 384, identifier:broker_name; 385, return_statement; 385, 386; 386, binary_operator:-; 386, 387; 386, 388; 387, identifier:final_broks_count; 388, identifier:initial_broks_count | def fill_initial_broks(self, broker_name):
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:
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)
brok = self.get_program_status_brok()
self.add_brok(brok, broker_uuid)
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:
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:
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)
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
self.send_broks_to_modules()
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; 2, function_name:consume_results; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 16; 5, 36; 5, 162; 5, 166; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:queue_size; 9, call; 9, 10; 9, 15; 10, attribute; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:waiting_results; 14, identifier:qsize; 15, argument_list; 16, for_statement; 16, 17; 16, 18; 16, 22; 17, identifier:_; 18, call; 18, 19; 18, 20; 19, identifier:range; 20, argument_list; 20, 21; 21, identifier:queue_size; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:manage_results; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 35; 30, attribute; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:waiting_results; 34, identifier:get; 35, argument_list; 36, for_statement; 36, 37; 36, 38; 36, 48; 37, identifier:chk; 38, call; 38, 39; 38, 40; 39, identifier:list; 40, argument_list; 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:checks; 46, identifier:values; 47, argument_list; 48, block; 48, 49; 49, if_statement; 49, 50; 49, 55; 50, comparison_operator:==; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:chk; 53, identifier:status; 54, identifier:ACT_STATUS_WAIT_CONSUME; 55, block; 55, 56; 55, 64; 55, 75; 55, 79; 55, 99; 55, 143; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:logger; 60, identifier:debug; 61, argument_list; 61, 62; 61, 63; 62, string:"Consuming: %s"; 63, identifier:chk; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:item; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:find_item_by_id; 71, argument_list; 71, 72; 72, attribute; 72, 73; 72, 74; 73, identifier:chk; 74, identifier:ref; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:notification_period; 78, None; 79, if_statement; 79, 80; 79, 88; 80, comparison_operator:is; 80, 81; 80, 87; 81, call; 81, 82; 81, 83; 82, identifier:getattr; 83, argument_list; 83, 84; 83, 85; 83, 86; 84, identifier:item; 85, string:'notification_period'; 86, None; 87, None; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:notification_period; 92, subscript; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:timeperiods; 96, attribute; 96, 97; 96, 98; 97, identifier:item; 98, identifier:notification_period; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:dep_checks; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:item; 105, identifier:consume_result; 106, argument_list; 106, 107; 106, 108; 106, 109; 106, 112; 106, 115; 106, 118; 106, 121; 106, 124; 106, 127; 106, 130; 106, 133; 107, identifier:chk; 108, identifier:notification_period; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:hosts; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:services; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:timeperiods; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:macromodulations; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:checkmodulations; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:businessimpactmodulations; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:resultmodulations; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:checks; 133, boolean_operator:and; 133, 134; 133, 139; 134, attribute; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:pushed_conf; 138, identifier:log_active_checks; 139, not_operator; 139, 140; 140, attribute; 140, 141; 140, 142; 141, identifier:chk; 142, identifier:passive_check; 143, for_statement; 143, 144; 143, 145; 143, 146; 144, identifier:check; 145, identifier:dep_checks; 146, block; 146, 147; 146, 155; 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; 152, 154; 153, string:"-> raised a dependency check: %s"; 154, identifier:chk; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:add; 160, argument_list; 160, 161; 161, identifier:check; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:have_resolved_checks; 165, True; 166, while_statement; 166, 167; 166, 168; 167, identifier:have_resolved_checks; 168, block; 168, 169; 168, 173; 168, 220; 169, expression_statement; 169, 170; 170, assignment; 170, 171; 170, 172; 171, identifier:have_resolved_checks; 172, False; 173, for_statement; 173, 174; 173, 175; 173, 185; 174, identifier:chk; 175, call; 175, 176; 175, 177; 176, identifier:list; 177, argument_list; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:checks; 183, identifier:values; 184, argument_list; 185, block; 185, 186; 186, if_statement; 186, 187; 186, 192; 187, comparison_operator:==; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:chk; 190, identifier:status; 191, identifier:ACT_STATUS_WAITING_ME; 192, block; 192, 193; 192, 214; 193, for_statement; 193, 194; 193, 195; 193, 198; 194, identifier:dependent_checks; 195, attribute; 195, 196; 195, 197; 196, identifier:chk; 197, identifier:depend_on_me; 198, block; 198, 199; 198, 210; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 206; 201, attribute; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:dependent_checks; 204, identifier:depend_on; 205, identifier:remove; 206, argument_list; 206, 207; 207, attribute; 207, 208; 207, 209; 208, identifier:chk; 209, identifier:uuid; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:have_resolved_checks; 213, True; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:chk; 218, identifier:status; 219, identifier:ACT_STATUS_ZOMBIE; 220, for_statement; 220, 221; 220, 222; 220, 232; 221, identifier:chk; 222, call; 222, 223; 222, 224; 223, identifier:list; 224, argument_list; 224, 225; 225, call; 225, 226; 225, 231; 226, attribute; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:checks; 230, identifier:values; 231, argument_list; 232, block; 232, 233; 233, if_statement; 233, 234; 233, 244; 234, boolean_operator:and; 234, 235; 234, 240; 235, comparison_operator:==; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:chk; 238, identifier:status; 239, identifier:ACT_STATUS_WAIT_DEPEND; 240, not_operator; 240, 241; 241, attribute; 241, 242; 241, 243; 242, identifier:chk; 243, identifier:depend_on; 244, block; 244, 245; 244, 256; 244, 260; 244, 280; 244, 324; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:item; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:find_item_by_id; 252, argument_list; 252, 253; 253, attribute; 253, 254; 253, 255; 254, identifier:chk; 255, identifier:ref; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:notification_period; 259, None; 260, if_statement; 260, 261; 260, 269; 261, comparison_operator:is; 261, 262; 261, 268; 262, call; 262, 263; 262, 264; 263, identifier:getattr; 264, argument_list; 264, 265; 264, 266; 264, 267; 265, identifier:item; 266, string:'notification_period'; 267, None; 268, None; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:notification_period; 273, subscript; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:self; 276, identifier:timeperiods; 277, attribute; 277, 278; 277, 279; 278, identifier:item; 279, identifier:notification_period; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:dep_checks; 283, call; 283, 284; 283, 287; 284, attribute; 284, 285; 284, 286; 285, identifier:item; 286, identifier:consume_result; 287, argument_list; 287, 288; 287, 289; 287, 290; 287, 293; 287, 296; 287, 299; 287, 302; 287, 305; 287, 308; 287, 311; 287, 314; 288, identifier:chk; 289, identifier:notification_period; 290, attribute; 290, 291; 290, 292; 291, identifier:self; 292, identifier:hosts; 293, attribute; 293, 294; 293, 295; 294, identifier:self; 295, identifier:services; 296, attribute; 296, 297; 296, 298; 297, identifier:self; 298, identifier:timeperiods; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:macromodulations; 302, attribute; 302, 303; 302, 304; 303, identifier:self; 304, identifier:checkmodulations; 305, attribute; 305, 306; 305, 307; 306, identifier:self; 307, identifier:businessimpactmodulations; 308, attribute; 308, 309; 308, 310; 309, identifier:self; 310, identifier:resultmodulations; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:checks; 314, boolean_operator:and; 314, 315; 314, 320; 315, attribute; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:self; 318, identifier:pushed_conf; 319, identifier:log_active_checks; 320, not_operator; 320, 321; 321, attribute; 321, 322; 321, 323; 322, identifier:chk; 323, identifier:passive_check; 324, for_statement; 324, 325; 324, 326; 324, 327; 325, identifier:check; 326, identifier:dep_checks; 327, block; 327, 328; 328, expression_statement; 328, 329; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:self; 332, identifier:add; 333, argument_list; 333, 334; 334, identifier:check | def consume_results(self):
queue_size = self.waiting_results.qsize()
for _ in range(queue_size):
self.manage_results(self.waiting_results.get())
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)
for check in dep_checks:
logger.debug("-> raised a dependency check: %s", chk)
self.add(check)
have_resolved_checks = True
while have_resolved_checks:
have_resolved_checks = False
for chk in list(self.checks.values()):
if chk.status == ACT_STATUS_WAITING_ME:
for dependent_checks in chk.depend_on_me:
dependent_checks.depend_on.remove(chk.uuid)
have_resolved_checks = True
chk.status = ACT_STATUS_ZOMBIE
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, 14; 5, 18; 5, 22; 5, 65; 5, 70; 5, 81; 5, 143; 5, 185; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:t00; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:time; 12, identifier:time; 13, argument_list; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:nb_sent; 17, integer:0; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:broks; 21, list:[]; 22, for_statement; 22, 23; 22, 24; 22, 36; 23, identifier:broker_link; 24, call; 24, 25; 24, 26; 25, identifier:list; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 35; 28, attribute; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:my_daemon; 33, identifier:brokers; 34, identifier:values; 35, argument_list; 36, block; 36, 37; 37, for_statement; 37, 38; 37, 39; 37, 42; 38, identifier:brok; 39, attribute; 39, 40; 39, 41; 40, identifier:broker_link; 41, identifier:broks; 42, block; 42, 43; 43, if_statement; 43, 44; 43, 51; 44, not_operator; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:getattr; 47, argument_list; 47, 48; 47, 49; 47, 50; 48, identifier:brok; 49, string:'sent_to_externals'; 50, False; 51, block; 51, 52; 51, 58; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:brok; 56, identifier:to_send; 57, True; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:broks; 62, identifier:append; 63, argument_list; 63, 64; 64, identifier:brok; 65, if_statement; 65, 66; 65, 68; 66, not_operator; 66, 67; 67, identifier:broks; 68, block; 68, 69; 69, return_statement; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:logger; 74, identifier:debug; 75, argument_list; 75, 76; 75, 77; 76, string:"sending %d broks to modules..."; 77, call; 77, 78; 77, 79; 78, identifier:len; 79, argument_list; 79, 80; 80, identifier:broks; 81, for_statement; 81, 82; 81, 83; 81, 92; 82, identifier:mod; 83, call; 83, 84; 83, 91; 84, attribute; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:my_daemon; 89, identifier:modules_manager; 90, identifier:get_external_instances; 91, argument_list; 92, block; 92, 93; 92, 105; 92, 111; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:logger; 97, identifier:debug; 98, argument_list; 98, 99; 98, 100; 99, string:"Look for sending to module %s"; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:mod; 103, identifier:get_name; 104, argument_list; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:module_queue; 108, attribute; 108, 109; 108, 110; 109, identifier:mod; 110, identifier:to_q; 111, if_statement; 111, 112; 111, 113; 112, identifier:module_queue; 113, block; 113, 114; 113, 129; 113, 136; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:to_send; 117, list_comprehension; 117, 118; 117, 119; 117, 122; 118, identifier:b; 119, for_in_clause; 119, 120; 119, 121; 120, identifier:b; 121, identifier:broks; 122, if_clause; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:mod; 126, identifier:want_brok; 127, argument_list; 127, 128; 128, identifier:b; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:module_queue; 133, identifier:put; 134, argument_list; 134, 135; 135, identifier:to_send; 136, expression_statement; 136, 137; 137, augmented_assignment:+=; 137, 138; 137, 139; 138, identifier:nb_sent; 139, call; 139, 140; 139, 141; 140, identifier:len; 141, argument_list; 141, 142; 142, identifier:to_send; 143, for_statement; 143, 144; 143, 145; 143, 157; 144, identifier:broker_link; 145, call; 145, 146; 145, 147; 146, identifier:list; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 156; 149, attribute; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:my_daemon; 154, identifier:brokers; 155, identifier:values; 156, argument_list; 157, block; 157, 158; 158, for_statement; 158, 159; 158, 160; 158, 163; 159, identifier:brok; 160, attribute; 160, 161; 160, 162; 161, identifier:broker_link; 162, identifier:broks; 163, block; 163, 164; 164, if_statement; 164, 165; 164, 172; 165, not_operator; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:getattr; 168, argument_list; 168, 169; 168, 170; 168, 171; 169, identifier:brok; 170, string:'sent_to_externals'; 171, False; 172, block; 172, 173; 172, 179; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:brok; 177, identifier:to_send; 178, False; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:brok; 183, identifier:sent_to_externals; 184, True; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:logger; 189, identifier:debug; 190, argument_list; 190, 191; 190, 192; 190, 193; 191, string:"Time to send %d broks (after %d secs)"; 192, identifier:nb_sent; 193, binary_operator:-; 193, 194; 193, 199; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:time; 197, identifier:time; 198, argument_list; 199, identifier:t00 | def send_broks_to_modules(self):
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)
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, 13; 5, 19; 5, 25; 5, 33; 5, 44; 5, 96; 5, 100; 5, 104; 5, 271; 5, 279; 6, if_statement; 6, 7; 6, 11; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:unprocessed_external_commands; 11, block; 11, 12; 12, return_statement; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:commands_to_process; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:unprocessed_external_commands; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:unprocessed_external_commands; 24, list:[]; 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; 31, string:"Commands: %s"; 32, identifier:commands_to_process; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:logger; 37, identifier:debug; 38, argument_list; 38, 39; 38, 40; 39, string:"Commands to process: %d commands"; 40, call; 40, 41; 40, 42; 41, identifier:len; 42, argument_list; 42, 43; 43, identifier:commands_to_process; 44, for_statement; 44, 45; 44, 46; 44, 47; 45, identifier:ext_cmd; 46, identifier:commands_to_process; 47, block; 47, 48; 47, 59; 47, 70; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:cmd; 51, call; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:external_commands_manager; 56, identifier:resolve_command; 57, argument_list; 57, 58; 58, identifier:ext_cmd; 59, expression_statement; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:logger; 63, identifier:debug; 64, argument_list; 64, 65; 64, 66; 64, 69; 65, string:"Resolved command: %s, result: %s"; 66, attribute; 66, 67; 66, 68; 67, identifier:ext_cmd; 68, identifier:cmd_line; 69, identifier:cmd; 70, if_statement; 70, 71; 70, 76; 71, boolean_operator:and; 71, 72; 71, 73; 72, identifier:cmd; 73, subscript; 73, 74; 73, 75; 74, identifier:cmd; 75, string:'global'; 76, block; 76, 77; 77, for_statement; 77, 78; 77, 79; 77, 82; 78, identifier:scheduler_link_uuid; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:schedulers; 82, block; 82, 83; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 94; 85, attribute; 85, 86; 85, 93; 86, attribute; 86, 87; 86, 92; 87, subscript; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:schedulers; 91, identifier:scheduler_link_uuid; 92, identifier:pushed_commands; 93, identifier:append; 94, argument_list; 94, 95; 95, identifier:ext_cmd; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:count_pushed_commands; 99, integer:0; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:count_failed_commands; 103, integer:0; 104, for_statement; 104, 105; 104, 106; 104, 109; 105, identifier:scheduler_link_uuid; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:schedulers; 109, block; 109, 110; 109, 118; 109, 137; 109, 149; 109, 164; 109, 178; 109, 182; 109, 203; 109, 209; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:link; 113, subscript; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:schedulers; 117, identifier:scheduler_link_uuid; 118, if_statement; 118, 119; 118, 123; 119, not_operator; 119, 120; 120, attribute; 120, 121; 120, 122; 121, identifier:link; 122, identifier:active; 123, block; 123, 124; 123, 136; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:logger; 128, identifier:debug; 129, argument_list; 129, 130; 129, 133; 130, concatenated_string; 130, 131; 130, 132; 131, string:"The scheduler '%s' is not active, it is not possible to push "; 132, string:"external commands to its connection!"; 133, attribute; 133, 134; 133, 135; 134, identifier:link; 135, identifier:name; 136, continue_statement; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:commands; 140, list_comprehension; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:ext_cmd; 143, identifier:cmd_line; 144, for_in_clause; 144, 145; 144, 146; 145, identifier:ext_cmd; 146, attribute; 146, 147; 146, 148; 147, identifier:link; 148, identifier:pushed_commands; 149, if_statement; 149, 150; 149, 152; 150, not_operator; 150, 151; 151, identifier:commands; 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:debug; 158, argument_list; 158, 159; 158, 160; 159, string:"The scheduler '%s' has no commands."; 160, attribute; 160, 161; 160, 162; 161, identifier:link; 162, identifier:name; 163, continue_statement; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:logger; 168, identifier:debug; 169, argument_list; 169, 170; 169, 171; 169, 175; 170, string:"Sending %d commands to scheduler %s"; 171, call; 171, 172; 171, 173; 172, identifier:len; 173, argument_list; 173, 174; 174, identifier:commands; 175, attribute; 175, 176; 175, 177; 176, identifier:link; 177, identifier:name; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:sent; 181, list:[]; 182, try_statement; 182, 183; 182, 193; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:sent; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:link; 190, identifier:push_external_commands; 191, argument_list; 191, 192; 192, identifier:commands; 193, except_clause; 193, 194; 193, 195; 194, identifier:LinkError; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:logger; 200, identifier:warning; 201, argument_list; 201, 202; 202, string:"Scheduler connection failed, I could not push external commands!"; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:link; 207, identifier:pushed_commands; 208, list:[]; 209, if_statement; 209, 210; 209, 211; 209, 236; 210, identifier:sent; 211, block; 211, 212; 211, 227; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:statsmgr; 216, identifier:gauge; 217, argument_list; 217, 218; 217, 223; 218, binary_operator:%; 218, 219; 218, 220; 219, string:'external-commands.pushed.%s'; 220, attribute; 220, 221; 220, 222; 221, identifier:link; 222, identifier:name; 223, call; 223, 224; 223, 225; 224, identifier:len; 225, argument_list; 225, 226; 226, identifier:commands; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:count_pushed_commands; 230, binary_operator:+; 230, 231; 230, 232; 231, identifier:count_pushed_commands; 232, call; 232, 233; 232, 234; 233, identifier:len; 234, argument_list; 234, 235; 235, identifier:commands; 236, else_clause; 236, 237; 237, block; 237, 238; 237, 247; 237, 262; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:count_failed_commands; 241, binary_operator:+; 241, 242; 241, 243; 242, identifier:count_failed_commands; 243, call; 243, 244; 243, 245; 244, identifier:len; 245, argument_list; 245, 246; 246, identifier:commands; 247, expression_statement; 247, 248; 248, call; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:statsmgr; 251, identifier:gauge; 252, argument_list; 252, 253; 252, 258; 253, binary_operator:%; 253, 254; 253, 255; 254, string:'external-commands.failed.%s'; 255, attribute; 255, 256; 255, 257; 256, identifier:link; 257, identifier:name; 258, call; 258, 259; 258, 260; 259, identifier:len; 260, argument_list; 260, 261; 261, identifier:commands; 262, expression_statement; 262, 263; 263, call; 263, 264; 263, 269; 264, attribute; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:external_commands; 268, identifier:extend; 269, argument_list; 269, 270; 270, identifier:commands; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:statsmgr; 275, identifier:gauge; 276, argument_list; 276, 277; 276, 278; 277, string:'external-commands.pushed.all'; 278, identifier:count_pushed_commands; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:statsmgr; 283, identifier:gauge; 284, argument_list; 284, 285; 284, 286; 285, string:'external-commands.failed.all'; 286, identifier:count_failed_commands | def push_external_commands_to_schedulers(self):
if not self.unprocessed_external_commands:
return
commands_to_process = self.unprocessed_external_commands
self.unprocessed_external_commands = []
logger.debug("Commands: %s", commands_to_process)
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']:
for scheduler_link_uuid in self.schedulers:
self.schedulers[scheduler_link_uuid].pushed_commands.append(ext_cmd)
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
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!")
link.pushed_commands = []
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))
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, 11; 6, 34; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:group_names; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:hostgroup_id; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:hostgroups; 16, block; 16, 17; 16, 23; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:hostgroup; 20, subscript; 20, 21; 20, 22; 21, identifier:hostgroups; 22, identifier:hostgroup_id; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:group_names; 27, identifier:append; 28, argument_list; 28, 29; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:hostgroup; 32, identifier:get_name; 33, argument_list; 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_names | def get_groupnames(self, hostgroups):
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, 11; 6, 32; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:group_aliases; 10, list:[]; 11, for_statement; 11, 12; 11, 13; 11, 16; 12, identifier:hostgroup_id; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:hostgroups; 16, block; 16, 17; 16, 23; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:hostgroup; 20, subscript; 20, 21; 20, 22; 21, identifier:hostgroups; 22, identifier:hostgroup_id; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:group_aliases; 27, identifier:append; 28, argument_list; 28, 29; 29, attribute; 29, 30; 29, 31; 30, identifier:hostgroup; 31, identifier:alias; 32, return_statement; 32, 33; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, string:','; 36, identifier:join; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:sorted; 40, argument_list; 40, 41; 41, identifier:group_aliases | def get_groupaliases(self, hostgroups):
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, 11; 6, 68; 6, 107; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:overall_state; 10, integer:0; 11, if_statement; 11, 12; 11, 16; 11, 21; 11, 30; 11, 39; 12, not_operator; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:monitored; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:overall_state; 20, integer:5; 21, elif_clause; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:acknowledged; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:overall_state; 29, integer:1; 30, elif_clause; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:downtimed; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:overall_state; 38, integer:2; 39, elif_clause; 39, 40; 39, 45; 40, comparison_operator:==; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:state_type; 44, string:'HARD'; 45, block; 45, 46; 46, if_statement; 46, 47; 46, 52; 46, 57; 47, comparison_operator:==; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:state; 51, string:'UNREACHABLE'; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:overall_state; 56, integer:3; 57, elif_clause; 57, 58; 57, 63; 58, comparison_operator:==; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:state; 62, string:'DOWN'; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:overall_state; 67, integer:4; 68, if_statement; 68, 69; 68, 72; 69, comparison_operator:<=; 69, 70; 69, 71; 70, identifier:overall_state; 71, integer:2; 72, block; 72, 73; 73, for_statement; 73, 74; 73, 75; 73, 78; 74, identifier:service; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:services; 78, block; 78, 79; 79, if_statement; 79, 80; 79, 83; 80, comparison_operator:in; 80, 81; 80, 82; 81, identifier:service; 82, identifier:services; 83, block; 83, 84; 83, 90; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:service; 87, subscript; 87, 88; 87, 89; 88, identifier:services; 89, identifier:service; 90, if_statement; 90, 91; 90, 96; 91, comparison_operator:<; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:service; 94, identifier:overall_state_id; 95, integer:5; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:overall_state; 100, call; 100, 101; 100, 102; 101, identifier:max; 102, argument_list; 102, 103; 102, 104; 103, identifier:overall_state; 104, attribute; 104, 105; 104, 106; 105, identifier:service; 106, identifier:overall_state_id; 107, return_statement; 107, 108; 108, identifier:overall_state | def get_overall_state(self, services):
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
if overall_state <= 2:
for service in self.services:
if service in services:
service = services[service]
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, 154; 6, if_statement; 6, 7; 6, 11; 7, not_operator; 7, 8; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:first_scheduling; 11, block; 11, 12; 11, 19; 11, 27; 11, 35; 11, 43; 11, 57; 11, 64; 11, 102; 11, 140; 11, 148; 12, expression_statement; 12, 13; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:logger; 16, identifier:info; 17, argument_list; 17, 18; 18, string:"First scheduling launched"; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:_t0; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:time; 25, identifier:time; 26, argument_list; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:sched; 33, identifier:initial_program_status; 34, argument_list; 35, expression_statement; 35, 36; 36, call; 36, 37; 36, 42; 37, attribute; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:sched; 41, identifier:schedule; 42, argument_list; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:statsmgr; 47, identifier:timer; 48, argument_list; 48, 49; 48, 50; 49, string:'first_scheduling'; 50, binary_operator:-; 50, 51; 50, 56; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:time; 54, identifier:time; 55, argument_list; 56, identifier:_t0; 57, expression_statement; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:logger; 61, identifier:info; 62, argument_list; 62, 63; 63, string:"First scheduling done"; 64, for_statement; 64, 65; 64, 66; 64, 84; 65, identifier:satellite; 66, list_comprehension; 66, 67; 66, 68; 66, 80; 67, identifier:s; 68, for_in_clause; 68, 69; 68, 70; 69, identifier:s; 70, call; 70, 71; 70, 72; 71, identifier:list; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:pollers; 78, identifier:values; 79, argument_list; 80, if_clause; 80, 81; 81, attribute; 81, 82; 81, 83; 82, identifier:s; 83, identifier:passive; 84, block; 84, 85; 85, if_statement; 85, 86; 85, 93; 86, not_operator; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:daemon_connection_init; 91, argument_list; 91, 92; 92, identifier:satellite; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:logger; 98, identifier:error; 99, argument_list; 99, 100; 99, 101; 100, string:"Passive satellite connection failed: %s"; 101, identifier:satellite; 102, for_statement; 102, 103; 102, 104; 102, 122; 103, identifier:satellite; 104, list_comprehension; 104, 105; 104, 106; 104, 118; 105, identifier:s; 106, for_in_clause; 106, 107; 106, 108; 107, identifier:s; 108, call; 108, 109; 108, 110; 109, identifier:list; 110, argument_list; 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:reactionners; 116, identifier:values; 117, argument_list; 118, if_clause; 118, 119; 119, attribute; 119, 120; 119, 121; 120, identifier:s; 121, identifier:passive; 122, block; 122, 123; 123, if_statement; 123, 124; 123, 131; 124, not_operator; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:daemon_connection_init; 129, argument_list; 129, 130; 130, identifier:satellite; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:logger; 136, identifier:error; 137, argument_list; 137, 138; 137, 139; 138, string:"Passive satellite connection failed: %s"; 139, identifier:satellite; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:sched; 146, identifier:ticks; 147, integer:0; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:first_scheduling; 153, True; 154, if_statement; 154, 155; 154, 160; 154, 193; 155, attribute; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:sched; 159, identifier:pushed_conf; 160, block; 160, 161; 160, 185; 161, if_statement; 161, 162; 161, 168; 162, not_operator; 162, 163; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:sched; 167, identifier:must_schedule; 168, block; 168, 169; 168, 177; 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:self; 174, identifier:sched; 175, identifier:start_scheduling; 176, argument_list; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 184; 179, attribute; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:sched; 183, identifier:before_run; 184, argument_list; 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:self; 190, identifier:sched; 191, identifier:run; 192, argument_list; 193, else_clause; 193, 194; 193, 201; 194, ERROR; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:logger; 197, identifier:warning; 198, attribute; 198, 199; 198, 200; 199, identifier:self; 200, identifier:loop_count; 201, block: | def do_loop_turn(self):
if not self.first_scheduling:
logger.info("First scheduling launched")
_t0 = time.time()
self.sched.initial_program_status()
self.sched.schedule()
statsmgr.timer('first_scheduling', time.time() - _t0)
logger.info("First scheduling done")
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)
self.sched.ticks = 0
self.first_scheduling = True
if self.sched.pushed_conf:
if not self.sched.must_schedule:
self.sched.start_scheduling()
self.sched.before_run()
self.sched.run()
else:
logger.warning("
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, 15; 8, 25; 8, 42; 8, 88; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:reachable; 14, False; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:attempt; 20, binary_operator:+; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:attempt; 24, integer:1; 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, 35; 30, 38; 30, 41; 31, string:"Failed attempt for %s (%d/%d), reason: %s"; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:name; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:attempt; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:max_check_attempts; 41, identifier:reason; 42, if_statement; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:alive; 46, block; 46, 47; 47, if_statement; 47, 48; 47, 52; 47, 70; 48, not_operator; 48, 49; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:stopping; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:logger; 57, identifier:warning; 58, argument_list; 58, 59; 58, 60; 58, 63; 58, 66; 58, 69; 59, string:"Add failed attempt for %s (%d/%d) - %s"; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:name; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:attempt; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:max_check_attempts; 69, identifier:reason; 70, else_clause; 70, 71; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:logger; 76, identifier:info; 77, argument_list; 77, 78; 77, 79; 77, 82; 77, 85; 78, string:"Stopping... failed attempt for %s (%d/%d) - also probably stopping"; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:name; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:attempt; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:max_check_attempts; 88, if_statement; 88, 89; 88, 96; 89, comparison_operator:>=; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:attempt; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:max_check_attempts; 96, block; 96, 97; 96, 132; 97, if_statement; 97, 98; 97, 102; 97, 117; 98, not_operator; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:stopping; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:logger; 107, identifier:warning; 108, argument_list; 108, 109; 108, 110; 108, 113; 108, 116; 109, string:"Set %s as dead, too much failed attempts (%d), last problem is: %s"; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:name; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:max_check_attempts; 116, identifier:reason; 117, else_clause; 117, 118; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:logger; 123, identifier:info; 124, argument_list; 124, 125; 124, 126; 124, 129; 125, string:"Stopping... set %s as dead, too much failed attempts (%d)"; 126, attribute; 126, 127; 126, 128; 127, identifier:self; 128, identifier:name; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:max_check_attempts; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:set_dead; 137, argument_list | def add_failed_check_attempt(self, reason=''):
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)
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 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, 26; 12, 52; 12, 78; 12, 104; 12, 197; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:cfg; 16, dictionary; 16, 17; 16, 20; 16, 23; 17, pair; 17, 18; 17, 19; 18, string:'pollers'; 19, dictionary; 20, pair; 20, 21; 20, 22; 21, string:'reactionners'; 22, dictionary; 23, pair; 23, 24; 23, 25; 24, string:'receivers'; 25, dictionary; 26, for_statement; 26, 27; 26, 28; 26, 31; 27, identifier:poller_id; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:pollers; 31, block; 31, 32; 31, 38; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:poller; 35, subscript; 35, 36; 35, 37; 36, identifier:pollers; 37, identifier:poller_id; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 47; 40, subscript; 40, 41; 40, 44; 41, subscript; 41, 42; 41, 43; 42, identifier:cfg; 43, string:'pollers'; 44, attribute; 44, 45; 44, 46; 45, identifier:poller; 46, identifier:uuid; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:poller; 50, identifier:give_satellite_cfg; 51, argument_list; 52, for_statement; 52, 53; 52, 54; 52, 57; 53, identifier:reactionner_id; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:reactionners; 57, block; 57, 58; 57, 64; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:reactionner; 61, subscript; 61, 62; 61, 63; 62, identifier:reactionners; 63, identifier:reactionner_id; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 73; 66, subscript; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:cfg; 69, string:'reactionners'; 70, attribute; 70, 71; 70, 72; 71, identifier:reactionner; 72, identifier:uuid; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:reactionner; 76, identifier:give_satellite_cfg; 77, argument_list; 78, for_statement; 78, 79; 78, 80; 78, 83; 79, identifier:receiver_id; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:receivers; 83, block; 83, 84; 83, 90; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:receiver; 87, subscript; 87, 88; 87, 89; 88, identifier:receivers; 89, identifier:receiver_id; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 99; 92, subscript; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:cfg; 95, string:'receivers'; 96, attribute; 96, 97; 96, 98; 97, identifier:receiver; 98, identifier:uuid; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:receiver; 102, identifier:give_satellite_cfg; 103, argument_list; 104, if_statement; 104, 105; 104, 106; 105, identifier:manage_sub_realms; 106, block; 106, 107; 106, 137; 106, 167; 107, for_statement; 107, 108; 107, 109; 107, 116; 108, identifier:poller_id; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:get_all_subs_satellites_by_type; 113, argument_list; 113, 114; 113, 115; 114, string:'pollers'; 115, identifier:realms; 116, block; 116, 117; 116, 123; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:poller; 120, subscript; 120, 121; 120, 122; 121, identifier:pollers; 122, identifier:poller_id; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 132; 125, subscript; 125, 126; 125, 129; 126, subscript; 126, 127; 126, 128; 127, identifier:cfg; 128, string:'pollers'; 129, attribute; 129, 130; 129, 131; 130, identifier:poller; 131, identifier:uuid; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:poller; 135, identifier:give_satellite_cfg; 136, argument_list; 137, for_statement; 137, 138; 137, 139; 137, 146; 138, identifier:reactionner_id; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:get_all_subs_satellites_by_type; 143, argument_list; 143, 144; 143, 145; 144, string:'reactionners'; 145, identifier:realms; 146, block; 146, 147; 146, 153; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:reactionner; 150, subscript; 150, 151; 150, 152; 151, identifier:reactionners; 152, identifier:reactionner_id; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 162; 155, subscript; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:cfg; 158, string:'reactionners'; 159, attribute; 159, 160; 159, 161; 160, identifier:reactionner; 161, identifier:uuid; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:reactionner; 165, identifier:give_satellite_cfg; 166, argument_list; 167, for_statement; 167, 168; 167, 169; 167, 176; 168, identifier:receiver_id; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:get_all_subs_satellites_by_type; 173, argument_list; 173, 174; 173, 175; 174, string:'receivers'; 175, identifier:realms; 176, block; 176, 177; 176, 183; 177, expression_statement; 177, 178; 178, assignment; 178, 179; 178, 180; 179, identifier:receiver; 180, subscript; 180, 181; 180, 182; 181, identifier:receivers; 182, identifier:receiver_id; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 192; 185, subscript; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:cfg; 188, string:'receivers'; 189, attribute; 189, 190; 189, 191; 190, identifier:receiver; 191, identifier:uuid; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:receiver; 195, identifier:give_satellite_cfg; 196, argument_list; 197, return_statement; 197, 198; 198, identifier:cfg | def get_links_for_a_broker(self, pollers, reactionners, receivers, realms,
manage_sub_realms=False):
cfg = {
'pollers': {},
'reactionners': {},
'receivers': {},
}
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 manage_sub_realms:
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()
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()
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, 22; 8, 155; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:cfg; 12, dictionary; 12, 13; 12, 16; 12, 19; 13, pair; 13, 14; 13, 15; 14, string:'pollers'; 15, dictionary; 16, pair; 16, 17; 16, 18; 17, string:'reactionners'; 18, dictionary; 19, pair; 19, 20; 19, 21; 20, string:'brokers'; 21, dictionary; 22, try_statement; 22, 23; 22, 141; 23, block; 23, 24; 23, 63; 23, 102; 24, for_statement; 24, 25; 24, 26; 24, 37; 25, identifier:poller; 26, binary_operator:+; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:pollers; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:get_potential_satellites_by_type; 34, argument_list; 34, 35; 34, 36; 35, identifier:pollers; 36, string:"poller"; 37, block; 37, 38; 37, 49; 38, if_statement; 38, 39; 38, 42; 39, comparison_operator:in; 39, 40; 39, 41; 40, identifier:poller; 41, identifier:pollers; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:poller; 46, subscript; 46, 47; 46, 48; 47, identifier:pollers; 48, identifier:poller; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 58; 51, subscript; 51, 52; 51, 55; 52, subscript; 52, 53; 52, 54; 53, identifier:cfg; 54, string:'pollers'; 55, attribute; 55, 56; 55, 57; 56, identifier:poller; 57, identifier:uuid; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:poller; 61, identifier:give_satellite_cfg; 62, argument_list; 63, for_statement; 63, 64; 63, 65; 63, 76; 64, identifier:reactionner; 65, binary_operator:+; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:reactionners; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:self; 72, identifier:get_potential_satellites_by_type; 73, argument_list; 73, 74; 73, 75; 74, identifier:reactionners; 75, string:"reactionner"; 76, block; 76, 77; 76, 88; 77, if_statement; 77, 78; 77, 81; 78, comparison_operator:in; 78, 79; 78, 80; 79, identifier:reactionner; 80, identifier:reactionners; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:reactionner; 85, subscript; 85, 86; 85, 87; 86, identifier:reactionners; 87, identifier:reactionner; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 97; 90, subscript; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:cfg; 93, string:'reactionners'; 94, attribute; 94, 95; 94, 96; 95, identifier:reactionner; 96, identifier:uuid; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:reactionner; 100, identifier:give_satellite_cfg; 101, argument_list; 102, for_statement; 102, 103; 102, 104; 102, 115; 103, identifier:broker; 104, binary_operator:+; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:brokers; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:self; 111, identifier:get_potential_satellites_by_type; 112, argument_list; 112, 113; 112, 114; 113, identifier:brokers; 114, string:"broker"; 115, block; 115, 116; 115, 127; 116, if_statement; 116, 117; 116, 120; 117, comparison_operator:in; 117, 118; 117, 119; 118, identifier:broker; 119, identifier:brokers; 120, block; 120, 121; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:broker; 124, subscript; 124, 125; 124, 126; 125, identifier:brokers; 126, identifier:broker; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 136; 129, subscript; 129, 130; 129, 133; 130, subscript; 130, 131; 130, 132; 131, identifier:cfg; 132, string:'brokers'; 133, attribute; 133, 134; 133, 135; 134, identifier:broker; 135, identifier:uuid; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:broker; 139, identifier:give_satellite_cfg; 140, argument_list; 141, except_clause; 141, 142; 141, 146; 142, as_pattern; 142, 143; 142, 144; 143, identifier:Exception; 144, as_pattern_target; 144, 145; 145, identifier:exp; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:logger; 151, identifier:exception; 152, argument_list; 152, 153; 152, 154; 153, string:"realm.get_links_for_a_scheduler: %s"; 154, identifier:exp; 155, return_statement; 155, 156; 156, identifier:cfg | def get_links_for_a_scheduler(self, pollers, reactionners, brokers):
cfg = {
'pollers': {},
'reactionners': {},
'brokers': {},
}
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:
logger.exception("realm.get_links_for_a_scheduler: %s", exp)
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, 13; 8, 43; 8, 119; 8, 125; 8, 203; 8, 209; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:found; 12, list:[]; 13, for_statement; 13, 14; 13, 15; 13, 27; 14, identifier:realm; 15, call; 15, 16; 15, 17; 16, identifier:sorted; 17, argument_list; 17, 18; 17, 19; 18, identifier:self; 19, keyword_argument; 19, 20; 19, 21; 20, identifier:key; 21, lambda; 21, 22; 21, 24; 22, lambda_parameters; 22, 23; 23, identifier:r; 24, attribute; 24, 25; 24, 26; 25, identifier:r; 26, identifier:level; 27, block; 27, 28; 28, if_statement; 28, 29; 28, 35; 29, call; 29, 30; 29, 31; 30, identifier:getattr; 31, argument_list; 31, 32; 31, 33; 31, 34; 32, identifier:realm; 33, string:'default'; 34, False; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:found; 40, identifier:append; 41, argument_list; 41, 42; 42, identifier:realm; 43, if_statement; 43, 44; 43, 46; 44, not_operator; 44, 45; 45, identifier:found; 46, block; 46, 47; 46, 62; 46, 77; 46, 83; 46, 92; 46, 98; 46, 105; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:found_names; 50, call; 50, 51; 50, 52; 51, identifier:sorted; 52, argument_list; 52, 53; 53, list_comprehension; 53, 54; 53, 59; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:r; 57, identifier:get_name; 58, argument_list; 59, for_in_clause; 59, 60; 59, 61; 60, identifier:r; 61, identifier:self; 62, if_statement; 62, 63; 62, 65; 63, not_operator; 63, 64; 64, identifier:found_names; 65, block; 65, 66; 65, 75; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:add_error; 71, argument_list; 71, 72; 72, concatenated_string; 72, 73; 72, 74; 73, string:"No realm is defined in this configuration! "; 74, string:"This should not be possible!"; 75, return_statement; 75, 76; 76, None; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:default_realm_name; 80, subscript; 80, 81; 80, 82; 81, identifier:found_names; 82, integer:0; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:default_realm; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:find_by_name; 90, argument_list; 90, 91; 91, identifier:default_realm_name; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:default_realm; 96, identifier:default; 97, True; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:found; 102, identifier:append; 103, argument_list; 103, 104; 104, identifier:default_realm; 105, if_statement; 105, 106; 105, 107; 106, identifier:check; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:add_error; 113, argument_list; 113, 114; 114, binary_operator:%; 114, 115; 114, 118; 115, concatenated_string; 115, 116; 115, 117; 116, string:"No realm is defined as the default one! "; 117, string:"I set %s as the default realm"; 118, identifier:default_realm_name; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:default_realm; 122, subscript; 122, 123; 122, 124; 123, identifier:found; 124, integer:0; 125, if_statement; 125, 126; 125, 132; 126, comparison_operator:>; 126, 127; 126, 131; 127, call; 127, 128; 127, 129; 128, identifier:len; 129, argument_list; 129, 130; 130, identifier:found; 131, integer:1; 132, block; 132, 133; 132, 148; 132, 154; 132, 163; 132, 182; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:found_names; 136, call; 136, 137; 136, 138; 137, identifier:sorted; 138, argument_list; 138, 139; 139, list_comprehension; 139, 140; 139, 145; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:r; 143, identifier:get_name; 144, argument_list; 145, for_in_clause; 145, 146; 145, 147; 146, identifier:r; 147, identifier:found; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:default_realm_name; 151, subscript; 151, 152; 151, 153; 152, identifier:found_names; 153, integer:0; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:default_realm; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:find_by_name; 161, argument_list; 161, 162; 162, identifier:default_realm_name; 163, for_statement; 163, 164; 163, 165; 163, 166; 164, identifier:realm; 165, identifier:found; 166, block; 166, 167; 167, if_statement; 167, 168; 167, 175; 168, comparison_operator:!=; 168, 169; 168, 174; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:realm; 172, identifier:get_name; 173, argument_list; 174, identifier:default_realm_name; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:realm; 180, identifier:default; 181, False; 182, if_statement; 182, 183; 182, 184; 183, identifier:check; 184, block; 184, 185; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:add_warning; 190, argument_list; 190, 191; 191, binary_operator:%; 191, 192; 191, 195; 192, concatenated_string; 192, 193; 192, 194; 193, string:"More than one realm is defined as the default one: %s. "; 194, string:"I set %s as the default realm."; 195, tuple; 195, 196; 195, 202; 196, call; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, string:','; 199, identifier:join; 200, argument_list; 200, 201; 201, identifier:found_names; 202, identifier:default_realm_name; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:self; 207, identifier:default; 208, identifier:default_realm; 209, return_statement; 209, 210; 210, identifier:default_realm | def get_default(self, check=False):
found = []
for realm in sorted(self, key=lambda r: r.level):
if getattr(realm, 'default', False):
found.append(realm)
if not found:
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:
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)
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; 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, block; 26, 27; 26, 53; 26, 169; 26, 181; 26, 188; 26, 206; 26, 237; 26, 304; 26, 315; 26, 323; 26, 335; 27, if_statement; 27, 28; 27, 36; 28, comparison_operator:in; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:cherrypy; 32, identifier:request; 33, identifier:method; 34, list:["POST"]; 34, 35; 35, string:"POST"; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 44; 38, not_operator; 38, 39; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:cherrypy; 42, identifier:request; 43, identifier:json; 44, block; 44, 45; 45, return_statement; 45, 46; 46, dictionary; 46, 47; 46, 50; 47, pair; 47, 48; 47, 49; 48, string:'_status'; 49, string:u'ERR'; 50, pair; 50, 51; 50, 52; 51, string:'_message'; 52, string:u'You must POST parameters on this endpoint.'; 53, if_statement; 53, 54; 53, 57; 54, comparison_operator:is; 54, 55; 54, 56; 55, identifier:command; 56, None; 57, block; 57, 58; 58, try_statement; 58, 59; 58, 158; 59, block; 59, 60; 59, 74; 59, 88; 59, 102; 59, 116; 59, 130; 59, 144; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:command; 63, call; 63, 64; 63, 71; 64, attribute; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:cherrypy; 68, identifier:request; 69, identifier:json; 70, identifier:get; 71, argument_list; 71, 72; 71, 73; 72, string:'command'; 73, None; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:timestamp; 77, call; 77, 78; 77, 85; 78, attribute; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:cherrypy; 82, identifier:request; 83, identifier:json; 84, identifier:get; 85, argument_list; 85, 86; 85, 87; 86, string:'timestamp'; 87, None; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:element; 91, call; 91, 92; 91, 99; 92, attribute; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:cherrypy; 96, identifier:request; 97, identifier:json; 98, identifier:get; 99, argument_list; 99, 100; 99, 101; 100, string:'element'; 101, None; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:host; 105, call; 105, 106; 105, 113; 106, attribute; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:cherrypy; 110, identifier:request; 111, identifier:json; 112, identifier:get; 113, argument_list; 113, 114; 113, 115; 114, string:'host'; 115, None; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:service; 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:cherrypy; 124, identifier:request; 125, identifier:json; 126, identifier:get; 127, argument_list; 127, 128; 127, 129; 128, string:'service'; 129, None; 130, expression_statement; 130, 131; 131, assignment; 131, 132; 131, 133; 132, identifier:user; 133, call; 133, 134; 133, 141; 134, attribute; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:cherrypy; 138, identifier:request; 139, identifier:json; 140, identifier:get; 141, argument_list; 141, 142; 141, 143; 142, string:'user'; 143, None; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:parameters; 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:cherrypy; 152, identifier:request; 153, identifier:json; 154, identifier:get; 155, argument_list; 155, 156; 155, 157; 156, string:'parameters'; 157, None; 158, except_clause; 158, 159; 158, 160; 159, identifier:AttributeError; 160, block; 160, 161; 161, return_statement; 161, 162; 162, dictionary; 162, 163; 162, 166; 163, pair; 163, 164; 163, 165; 164, string:'_status'; 165, string:u'ERR'; 166, pair; 166, 167; 166, 168; 167, string:'_message'; 168, string:u'Missing command parameters'; 169, if_statement; 169, 170; 169, 172; 170, not_operator; 170, 171; 171, identifier:command; 172, block; 172, 173; 173, return_statement; 173, 174; 174, dictionary; 174, 175; 174, 178; 175, pair; 175, 176; 175, 177; 176, string:'_status'; 177, string:u'ERR'; 178, pair; 178, 179; 178, 180; 179, string:'_message'; 180, string:u'Missing command parameter'; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:fields; 184, call; 184, 185; 184, 186; 185, identifier:split_semicolon; 186, argument_list; 186, 187; 187, identifier:command; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:command_line; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:command; 194, identifier:replace; 195, argument_list; 195, 196; 195, 199; 196, subscript; 196, 197; 196, 198; 197, identifier:fields; 198, integer:0; 199, call; 199, 200; 199, 205; 200, attribute; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:fields; 203, integer:0; 204, identifier:upper; 205, argument_list; 206, if_statement; 206, 207; 206, 208; 207, identifier:timestamp; 208, block; 208, 209; 208, 229; 209, try_statement; 209, 210; 209, 218; 210, block; 210, 211; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:timestamp; 214, call; 214, 215; 214, 216; 215, identifier:int; 216, argument_list; 216, 217; 217, identifier:timestamp; 218, except_clause; 218, 219; 218, 220; 219, identifier:ValueError; 220, block; 220, 221; 221, return_statement; 221, 222; 222, dictionary; 222, 223; 222, 226; 223, pair; 223, 224; 223, 225; 224, string:'_status'; 225, string:u'ERR'; 226, pair; 226, 227; 226, 228; 227, string:'_message'; 228, string:u'Timestamp must be an integer value'; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:command_line; 232, binary_operator:%; 232, 233; 232, 234; 233, string:'[%d] %s'; 234, tuple; 234, 235; 234, 236; 235, identifier:timestamp; 236, identifier:command_line; 237, if_statement; 237, 238; 237, 243; 237, 277; 238, boolean_operator:or; 238, 239; 238, 242; 239, boolean_operator:or; 239, 240; 239, 241; 240, identifier:host; 241, identifier:service; 242, identifier:user; 243, block; 243, 244; 243, 255; 243, 266; 244, if_statement; 244, 245; 244, 246; 245, identifier:host; 246, block; 246, 247; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:command_line; 250, binary_operator:%; 250, 251; 250, 252; 251, string:'%s;%s'; 252, tuple; 252, 253; 252, 254; 253, identifier:command_line; 254, identifier:host; 255, if_statement; 255, 256; 255, 257; 256, identifier:service; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:command_line; 261, binary_operator:%; 261, 262; 261, 263; 262, string:'%s;%s'; 263, tuple; 263, 264; 263, 265; 264, identifier:command_line; 265, identifier:service; 266, if_statement; 266, 267; 266, 268; 267, identifier:user; 268, block; 268, 269; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 272; 271, identifier:command_line; 272, binary_operator:%; 272, 273; 272, 274; 273, string:'%s;%s'; 274, tuple; 274, 275; 274, 276; 275, identifier:command_line; 276, identifier:user; 277, elif_clause; 277, 278; 277, 279; 278, identifier:element; 279, block; 279, 280; 279, 296; 280, if_statement; 280, 281; 280, 284; 281, comparison_operator:in; 281, 282; 281, 283; 282, string:'/'; 283, identifier:element; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:element; 288, call; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:element; 291, identifier:replace; 292, argument_list; 292, 293; 292, 294; 292, 295; 293, string:'/'; 294, string:';'; 295, integer:1; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:command_line; 299, binary_operator:%; 299, 300; 299, 301; 300, string:'%s;%s'; 301, tuple; 301, 302; 301, 303; 302, identifier:command_line; 303, identifier:element; 304, if_statement; 304, 305; 304, 306; 305, identifier:parameters; 306, block; 306, 307; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:command_line; 310, binary_operator:%; 310, 311; 310, 312; 311, string:'%s;%s'; 312, tuple; 312, 313; 312, 314; 313, identifier:command_line; 314, identifier:parameters; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:logger; 319, identifier:warning; 320, argument_list; 320, 321; 320, 322; 321, string:"Got an external command: %s"; 322, identifier:command_line; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 330; 325, attribute; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:self; 328, identifier:app; 329, identifier:add; 330, argument_list; 330, 331; 331, call; 331, 332; 331, 333; 332, identifier:ExternalCommand; 333, argument_list; 333, 334; 334, identifier:command_line; 335, return_statement; 335, 336; 336, dictionary; 336, 337; 336, 340; 336, 345; 337, pair; 337, 338; 337, 339; 338, string:'_status'; 339, string:u'OK'; 340, pair; 340, 341; 340, 342; 341, string:'_message'; 342, binary_operator:%; 342, 343; 342, 344; 343, string:u"Got command: %s"; 344, identifier:command_line; 345, pair; 345, 346; 345, 347; 346, string:'command'; 347, identifier:command_line | def command(self, command=None,
timestamp=None, element=None, host=None, service=None, user=None, parameters=None):
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:
element = element.replace('/', ';', 1)
command_line = '%s;%s' % (command_line, element)
if parameters:
command_line = '%s;%s' % (command_line, parameters)
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; 9, with_statement; 9, 10; 9, 17; 10, with_clause; 10, 11; 11, with_item; 11, 12; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:app; 16, identifier:conf_lock; 17, block; 17, 18; 17, 22; 17, 74; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:res; 21, dictionary; 22, for_statement; 22, 23; 22, 24; 22, 31; 23, identifier:s_type; 24, list:['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']; 24, 25; 24, 26; 24, 27; 24, 28; 24, 29; 24, 30; 25, string:'arbiter'; 26, string:'scheduler'; 27, string:'poller'; 28, string:'reactionner'; 29, string:'receiver'; 30, string:'broker'; 31, block; 31, 32; 31, 40; 31, 44; 31, 50; 32, if_statement; 32, 33; 32, 38; 33, boolean_operator:and; 33, 34; 33, 35; 34, identifier:daemon_type; 35, comparison_operator:!=; 35, 36; 35, 37; 36, identifier:daemon_type; 37, identifier:s_type; 38, block; 38, 39; 39, continue_statement; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:satellite_list; 43, list:[]; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 49; 46, subscript; 46, 47; 46, 48; 47, identifier:res; 48, identifier:s_type; 49, identifier:satellite_list; 50, for_statement; 50, 51; 50, 52; 50, 64; 51, identifier:daemon_link; 52, call; 52, 53; 52, 54; 53, identifier:getattr; 54, argument_list; 54, 55; 54, 60; 54, 63; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:app; 59, identifier:conf; 60, binary_operator:+; 60, 61; 60, 62; 61, identifier:s_type; 62, string:'s'; 63, list:[]; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:satellite_list; 69, identifier:append; 70, argument_list; 70, 71; 71, attribute; 71, 72; 71, 73; 72, identifier:daemon_link; 73, identifier:name; 74, return_statement; 74, 75; 75, identifier:res | def satellites_list(self, daemon_type=''):
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, 13; 5, 21; 5, 86; 5, 119; 5, 127; 5, 193; 5, 201; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:logger; 10, identifier:debug; 11, argument_list; 11, 12; 12, string:"Filling the unset properties with their default value:"; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:types_creations; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:__class__; 20, identifier:types_creations; 21, for_statement; 21, 22; 21, 23; 21, 24; 22, identifier:o_type; 23, identifier:types_creations; 24, block; 24, 25; 24, 36; 24, 49; 24, 57; 24, 66; 24, 80; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 33; 27, tuple_pattern; 27, 28; 27, 29; 27, 30; 27, 31; 27, 32; 28, identifier:_; 29, identifier:_; 30, identifier:inner_property; 31, identifier:_; 32, identifier:_; 33, subscript; 33, 34; 33, 35; 34, identifier:types_creations; 35, identifier:o_type; 36, if_statement; 36, 37; 36, 47; 37, comparison_operator:in; 37, 38; 37, 39; 38, identifier:inner_property; 39, list:['realms', 'arbiters', 'schedulers', 'reactionners',
'pollers', 'brokers', 'receivers']; 39, 40; 39, 41; 39, 42; 39, 43; 39, 44; 39, 45; 39, 46; 40, string:'realms'; 41, string:'arbiters'; 42, string:'schedulers'; 43, string:'reactionners'; 44, string:'pollers'; 45, string:'brokers'; 46, string:'receivers'; 47, block; 47, 48; 48, continue_statement; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:logger; 53, identifier:debug; 54, argument_list; 54, 55; 54, 56; 55, string:" . for %s"; 56, identifier:inner_property; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:inner_object; 60, call; 60, 61; 60, 62; 61, identifier:getattr; 62, argument_list; 62, 63; 62, 64; 62, 65; 63, identifier:self; 64, identifier:inner_property; 65, None; 66, if_statement; 66, 67; 66, 70; 67, comparison_operator:is; 67, 68; 67, 69; 68, identifier:inner_object; 69, None; 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:debug; 76, argument_list; 76, 77; 76, 78; 77, string:"No %s to fill with default values"; 78, identifier:inner_property; 79, continue_statement; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:inner_object; 84, identifier:fill_default; 85, argument_list; 86, if_statement; 86, 87; 86, 95; 87, comparison_operator:is; 87, 88; 87, 94; 88, call; 88, 89; 88, 90; 89, identifier:getattr; 90, argument_list; 90, 91; 90, 92; 90, 93; 91, identifier:self; 92, string:'realms'; 93, None; 94, None; 95, block; 95, 96; 95, 102; 95, 110; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:fill_default_realm; 101, argument_list; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:realms; 108, identifier:fill_default; 109, argument_list; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:fill_default_satellites; 115, argument_list; 115, 116; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:launch_missing_daemons; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:types_creations; 122, attribute; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:__class__; 126, identifier:types_creations; 127, for_statement; 127, 128; 127, 129; 127, 130; 128, identifier:o_type; 129, identifier:types_creations; 130, block; 130, 131; 130, 142; 130, 161; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 139; 133, tuple_pattern; 133, 134; 133, 135; 133, 136; 133, 137; 133, 138; 134, identifier:_; 135, identifier:_; 136, identifier:inner_property; 137, identifier:_; 138, identifier:_; 139, subscript; 139, 140; 139, 141; 140, identifier:types_creations; 141, identifier:o_type; 142, if_statement; 142, 143; 142, 151; 143, comparison_operator:is; 143, 144; 143, 150; 144, call; 144, 145; 144, 146; 145, identifier:getattr; 146, argument_list; 146, 147; 146, 148; 146, 149; 147, identifier:self; 148, identifier:inner_property; 149, None; 150, None; 151, block; 151, 152; 151, 160; 152, expression_statement; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:logger; 156, identifier:debug; 157, argument_list; 157, 158; 157, 159; 158, string:"No %s to fill with default values"; 159, identifier:inner_property; 160, continue_statement; 161, if_statement; 161, 162; 161, 170; 162, comparison_operator:in; 162, 163; 162, 164; 163, identifier:inner_property; 164, list:['schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']; 164, 165; 164, 166; 164, 167; 164, 168; 164, 169; 165, string:'schedulers'; 166, string:'reactionners'; 167, string:'pollers'; 168, string:'brokers'; 169, string:'receivers'; 170, block; 170, 171; 170, 179; 170, 187; 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; 177, string:" . for %s"; 178, identifier:inner_property; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:inner_object; 182, call; 182, 183; 182, 184; 183, identifier:getattr; 184, argument_list; 184, 185; 184, 186; 185, identifier:self; 186, identifier:inner_property; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:inner_object; 191, identifier:fill_default; 192, argument_list; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:hosts; 199, identifier:fill_predictive_missing_parameters; 200, argument_list; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:services; 207, identifier:fill_predictive_missing_parameters; 208, argument_list | def fill_default_configuration(self):
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]
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()
if getattr(self, 'realms', None) is not None:
self.fill_default_realm()
self.realms.fill_default()
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
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()
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, 70; 7, for_statement; 7, 8; 7, 9; 7, 12; 8, identifier:arbiter; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:arbiters; 12, block; 12, 13; 13, for_statement; 13, 14; 13, 15; 13, 21; 14, identifier:module; 15, call; 15, 16; 15, 17; 16, identifier:getattr; 17, argument_list; 17, 18; 17, 19; 17, 20; 18, identifier:arbiter; 19, string:'modules'; 20, list:[]; 21, block; 21, 22; 21, 30; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:module_name; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:module; 28, identifier:get_name; 29, argument_list; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:mod; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:modules; 35, block; 35, 36; 36, if_statement; 36, 37; 36, 53; 37, comparison_operator:==; 37, 38; 37, 48; 38, call; 38, 39; 38, 47; 39, attribute; 39, 40; 39, 46; 40, call; 40, 41; 40, 42; 41, identifier:getattr; 42, argument_list; 42, 43; 42, 44; 42, 45; 43, identifier:mod; 44, string:'python_name'; 45, string:''; 46, identifier:strip; 47, argument_list; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:module_type; 51, identifier:strip; 52, argument_list; 53, block; 53, 54; 54, if_statement; 54, 55; 54, 67; 55, comparison_operator:==; 55, 56; 55, 66; 56, call; 56, 57; 56, 65; 57, attribute; 57, 58; 57, 64; 58, call; 58, 59; 58, 60; 59, identifier:getattr; 60, argument_list; 60, 61; 60, 62; 60, 63; 61, identifier:mod; 62, string:'name'; 63, string:''; 64, identifier:strip; 65, argument_list; 66, identifier:module_name; 67, block; 67, 68; 68, return_statement; 68, 69; 69, True; 70, return_statement; 70, 71; 71, False | def got_arbiter_module_type_defined(self, module_type):
for arbiter in self.arbiters:
for module in getattr(arbiter, 'modules', []):
module_name = module.get_name()
for mod in self.modules:
if getattr(mod, 'python_name', '').strip() == module_type.strip():
if getattr(mod, 'name', '').strip() == module_name:
return True
return False |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:load_modules_configuration_objects; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:raw_objects; 6, block; 6, 7; 7, for_statement; 7, 8; 7, 9; 7, 14; 8, identifier:instance; 9, attribute; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:modules_manager; 13, identifier:instances; 14, block; 14, 15; 14, 25; 14, 44; 14, 84; 14, 99; 14, 107; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:logger; 19, identifier:debug; 20, argument_list; 20, 21; 20, 22; 21, string:"Getting objects from the module: %s"; 22, attribute; 22, 23; 22, 24; 23, identifier:instance; 24, identifier:name; 25, if_statement; 25, 26; 25, 32; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:hasattr; 29, argument_list; 29, 30; 29, 31; 30, identifier:instance; 31, string:'get_objects'; 32, block; 32, 33; 32, 43; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:logger; 37, identifier:debug; 38, argument_list; 38, 39; 38, 40; 39, string:"The module '%s' do not provide any objects."; 40, attribute; 40, 41; 40, 42; 41, identifier:instance; 42, identifier:name; 43, return_statement; 44, try_statement; 44, 45; 44, 64; 45, block; 45, 46; 45, 56; 46, expression_statement; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:logger; 50, identifier:info; 51, argument_list; 51, 52; 51, 53; 52, string:"Getting Alignak monitored configuration objects from module '%s'"; 53, attribute; 53, 54; 53, 55; 54, identifier:instance; 55, identifier:name; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:got_objects; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:instance; 62, identifier:get_objects; 63, argument_list; 64, except_clause; 64, 65; 64, 69; 65, as_pattern; 65, 66; 65, 67; 66, identifier:Exception; 67, as_pattern_target; 67, 68; 68, identifier:exp; 69, block; 69, 70; 69, 83; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:logger; 74, identifier:exception; 75, argument_list; 75, 76; 75, 79; 75, 82; 76, concatenated_string; 76, 77; 76, 78; 77, string:"Module %s get_objects raised an exception %s. "; 78, string:"Log and continue to run."; 79, attribute; 79, 80; 79, 81; 80, identifier:instance; 81, identifier:name; 82, identifier:exp; 83, continue_statement; 84, if_statement; 84, 85; 84, 87; 85, not_operator; 85, 86; 86, identifier:got_objects; 87, block; 87, 88; 87, 98; 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:"The module '%s' did not provided any objects."; 95, attribute; 95, 96; 95, 97; 96, identifier:instance; 97, identifier:name; 98, return_statement; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:types_creations; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:conf; 106, identifier:types_creations; 107, for_statement; 107, 108; 107, 109; 107, 110; 108, identifier:o_type; 109, identifier:types_creations; 110, block; 110, 111; 110, 122; 110, 135; 110, 152; 110, 193; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 119; 113, tuple_pattern; 113, 114; 113, 115; 113, 116; 113, 117; 113, 118; 114, identifier:_; 115, identifier:_; 116, identifier:prop; 117, identifier:_; 118, identifier:_; 119, subscript; 119, 120; 119, 121; 120, identifier:types_creations; 121, identifier:o_type; 122, if_statement; 122, 123; 122, 133; 123, comparison_operator:in; 123, 124; 123, 125; 124, identifier:prop; 125, list:['arbiters', 'brokers', 'schedulers',
'pollers', 'reactionners', 'receivers', 'modules']; 125, 126; 125, 127; 125, 128; 125, 129; 125, 130; 125, 131; 125, 132; 126, string:'arbiters'; 127, string:'brokers'; 128, string:'schedulers'; 129, string:'pollers'; 130, string:'reactionners'; 131, string:'receivers'; 132, string:'modules'; 133, block; 133, 134; 134, continue_statement; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:not; 136, 137; 136, 138; 137, identifier:prop; 138, identifier:got_objects; 139, block; 139, 140; 139, 151; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:logger; 144, identifier:warning; 145, argument_list; 145, 146; 145, 147; 145, 148; 146, string:"Did not get any '%s' objects from %s"; 147, identifier:prop; 148, attribute; 148, 149; 148, 150; 149, identifier:instance; 150, identifier:name; 151, continue_statement; 152, for_statement; 152, 153; 152, 154; 152, 157; 153, identifier:obj; 154, subscript; 154, 155; 154, 156; 155, identifier:got_objects; 156, identifier:prop; 157, block; 157, 158; 157, 169; 157, 184; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:not; 159, 160; 159, 161; 160, identifier:o_type; 161, identifier:raw_objects; 162, block; 162, 163; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 168; 165, subscript; 165, 166; 165, 167; 166, identifier:raw_objects; 167, identifier:o_type; 168, list:[]; 169, if_statement; 169, 170; 169, 173; 170, comparison_operator:not; 170, 171; 170, 172; 171, string:'imported_from'; 172, identifier:obj; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, subscript; 176, 177; 176, 178; 177, identifier:obj; 178, string:'imported_from'; 179, binary_operator:%; 179, 180; 179, 181; 180, string:'module:%s'; 181, attribute; 181, 182; 181, 183; 182, identifier:instance; 183, identifier:name; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, subscript; 187, 188; 187, 189; 188, identifier:raw_objects; 189, identifier:o_type; 190, identifier:append; 191, argument_list; 191, 192; 192, identifier:obj; 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, 206; 198, 207; 199, string:"Added %i %s objects from %s"; 200, call; 200, 201; 200, 202; 201, identifier:len; 202, argument_list; 202, 203; 203, subscript; 203, 204; 203, 205; 204, identifier:got_objects; 205, identifier:prop; 206, identifier:o_type; 207, attribute; 207, 208; 207, 209; 208, identifier:instance; 209, identifier:name | def load_modules_configuration_objects(self, raw_objects):
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:
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]:
if o_type not in raw_objects:
raw_objects[o_type] = []
if 'imported_from' not in obj:
obj['imported_from'] = 'module:%s' % instance.name
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; 2, function_name:load_modules_alignak_configuration; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 10; 5, 112; 5, 116; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:alignak_cfg; 9, dictionary; 10, for_statement; 10, 11; 10, 12; 10, 17; 11, identifier:instance; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:modules_manager; 16, identifier:instances; 17, block; 17, 18; 17, 27; 18, if_statement; 18, 19; 18, 25; 19, not_operator; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:hasattr; 22, argument_list; 22, 23; 22, 24; 23, identifier:instance; 24, string:'get_alignak_configuration'; 25, block; 25, 26; 26, return_statement; 27, try_statement; 27, 28; 27, 54; 28, block; 28, 29; 28, 39; 28, 47; 29, expression_statement; 29, 30; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:logger; 33, identifier:info; 34, argument_list; 34, 35; 34, 36; 35, string:"Getting Alignak global configuration from module '%s'"; 36, attribute; 36, 37; 36, 38; 37, identifier:instance; 38, identifier:name; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:cfg; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:instance; 45, identifier:get_alignak_configuration; 46, argument_list; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:alignak_cfg; 51, identifier:update; 52, argument_list; 52, 53; 53, identifier:cfg; 54, except_clause; 54, 55; 54, 59; 55, as_pattern; 55, 56; 55, 57; 56, identifier:Exception; 57, as_pattern_target; 57, 58; 58, identifier:exp; 59, block; 59, 60; 59, 76; 59, 84; 59, 93; 59, 105; 59, 111; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:logger; 64, identifier:error; 65, argument_list; 65, 66; 65, 69; 65, 72; 66, concatenated_string; 66, 67; 66, 68; 67, string:"Module %s get_alignak_configuration raised an exception %s. "; 68, string:"Log and continue to run"; 69, attribute; 69, 70; 69, 71; 70, identifier:instance; 71, identifier:name; 72, call; 72, 73; 72, 74; 73, identifier:str; 74, argument_list; 74, 75; 75, identifier:exp; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:output; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:io; 82, identifier:StringIO; 83, argument_list; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:traceback; 88, identifier:print_exc; 89, argument_list; 89, 90; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:file; 92, identifier:output; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:logger; 97, identifier:error; 98, argument_list; 98, 99; 98, 100; 99, string:"Back trace of this remove: %s"; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:output; 103, identifier:getvalue; 104, argument_list; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:output; 109, identifier:close; 110, argument_list; 111, continue_statement; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:params; 115, list:[]; 116, if_statement; 116, 117; 116, 118; 117, identifier:alignak_cfg; 118, block; 118, 119; 118, 126; 118, 201; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:logger; 123, identifier:info; 124, argument_list; 124, 125; 125, string:"Got Alignak global configuration:"; 126, for_statement; 126, 127; 126, 130; 126, 138; 127, pattern_list; 127, 128; 127, 129; 128, identifier:key; 129, identifier:value; 130, call; 130, 131; 130, 132; 131, identifier:sorted; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:alignak_cfg; 136, identifier:items; 137, argument_list; 138, block; 138, 139; 138, 148; 138, 172; 138, 178; 138, 184; 138, 190; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:logger; 143, identifier:info; 144, argument_list; 144, 145; 144, 146; 144, 147; 145, string:"- %s = %s"; 146, identifier:key; 147, identifier:value; 148, if_statement; 148, 149; 148, 155; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:key; 152, identifier:startswith; 153, argument_list; 153, 154; 154, string:'_'; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:key; 159, binary_operator:+; 159, 160; 159, 171; 160, binary_operator:+; 160, 161; 160, 162; 161, string:'$'; 162, call; 162, 163; 162, 170; 163, attribute; 163, 164; 163, 169; 164, subscript; 164, 165; 164, 166; 165, identifier:key; 166, slice; 166, 167; 166, 168; 167, integer:1; 168, colon; 169, identifier:upper; 170, argument_list; 171, string:'$'; 172, if_statement; 172, 173; 172, 176; 173, comparison_operator:is; 173, 174; 173, 175; 174, identifier:value; 175, None; 176, block; 176, 177; 177, continue_statement; 178, if_statement; 178, 179; 178, 182; 179, comparison_operator:==; 179, 180; 179, 181; 180, identifier:value; 181, string:'None'; 182, block; 182, 183; 183, continue_statement; 184, if_statement; 184, 185; 184, 188; 185, comparison_operator:==; 185, 186; 185, 187; 186, identifier:value; 187, string:''; 188, block; 188, 189; 189, continue_statement; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:params; 194, identifier:append; 195, argument_list; 195, 196; 196, binary_operator:%; 196, 197; 196, 198; 197, string:"%s=%s"; 198, tuple; 198, 199; 198, 200; 199, identifier:key; 200, identifier:value; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 208; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:conf; 207, identifier:load_params; 208, argument_list; 208, 209; 209, identifier:params | def load_modules_alignak_configuration(self):
alignak_cfg = {}
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:
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)
if key.startswith('_'):
key = '$' + key[1:].upper() + '$'
if value is None:
continue
if value == 'None':
continue
if value == '':
continue
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, 13; 8, 32; 8, 204; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:result; 12, True; 13, if_statement; 13, 14; 13, 15; 13, 23; 14, identifier:run_daemons; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:logger; 20, identifier:info; 21, argument_list; 21, 22; 22, string:"Alignak configured daemons start:"; 23, else_clause; 23, 24; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:logger; 29, identifier:info; 30, argument_list; 30, 31; 31, string:"Alignak configured daemons check:"; 32, for_statement; 32, 33; 32, 34; 32, 65; 33, identifier:satellites_list; 34, list:[self.conf.arbiters, self.conf.receivers, self.conf.reactionners,
self.conf.pollers, self.conf.brokers, self.conf.schedulers]; 34, 35; 34, 40; 34, 45; 34, 50; 34, 55; 34, 60; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:conf; 39, identifier:arbiters; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:conf; 44, identifier:receivers; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:conf; 49, identifier:reactionners; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:conf; 54, identifier:pollers; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:conf; 59, identifier:brokers; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:conf; 64, identifier:schedulers; 65, block; 65, 66; 66, for_statement; 66, 67; 66, 68; 66, 69; 67, identifier:satellite; 68, identifier:satellites_list; 69, block; 69, 70; 69, 86; 69, 94; 69, 131; 69, 136; 69, 150; 69, 169; 69, 189; 69, 198; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:logger; 74, identifier:info; 75, argument_list; 75, 76; 75, 77; 75, 80; 75, 83; 76, string:"- found %s, to be launched: %s, address: %s"; 77, attribute; 77, 78; 77, 79; 78, identifier:satellite; 79, identifier:name; 80, attribute; 80, 81; 80, 82; 81, identifier:satellite; 82, identifier:alignak_launched; 83, attribute; 83, 84; 83, 85; 84, identifier:satellite; 85, identifier:uri; 86, if_statement; 86, 87; 86, 92; 87, comparison_operator:==; 87, 88; 87, 89; 88, identifier:satellite; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:link_to_myself; 92, block; 92, 93; 93, continue_statement; 94, if_statement; 94, 95; 94, 107; 95, boolean_operator:and; 95, 96; 95, 99; 95, 100; 96, attribute; 96, 97; 96, 98; 97, identifier:satellite; 98, identifier:alignak_launched; 99, line_continuation:\; 100, comparison_operator:not; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:satellite; 103, identifier:address; 104, list:['127.0.0.1', 'localhost']; 104, 105; 104, 106; 105, string:'127.0.0.1'; 106, string:'localhost'; 107, block; 107, 108; 107, 126; 107, 130; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:logger; 112, identifier:error; 113, argument_list; 113, 114; 113, 117; 113, 120; 113, 123; 114, concatenated_string; 114, 115; 114, 116; 115, string:"Alignak is required to launch a daemon for %s %s "; 116, string:"but the satelitte is defined on an external address: %s"; 117, attribute; 117, 118; 117, 119; 118, identifier:satellite; 119, identifier:type; 120, attribute; 120, 121; 120, 122; 121, identifier:satellite; 122, identifier:name; 123, attribute; 123, 124; 123, 125; 124, identifier:satellite; 125, identifier:address; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:result; 129, False; 130, continue_statement; 131, if_statement; 131, 132; 131, 134; 132, not_operator; 132, 133; 133, identifier:run_daemons; 134, block; 134, 135; 135, continue_statement; 136, if_statement; 136, 137; 136, 141; 137, not_operator; 137, 138; 138, attribute; 138, 139; 138, 140; 139, identifier:satellite; 140, identifier:alignak_launched; 141, block; 141, 142; 141, 149; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:logger; 146, identifier:debug; 147, argument_list; 147, 148; 148, string:"Alignak will not launch '%s'"; 149, continue_statement; 150, if_statement; 150, 151; 150, 155; 151, not_operator; 151, 152; 152, attribute; 152, 153; 152, 154; 153, identifier:satellite; 154, identifier:active; 155, block; 155, 156; 155, 168; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:logger; 160, identifier:warning; 161, argument_list; 161, 162; 161, 165; 162, concatenated_string; 162, 163; 162, 164; 163, string:"- daemon '%s' is declared but not set as active, "; 164, string:"do not start..."; 165, attribute; 165, 166; 165, 167; 166, identifier:satellite; 167, identifier:name; 168, continue_statement; 169, if_statement; 169, 170; 169, 177; 170, comparison_operator:in; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:satellite; 173, identifier:name; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:my_daemons; 177, block; 177, 178; 177, 188; 178, expression_statement; 178, 179; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:logger; 182, identifier:warning; 183, argument_list; 183, 184; 183, 185; 184, string:"- daemon '%s' is already running"; 185, attribute; 185, 186; 185, 187; 186, identifier:satellite; 187, identifier:name; 188, continue_statement; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:started; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:start_daemon; 196, argument_list; 196, 197; 197, identifier:satellite; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:result; 201, boolean_operator:and; 201, 202; 201, 203; 202, identifier:result; 203, identifier:started; 204, return_statement; 204, 205; 205, identifier:result | def daemons_start(self, run_daemons=True):
result = True
if run_daemons:
logger.info("Alignak configured daemons start:")
else:
logger.info("Alignak configured daemons check:")
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:
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:
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, 30; 11, 34; 11, 274; 12, function_definition; 12, 13; 12, 14; 12, 16; 13, function_name:on_terminate; 14, parameters; 14, 15; 15, identifier:proc; 16, block; 16, 17; 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; 22, 24; 22, 27; 23, string:"process %s terminated with exit code %s"; 24, attribute; 24, 25; 24, 26; 25, identifier:proc; 26, identifier:pid; 27, attribute; 27, 28; 27, 29; 28, identifier:proc; 29, identifier:returncode; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:result; 33, True; 34, if_statement; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:my_daemons; 38, block; 38, 39; 38, 46; 38, 54; 38, 139; 38, 143; 38, 178; 38, 195; 38, 260; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:logger; 43, identifier:info; 44, argument_list; 44, 45; 45, string:"Alignak self-launched daemons stop:"; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:start; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:time; 52, identifier:time; 53, argument_list; 54, for_statement; 54, 55; 54, 56; 54, 66; 55, identifier:daemon; 56, call; 56, 57; 56, 58; 57, identifier:list; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:my_daemons; 64, identifier:values; 65, argument_list; 66, block; 66, 67; 66, 71; 66, 84; 66, 93; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:procs; 70, list:[]; 71, if_statement; 71, 72; 71, 73; 72, identifier:kill_children; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:procs; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:daemon; 81, string:'process'; 82, identifier:children; 83, argument_list; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:procs; 88, identifier:append; 89, argument_list; 89, 90; 90, subscript; 90, 91; 90, 92; 91, identifier:daemon; 92, string:'process'; 93, for_statement; 93, 94; 93, 95; 93, 96; 94, identifier:process; 95, identifier:procs; 96, block; 96, 97; 97, try_statement; 97, 98; 97, 117; 98, block; 98, 99; 98, 111; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:logger; 103, identifier:info; 104, argument_list; 104, 105; 104, 106; 105, string:"- terminating process %s"; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:process; 109, identifier:name; 110, argument_list; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:process; 115, identifier:terminate; 116, argument_list; 117, except_clause; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:psutil; 120, identifier:AccessDenied; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:logger; 126, identifier:warning; 127, argument_list; 127, 128; 127, 129; 127, 134; 128, string:"Process %s is %s"; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:process; 132, identifier:name; 133, argument_list; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:process; 137, identifier:status; 138, argument_list; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:procs; 142, list:[]; 143, for_statement; 143, 144; 143, 145; 143, 155; 144, identifier:daemon; 145, call; 145, 146; 145, 147; 146, identifier:list; 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:my_daemons; 153, identifier:values; 154, argument_list; 155, block; 155, 156; 155, 169; 156, if_statement; 156, 157; 156, 158; 157, identifier:kill_children; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:procs; 162, call; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, subscript; 164, 165; 164, 166; 165, identifier:daemon; 166, string:'process'; 167, identifier:children; 168, argument_list; 169, expression_statement; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, identifier:procs; 173, identifier:append; 174, argument_list; 174, 175; 175, subscript; 175, 176; 175, 177; 176, identifier:daemon; 177, string:'process'; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 183; 180, pattern_list; 180, 181; 180, 182; 181, identifier:_; 182, identifier:alive; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:psutil; 186, identifier:wait_procs; 187, argument_list; 187, 188; 187, 189; 187, 192; 188, identifier:procs; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:timeout; 191, identifier:timeout; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:callback; 194, identifier:on_terminate; 195, if_statement; 195, 196; 195, 197; 196, identifier:alive; 197, block; 197, 198; 197, 220; 197, 237; 198, for_statement; 198, 199; 198, 200; 198, 201; 199, identifier:process; 200, identifier:alive; 201, block; 201, 202; 201, 214; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:logger; 206, identifier:warning; 207, argument_list; 207, 208; 207, 209; 208, string:"Process %s did not stopped, trying to kill"; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:process; 212, identifier:name; 213, argument_list; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:process; 218, identifier:kill; 219, argument_list; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, pattern_list; 222, 223; 222, 224; 223, identifier:_; 224, identifier:alive; 225, call; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:psutil; 228, identifier:wait_procs; 229, argument_list; 229, 230; 229, 231; 229, 234; 230, identifier:alive; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:timeout; 233, identifier:timeout; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:callback; 236, identifier:on_terminate; 237, if_statement; 237, 238; 237, 239; 238, identifier:alive; 239, block; 239, 240; 240, for_statement; 240, 241; 240, 242; 240, 243; 241, identifier:process; 242, identifier:alive; 243, block; 243, 244; 243, 256; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:logger; 248, identifier:warning; 249, argument_list; 249, 250; 249, 251; 250, string:"process %s survived SIGKILL; giving up"; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:process; 254, identifier:name; 255, argument_list; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:result; 259, False; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:logger; 264, identifier:debug; 265, argument_list; 265, 266; 265, 267; 266, string:"Stopping daemons duration: %.2f seconds"; 267, binary_operator:-; 267, 268; 267, 273; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:time; 271, identifier:time; 272, argument_list; 273, identifier:start; 274, return_statement; 274, 275; 275, identifier:result | def daemons_stop(self, timeout=30, kill_children=False):
def on_terminate(proc):
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()):
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()):
if kill_children:
procs = daemon['process'].children()
procs.append(daemon['process'])
_, alive = psutil.wait_procs(procs, timeout=timeout, callback=on_terminate)
if alive:
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:
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; 2, function_name:setup_new_conf; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 16; 5, 412; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 15; 8, attribute; 8, 9; 8, 14; 9, call; 9, 10; 9, 11; 10, identifier:super; 11, argument_list; 11, 12; 11, 13; 12, identifier:Arbiter; 13, identifier:self; 14, identifier:setup_new_conf; 15, argument_list; 16, with_statement; 16, 17; 16, 22; 17, with_clause; 17, 18; 18, with_item; 18, 19; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:conf_lock; 22, block; 22, 23; 22, 30; 22, 38; 22, 50; 22, 60; 22, 68; 22, 75; 22, 94; 22, 102; 22, 112; 22, 122; 22, 128; 22, 136; 22, 229; 22, 245; 22, 254; 22, 262; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:logger; 27, identifier:info; 28, argument_list; 28, 29; 29, string:"I received a new configuration from my master"; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:cur_conf; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:new_conf; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:self_conf; 41, call; 41, 42; 41, 47; 42, attribute; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:cur_conf; 46, identifier:get; 47, argument_list; 47, 48; 47, 49; 48, string:'self_conf'; 49, None; 50, if_statement; 50, 51; 50, 53; 51, not_operator; 51, 52; 52, identifier:self_conf; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:self_conf; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:conf; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:whole_conf; 63, subscript; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:cur_conf; 67, string:'whole_conf'; 68, expression_statement; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:logger; 72, identifier:debug; 73, argument_list; 73, 74; 74, string:"Received a new configuration, containing:"; 75, for_statement; 75, 76; 75, 77; 75, 80; 76, identifier:key; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:cur_conf; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:logger; 85, identifier:debug; 86, argument_list; 86, 87; 86, 88; 86, 89; 87, string:"- %s: %s"; 88, identifier:key; 89, subscript; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:cur_conf; 93, identifier:key; 94, expression_statement; 94, 95; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:logger; 98, identifier:debug; 99, argument_list; 99, 100; 99, 101; 100, string:"satellite self configuration part: %s"; 101, identifier:self_conf; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:alignak_name; 107, subscript; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:cur_conf; 111, string:'alignak_name'; 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:"My Alignak instance: %s"; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:alignak_name; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:new_conf; 127, dictionary; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:t00; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:time; 134, identifier:time; 135, argument_list; 136, try_statement; 136, 137; 136, 145; 136, 184; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:received_conf_part; 141, call; 141, 142; 141, 143; 142, identifier:unserialize; 143, argument_list; 143, 144; 144, identifier:whole_conf; 145, except_clause; 145, 146; 145, 150; 146, as_pattern; 146, 147; 146, 148; 147, identifier:AlignakClassLookupException; 148, as_pattern_target; 148, 149; 149, identifier:exp; 150, block; 150, 151; 150, 160; 150, 171; 150, 183; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:new_conf; 156, dictionary; 156, 157; 157, pair; 157, 158; 157, 159; 158, string:"_status"; 159, string:"Cannot un-serialize configuration received from arbiter"; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:logger; 164, identifier:error; 165, argument_list; 165, 166; 166, subscript; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:new_conf; 170, string:'_status'; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:logger; 175, identifier:error; 176, argument_list; 176, 177; 176, 178; 177, string:"Back trace of the error:\n%s"; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:traceback; 181, identifier:format_exc; 182, argument_list; 183, return_statement; 184, except_clause; 184, 185; 184, 189; 185, as_pattern; 185, 186; 185, 187; 186, identifier:Exception; 187, as_pattern_target; 187, 188; 188, identifier:exp; 189, block; 189, 190; 189, 199; 189, 210; 189, 219; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:new_conf; 195, dictionary; 195, 196; 196, pair; 196, 197; 196, 198; 197, string:"_status"; 198, string:"Cannot un-serialize configuration received from arbiter"; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:logger; 203, identifier:error; 204, argument_list; 204, 205; 205, subscript; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:new_conf; 209, string:'_status'; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:logger; 214, identifier:error; 215, argument_list; 215, 216; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:new_conf; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:exit_on_exception; 224, argument_list; 224, 225; 224, 226; 225, identifier:exp; 226, attribute; 226, 227; 226, 228; 227, identifier:self; 228, identifier:new_conf; 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; 234, 237; 234, 238; 235, string:"Monitored configuration %s received at %d. Un-serialized in %d secs"; 236, identifier:received_conf_part; 237, identifier:t00; 238, binary_operator:-; 238, 239; 238, 244; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:time; 242, identifier:time; 243, argument_list; 244, identifier:t00; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:my_satellites; 248, call; 248, 249; 248, 250; 249, identifier:getattr; 250, argument_list; 250, 251; 250, 252; 250, 253; 251, identifier:self; 252, string:'arbiters'; 253, dictionary; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:received_satellites; 257, subscript; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:self; 260, identifier:cur_conf; 261, string:'arbiters'; 262, for_statement; 262, 263; 262, 264; 262, 265; 263, identifier:link_uuid; 264, identifier:received_satellites; 265, block; 265, 266; 265, 272; 265, 288; 265, 296; 265, 300; 265, 304; 265, 308; 265, 312; 265, 316; 265, 356; 265, 366; 265, 374; 265, 382; 265, 388; 265, 394; 265, 400; 265, 406; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:rs_conf; 269, subscript; 269, 270; 269, 271; 270, identifier:received_satellites; 271, identifier:link_uuid; 272, expression_statement; 272, 273; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:logger; 276, identifier:debug; 277, argument_list; 277, 278; 277, 279; 277, 282; 277, 285; 278, string:"- received %s - %s: %s"; 279, subscript; 279, 280; 279, 281; 280, identifier:rs_conf; 281, string:'instance_id'; 282, subscript; 282, 283; 282, 284; 283, identifier:rs_conf; 284, string:'type'; 285, subscript; 285, 286; 285, 287; 286, identifier:rs_conf; 287, string:'name'; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:already_got; 291, comparison_operator:in; 291, 292; 291, 295; 292, subscript; 292, 293; 292, 294; 293, identifier:rs_conf; 294, string:'instance_id'; 295, identifier:my_satellites; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:broks; 299, list:[]; 300, expression_statement; 300, 301; 301, assignment; 301, 302; 301, 303; 302, identifier:actions; 303, dictionary; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:wait_homerun; 307, dictionary; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 311; 310, identifier:external_commands; 311, dictionary; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 315; 314, identifier:running_id; 315, integer:0; 316, if_statement; 316, 317; 316, 318; 317, identifier:already_got; 318, block; 318, 319; 318, 329; 318, 337; 318, 352; 319, expression_statement; 319, 320; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:logger; 323, identifier:warning; 324, argument_list; 324, 325; 324, 326; 325, string:"I already got: %s"; 326, subscript; 326, 327; 326, 328; 327, identifier:rs_conf; 328, string:'instance_id'; 329, expression_statement; 329, 330; 330, assignment; 330, 331; 330, 332; 331, identifier:running_id; 332, attribute; 332, 333; 332, 336; 333, subscript; 333, 334; 333, 335; 334, identifier:my_satellites; 335, identifier:link_uuid; 336, identifier:running_id; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 344; 338, 345; 339, tuple_pattern; 339, 340; 339, 341; 339, 342; 339, 343; 340, identifier:broks; 341, identifier:actions; 342, identifier:wait_homerun; 343, identifier:external_commands; 344, line_continuation:\; 345, call; 345, 346; 345, 351; 346, attribute; 346, 347; 346, 350; 347, subscript; 347, 348; 347, 349; 348, identifier:my_satellites; 349, identifier:link_uuid; 350, identifier:get_and_clear_context; 351, argument_list; 352, delete_statement; 352, 353; 353, subscript; 353, 354; 353, 355; 354, identifier:my_satellites; 355, identifier:link_uuid; 356, expression_statement; 356, 357; 357, assignment; 357, 358; 357, 359; 358, identifier:new_link; 359, call; 359, 360; 359, 363; 360, attribute; 360, 361; 360, 362; 361, identifier:SatelliteLink; 362, identifier:get_a_satellite_link; 363, argument_list; 363, 364; 363, 365; 364, string:'arbiter'; 365, identifier:rs_conf; 366, expression_statement; 366, 367; 367, assignment; 367, 368; 367, 373; 368, subscript; 368, 369; 368, 370; 369, identifier:my_satellites; 370, attribute; 370, 371; 370, 372; 371, identifier:new_link; 372, identifier:uuid; 373, identifier:new_link; 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; 379, 381; 380, string:"I got a new arbiter satellite: %s"; 381, identifier:new_link; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 387; 384, attribute; 384, 385; 384, 386; 385, identifier:new_link; 386, identifier:running_id; 387, identifier:running_id; 388, expression_statement; 388, 389; 389, assignment; 389, 390; 389, 393; 390, attribute; 390, 391; 390, 392; 391, identifier:new_link; 392, identifier:external_commands; 393, identifier:external_commands; 394, expression_statement; 394, 395; 395, assignment; 395, 396; 395, 399; 396, attribute; 396, 397; 396, 398; 397, identifier:new_link; 398, identifier:broks; 399, identifier:broks; 400, expression_statement; 400, 401; 401, assignment; 401, 402; 401, 405; 402, attribute; 402, 403; 402, 404; 403, identifier:new_link; 404, identifier:wait_homerun; 405, identifier:wait_homerun; 406, expression_statement; 406, 407; 407, assignment; 407, 408; 407, 411; 408, attribute; 408, 409; 408, 410; 409, identifier:new_link; 410, identifier:actions; 411, identifier:actions; 412, expression_statement; 412, 413; 413, assignment; 413, 414; 413, 417; 414, attribute; 414, 415; 414, 416; 415, identifier:self; 416, identifier:have_conf; 417, True | def setup_new_conf(self):
super(Arbiter, self).setup_new_conf()
with self.conf_lock:
logger.info("I received a new configuration from my master")
self.cur_conf = self.new_conf
self_conf = self.cur_conf.get('self_conf', None)
if not self_conf:
self_conf = self.conf
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)
self.alignak_name = self.cur_conf['alignak_name']
logger.info("My Alignak instance: %s", self.alignak_name)
self.new_conf = {}
t00 = time.time()
try:
received_conf_part = unserialize(whole_conf)
except AlignakClassLookupException as exp:
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:
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)
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'])
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'])
running_id = my_satellites[link_uuid].running_id
(broks, actions,
wait_homerun, external_commands) = \
my_satellites[link_uuid].get_and_clear_context()
del my_satellites[link_uuid]
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
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, 13; 5, 17; 5, 27; 5, 31; 5, 56; 5, 64; 6, expression_statement; 6, 7; 7, call; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:logger; 10, identifier:info; 11, argument_list; 11, 12; 12, string:"Waiting for master death"; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:timeout; 16, float:1.0; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:last_master_ping; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:time; 25, identifier:time; 26, argument_list; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:master_timeout; 30, integer:300; 31, for_statement; 31, 32; 31, 33; 31, 38; 32, identifier:arbiter_link; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:conf; 37, identifier:arbiters; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 44; 40, not_operator; 40, 41; 41, attribute; 41, 42; 41, 43; 42, identifier:arbiter_link; 43, identifier:spare; 44, block; 44, 45; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 46, 49; 47, identifier:master_timeout; 48, line_continuation:\; 49, binary_operator:*; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:arbiter_link; 52, identifier:spare_check_interval; 53, attribute; 53, 54; 53, 55; 54, identifier:arbiter_link; 55, identifier:spare_max_check_attempts; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:logger; 60, identifier:info; 61, argument_list; 61, 62; 61, 63; 62, string:"I'll wait master death for %d seconds"; 63, identifier:master_timeout; 64, while_statement; 64, 65; 64, 69; 65, not_operator; 65, 66; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:interrupted; 69, block; 69, 70; 69, 81; 69, 90; 69, 101; 69, 110; 69, 118; 69, 126; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, pattern_list; 72, 73; 72, 74; 73, identifier:_; 74, identifier:tcdiff; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:make_a_pause; 79, argument_list; 79, 80; 80, identifier:timeout; 81, if_statement; 81, 82; 81, 83; 82, identifier:tcdiff; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, augmented_assignment:+=; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:last_master_ping; 89, identifier:tcdiff; 90, if_statement; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:new_conf; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:setup_new_conf; 100, argument_list; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 108; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:sys; 106, identifier:stdout; 107, identifier:write; 108, argument_list; 108, 109; 109, string:"."; 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:sys; 115, identifier:stdout; 116, identifier:flush; 117, argument_list; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:now; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:time; 124, identifier:time; 125, argument_list; 126, if_statement; 126, 127; 126, 134; 127, comparison_operator:>; 127, 128; 127, 133; 128, binary_operator:-; 128, 129; 128, 130; 129, identifier:now; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:last_master_ping; 133, identifier:master_timeout; 134, block; 134, 135; 134, 147; 134, 167; 134, 173; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:logger; 139, identifier:info; 140, argument_list; 140, 141; 140, 142; 141, string:"Arbiter Master is dead. The arbiter %s takes the lead!"; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:link_to_myself; 146, identifier:name; 147, for_statement; 147, 148; 147, 149; 147, 154; 148, identifier:arbiter_link; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:conf; 153, identifier:arbiters; 154, block; 154, 155; 155, if_statement; 155, 156; 155, 160; 156, not_operator; 156, 157; 157, attribute; 157, 158; 157, 159; 158, identifier:arbiter_link; 159, identifier:spare; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:arbiter_link; 165, identifier:alive; 166, False; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:must_run; 172, True; 173, break_statement | def wait_for_master_death(self):
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:
_, tcdiff = self.make_a_pause(timeout)
if tcdiff:
self.last_master_ping += tcdiff
if self.new_conf:
self.setup_new_conf()
sys.stdout.write(".")
sys.stdout.flush()
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, ERROR; 1, 2; 1, 257; 1, 261; 1, 268; 1, 408; 2, function_definition; 2, 3; 2, 4; 2, 9; 3, function_name:configuration_dispatch; 4, parameters; 4, 5; 4, 6; 5, identifier:self; 6, default_parameter; 6, 7; 6, 8; 7, identifier:not_configured; 8, None; 9, block; 9, 10; 9, 179; 9, 187; 9, 199; 9, 213; 9, 221; 9, 228; 9, 236; 9, 250; 10, if_statement; 10, 11; 10, 13; 11, not_operator; 11, 12; 12, identifier:not_configured; 13, block; 13, 14; 13, 28; 13, 36; 13, 40; 13, 47; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:dispatcher; 19, call; 19, 20; 19, 21; 20, identifier:Dispatcher; 21, argument_list; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:conf; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:link_to_myself; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:cur_conf; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:conf; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:first_connection_try_count; 39, integer:0; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:logger; 44, identifier:info; 45, argument_list; 45, 46; 46, string:"Connecting to my satellites..."; 47, while_statement; 47, 48; 47, 49; 48, True; 49, block; 49, 50; 49, 54; 49, 60; 49, 114; 49, 148; 49, 168; 50, expression_statement; 50, 51; 51, augmented_assignment:+=; 51, 52; 51, 53; 52, identifier:first_connection_try_count; 53, integer:1; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:all_connected; 59, True; 60, for_statement; 60, 61; 60, 62; 60, 67; 61, identifier:satellite; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:dispatcher; 66, identifier:all_daemons_links; 67, block; 67, 68; 67, 76; 67, 83; 67, 95; 67, 104; 68, if_statement; 68, 69; 68, 74; 69, comparison_operator:==; 69, 70; 69, 71; 70, identifier:satellite; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:link_to_myself; 74, block; 74, 75; 75, continue_statement; 76, if_statement; 76, 77; 76, 81; 77, not_operator; 77, 78; 78, attribute; 78, 79; 78, 80; 79, identifier:satellite; 80, identifier:active; 81, block; 81, 82; 82, continue_statement; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:connected; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:daemon_connection_init; 90, argument_list; 90, 91; 90, 92; 91, identifier:satellite; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:set_wait_new_conf; 94, True; 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; 100, 103; 101, string:" %s is %s"; 102, identifier:satellite; 103, identifier:connected; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:all_connected; 109, boolean_operator:and; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:all_connected; 113, identifier:connected; 114, if_statement; 114, 115; 114, 118; 114, 126; 114, 128; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:all_connected; 118, ERROR; 118, 119; 118, 122; 118, 123; 118, 125; 119, attribute; 119, 120; 119, 121; 120, identifier:logger; 121, identifier:info; 122, ERROR; 123, unary_operator:-; 123, 124; 124, identifier:satellites; 125, identifier:connection; 126, block; 126, 127; 127, break_statement; 128, else_clause; 128, 129; 128, 137; 129, ERROR; 129, 130; 129, 133; 129, 134; 129, 136; 130, attribute; 130, 131; 130, 132; 131, identifier:logger; 132, identifier:warning; 133, ERROR; 134, unary_operator:-; 134, 135; 135, identifier:satellites; 136, identifier:connection; 137, block; 137, 138; 137, 140; 137, 142; 138, expression_statement; 138, 139; 139, string:"let's give another chance after %d seconds..."; 140, expression_statement; 140, 141; 141, identifier:first_connection_try_count; 142, ERROR; 142, 143; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:link_to_myself; 147, identifier:polling_interval; 148, if_statement; 148, 149; 148, 152; 149, comparison_operator:>=; 149, 150; 149, 151; 150, identifier:first_connection_try_count; 151, integer:3; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:self; 157, identifier:request_stop; 158, argument_list; 158, 159; 158, 165; 159, binary_operator:%; 159, 160; 159, 164; 160, concatenated_string; 160, 161; 160, 162; 160, 163; 161, string:"All the daemons connections could not be established "; 162, string:"despite %d tries! "; 163, string:"Sorry, I bail out!"; 164, identifier:first_connection_try_count; 165, keyword_argument; 165, 166; 165, 167; 166, identifier:exit_code; 167, integer:4; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:time; 172, identifier:sleep; 173, argument_list; 173, 174; 174, attribute; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:link_to_myself; 178, identifier:polling_interval; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:_t0; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:time; 185, identifier:time; 186, argument_list; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:all_connected; 192, call; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:self; 196, identifier:dispatcher; 197, identifier:check_reachable; 198, argument_list; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:statsmgr; 203, identifier:timer; 204, argument_list; 204, 205; 204, 206; 205, string:'dispatcher.check-alive'; 206, binary_operator:-; 206, 207; 206, 212; 207, call; 207, 208; 207, 211; 208, attribute; 208, 209; 208, 210; 209, identifier:time; 210, identifier:time; 211, argument_list; 212, identifier:_t0; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:_t0; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:time; 219, identifier:time; 220, argument_list; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:logger; 225, identifier:info; 226, argument_list; 226, 227; 227, string:"Preparing the configuration for dispatching..."; 228, expression_statement; 228, 229; 229, call; 229, 230; 229, 235; 230, attribute; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:dispatcher; 234, identifier:prepare_dispatch; 235, argument_list; 236, expression_statement; 236, 237; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:statsmgr; 240, identifier:timer; 241, argument_list; 241, 242; 241, 243; 242, string:'dispatcher.prepare-dispatch'; 243, binary_operator:-; 243, 244; 243, 249; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:time; 247, identifier:time; 248, argument_list; 249, identifier:_t0; 250, expression_statement; 250, 251; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:logger; 254, identifier:info; 255, argument_list; 255, 256; 256, string:"- configuration is ready to dispatch"; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:first_dispatch_try_count; 260, integer:0; 261, expression_statement; 261, 262; 262, call; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:logger; 265, identifier:info; 266, argument_list; 266, 267; 267, string:"Dispatching the configuration to my satellites..."; 268, while_statement; 268, 269; 268, 270; 268, 385; 268, 393; 268, 395; 269, True; 270, ERROR; 270, 271; 270, 275; 270, 283; 270, 286; 270, 287; 270, 380; 271, expression_statement; 271, 272; 272, augmented_assignment:+=; 272, 273; 272, 274; 273, identifier:first_dispatch_try_count; 274, integer:1; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 278; 277, identifier:_t0; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:time; 281, identifier:time; 282, argument_list; 283, attribute; 283, 284; 283, 285; 284, identifier:logger; 285, identifier:info; 286, ERROR; 287, unary_operator:-; 287, 288; 287, 367; 288, ERROR; 288, 289; 288, 290; 288, 291; 288, 301; 288, 314; 288, 315; 288, 335; 288, 342; 288, 348; 288, 349; 288, 354; 288, 360; 289, identifier:configuration; 290, identifier:dispatching; 291, call; 291, 292; 291, 297; 292, attribute; 292, 293; 292, 296; 293, attribute; 293, 294; 293, 295; 294, identifier:self; 295, identifier:dispatcher; 296, identifier:check_reachable; 297, argument_list; 297, 298; 298, keyword_argument; 298, 299; 298, 300; 299, identifier:forced; 300, True; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:statsmgr; 304, identifier:timer; 305, argument_list; 305, 306; 305, 307; 306, string:'dispatcher.dispatch'; 307, binary_operator:-; 307, 308; 307, 313; 308, call; 308, 309; 308, 312; 309, attribute; 309, 310; 309, 311; 310, identifier:time; 311, identifier:time; 312, argument_list; 313, identifier:_t0; 314, identifier:pause; 315, call; 315, 316; 315, 317; 316, identifier:max; 317, argument_list; 317, 318; 317, 319; 318, integer:1; 319, call; 319, 320; 319, 321; 320, identifier:max; 321, argument_list; 321, 322; 321, 327; 322, attribute; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:self; 325, identifier:conf; 326, identifier:daemons_dispatch_timeout; 327, binary_operator:*; 327, 328; 327, 334; 328, call; 328, 329; 328, 330; 329, identifier:len; 330, argument_list; 330, 331; 331, attribute; 331, 332; 331, 333; 332, identifier:self; 333, identifier:my_daemons; 334, float:0.5; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:logger; 338, identifier:info; 339, argument_list; 339, 340; 339, 341; 340, string:"- pausing %d seconds..."; 341, identifier:pause; 342, call; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:time; 345, identifier:sleep; 346, argument_list; 346, 347; 347, identifier:pause; 348, identifier:_t0; 349, call; 349, 350; 349, 353; 350, attribute; 350, 351; 350, 352; 351, identifier:time; 352, identifier:time; 353, argument_list; 354, call; 354, 355; 354, 358; 355, attribute; 355, 356; 355, 357; 356, identifier:logger; 357, identifier:info; 358, argument_list; 358, 359; 359, string:"- checking configuration dispatch..."; 360, call; 360, 361; 360, 366; 361, attribute; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, identifier:self; 364, identifier:dispatcher; 365, identifier:check_dispatch; 366, argument_list; 367, call; 367, 368; 367, 371; 368, attribute; 368, 369; 368, 370; 369, identifier:statsmgr; 370, identifier:timer; 371, argument_list; 371, 372; 371, 373; 372, string:'dispatcher.check-dispatch'; 373, binary_operator:-; 373, 374; 373, 379; 374, call; 374, 375; 374, 378; 375, attribute; 375, 376; 375, 377; 376, identifier:time; 377, identifier:time; 378, argument_list; 379, identifier:_t0; 380, attribute; 380, 381; 380, 384; 381, attribute; 381, 382; 381, 383; 382, identifier:self; 383, identifier:dispatcher; 384, identifier:dispatch_ok; 385, ERROR; 385, 386; 385, 389; 385, 390; 385, 392; 386, attribute; 386, 387; 386, 388; 387, identifier:logger; 388, identifier:info; 389, ERROR; 390, unary_operator:-; 390, 391; 391, identifier:configuration; 392, identifier:dispatching; 393, block; 393, 394; 394, break_statement; 395, else_clause; 395, 396; 395, 404; 395, 407; 396, ERROR; 396, 397; 396, 400; 396, 401; 396, 403; 397, attribute; 397, 398; 397, 399; 398, identifier:logger; 399, identifier:warning; 400, ERROR; 401, unary_operator:-; 401, 402; 402, identifier:configuration; 403, identifier:dispatching; 404, ERROR; 404, 405; 404, 406; 405, string:"let's give another chance..."; 406, identifier:first_dispatch_try_count; 407, block:; 408, if_statement; 408, 409; 408, 412; 408, 428; 409, comparison_operator:>=; 409, 410; 409, 411; 410, identifier:first_dispatch_try_count; 411, integer:3; 412, ERROR; 412, 413; 413, block; 413, 414; 414, expression_statement; 414, 415; 415, call; 415, 416; 415, 419; 416, attribute; 416, 417; 416, 418; 417, identifier:self; 418, identifier:request_stop; 419, argument_list; 419, 420; 419, 425; 420, binary_operator:%; 420, 421; 420, 424; 421, concatenated_string; 421, 422; 421, 423; 422, string:"The configuration could not be dispatched despite %d tries! "; 423, string:"Sorry, I bail out!"; 424, identifier:first_connection_try_count; 425, keyword_argument; 425, 426; 425, 427; 426, identifier:exit_code; 427, integer:4; 428, block: | def configuration_dispatch(self, not_configured=None):
if not not_configured:
self.dispatcher = Dispatcher(self.conf, self.link_to_myself)
self.cur_conf = self.conf
first_connection_try_count = 0
logger.info("Connecting to my satellites...")
while True:
first_connection_try_count += 1
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
break
else:
logger.warning("- satellites connection
"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)
_t0 = time.time()
self.all_connected = self.dispatcher.check_reachable()
statsmgr.timer('dispatcher.check-alive', time.time() - _t0)
_t0 = time.time()
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")
first_dispatch_try_count = 0
logger.info("Dispatching the configuration to my satellites...")
while True:
first_dispatch_try_count += 1
_t0 = time.time()
logger.info("- configuration dispatching
self.dispatcher.check_reachable(forced=True)
statsmgr.timer('dispatcher.dispatch', time.time() - _t0)
pause = max(1, max(self.conf.daemons_dispatch_timeout, len(self.my_daemons) * 0.5))
logger.info("- pausing %d seconds...", pause)
time.sleep(pause)
_t0 = time.time()
logger.info("- checking configuration dispatch...")
self.dispatcher.check_dispatch()
statsmgr.timer('dispatcher.check-dispatch', time.time() - _t0)
if self.dispatcher.dispatch_ok:
logger.info("- configuration dispatching
break
else:
logger.warning("- configuration dispatching
"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; 2, function_name:duplicate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:host; 6, block; 6, 7; 6, 11; 6, 25; 6, 34; 6, 42; 6, 67; 6, 74; 6, 83; 6, 155; 6, 339; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:duplicates; 10, list:[]; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:prop; 14, call; 14, 15; 14, 24; 15, attribute; 15, 16; 15, 23; 16, call; 16, 17; 16, 22; 17, attribute; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:duplicate_foreach; 21, identifier:strip; 22, argument_list; 23, identifier:upper; 24, argument_list; 25, if_statement; 25, 26; 25, 31; 26, comparison_operator:not; 26, 27; 26, 28; 27, identifier:prop; 28, attribute; 28, 29; 28, 30; 29, identifier:host; 30, identifier:customs; 31, block; 31, 32; 32, return_statement; 32, 33; 33, identifier:duplicates; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:entry; 37, subscript; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:host; 40, identifier:customs; 41, identifier:prop; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:not_entry; 45, call; 45, 46; 45, 65; 46, attribute; 46, 47; 46, 64; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:host; 51, identifier:customs; 52, identifier:get; 53, argument_list; 53, 54; 53, 63; 54, binary_operator:+; 54, 55; 54, 58; 55, binary_operator:+; 55, 56; 55, 57; 56, string:'_'; 57, string:'!'; 58, subscript; 58, 59; 58, 60; 59, identifier:prop; 60, slice; 60, 61; 60, 62; 61, integer:1; 62, colon; 63, string:''; 64, identifier:split; 65, argument_list; 65, 66; 66, string:','; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:not_keys; 70, call; 70, 71; 70, 72; 71, identifier:strip_and_uniq; 72, argument_list; 72, 73; 73, identifier:not_entry; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:default_value; 77, call; 77, 78; 77, 79; 78, identifier:getattr; 79, argument_list; 79, 80; 79, 81; 79, 82; 80, identifier:self; 81, string:'default_value'; 82, string:''; 83, try_statement; 83, 84; 83, 96; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:key_values; 88, call; 88, 89; 88, 90; 89, identifier:tuple; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:generate_key_value_sequences; 93, argument_list; 93, 94; 93, 95; 94, identifier:entry; 95, identifier:default_value; 96, except_clause; 96, 97; 96, 101; 97, as_pattern; 97, 98; 97, 99; 98, identifier:KeyValueSyntaxError; 99, as_pattern_target; 99, 100; 100, identifier:exc; 101, block; 101, 102; 101, 129; 101, 139; 101, 146; 101, 153; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:fmt_dict; 105, dictionary; 105, 106; 105, 111; 105, 118; 105, 123; 105, 126; 106, pair; 106, 107; 106, 108; 107, string:'prop'; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:duplicate_foreach; 111, pair; 111, 112; 111, 113; 112, string:'host'; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:host; 116, identifier:get_name; 117, argument_list; 118, pair; 118, 119; 118, 120; 119, string:'svc'; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:service_description; 123, pair; 123, 124; 123, 125; 124, string:'entry'; 125, identifier:entry; 126, pair; 126, 127; 126, 128; 127, string:'exc'; 128, identifier:exc; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:err; 132, binary_operator:%; 132, 133; 132, 138; 133, parenthesized_expression; 133, 134; 134, concatenated_string; 134, 135; 134, 136; 134, 137; 135, string:"The custom property %(prop)r of the "; 136, string:"host %(host)r is not a valid entry for a service generator: %(exc)s, "; 137, string:"with entry=%(entry)r"; 138, identifier:fmt_dict; 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; 145, identifier:err; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:host; 150, identifier:add_error; 151, argument_list; 151, 152; 152, identifier:err; 153, return_statement; 153, 154; 154, identifier:duplicates; 155, for_statement; 155, 156; 155, 157; 155, 158; 156, identifier:key_value; 157, identifier:key_values; 158, block; 158, 159; 158, 165; 158, 171; 158, 179; 158, 189; 158, 202; 158, 332; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:key; 162, subscript; 162, 163; 162, 164; 163, identifier:key_value; 164, string:'KEY'; 165, if_statement; 165, 166; 165, 169; 166, comparison_operator:in; 166, 167; 166, 168; 167, identifier:key; 168, identifier:not_keys; 169, block; 169, 170; 170, continue_statement; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 174; 173, identifier:new_s; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:copy; 178, argument_list; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:new_s; 183, identifier:host_name; 184, call; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:host; 187, identifier:get_name; 188, argument_list; 189, if_statement; 189, 190; 189, 195; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:is_tpl; 194, argument_list; 195, block; 195, 196; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:new_s; 200, identifier:register; 201, integer:1; 202, for_statement; 202, 203; 202, 204; 202, 205; 203, identifier:key; 204, identifier:key_value; 205, block; 205, 206; 205, 253; 205, 260; 205, 294; 206, if_statement; 206, 207; 206, 210; 207, comparison_operator:==; 207, 208; 207, 209; 208, identifier:key; 209, string:'KEY'; 210, block; 210, 211; 211, if_statement; 211, 212; 211, 217; 212, call; 212, 213; 212, 214; 213, identifier:hasattr; 214, argument_list; 214, 215; 214, 216; 215, identifier:self; 216, string:'service_description'; 217, block; 217, 218; 217, 235; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:safe_key_value; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:re; 224, identifier:sub; 225, argument_list; 225, 226; 225, 231; 225, 232; 226, binary_operator:+; 226, 227; 226, 230; 227, binary_operator:+; 227, 228; 227, 229; 228, string:r'['; 229, string:"`~!$%^&*\"|'<>?,()="; 230, string:']+'; 231, string:'_'; 232, subscript; 232, 233; 232, 234; 233, identifier:key_value; 234, identifier:key; 235, expression_statement; 235, 236; 236, assignment; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:new_s; 239, identifier:service_description; 240, call; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:service_description; 245, identifier:replace; 246, argument_list; 246, 247; 246, 252; 247, binary_operator:+; 247, 248; 247, 251; 248, binary_operator:+; 248, 249; 248, 250; 249, string:'$'; 250, identifier:key; 251, string:'$'; 252, identifier:safe_key_value; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:_the_expandables; 256, list:['check_command', 'aggregation', 'event_handler']; 256, 257; 256, 258; 256, 259; 257, string:'check_command'; 258, string:'aggregation'; 259, string:'event_handler'; 260, for_statement; 260, 261; 260, 262; 260, 263; 261, identifier:prop; 262, identifier:_the_expandables; 263, block; 263, 264; 264, if_statement; 264, 265; 264, 270; 265, call; 265, 266; 265, 267; 266, identifier:hasattr; 267, argument_list; 267, 268; 267, 269; 268, identifier:self; 269, identifier:prop; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 274; 273, identifier:setattr; 274, argument_list; 274, 275; 274, 276; 274, 277; 275, identifier:new_s; 276, identifier:prop; 277, call; 277, 278; 277, 285; 278, attribute; 278, 279; 278, 284; 279, call; 279, 280; 279, 281; 280, identifier:getattr; 281, argument_list; 281, 282; 281, 283; 282, identifier:new_s; 283, identifier:prop; 284, identifier:replace; 285, argument_list; 285, 286; 285, 291; 286, binary_operator:+; 286, 287; 286, 290; 287, binary_operator:+; 287, 288; 287, 289; 288, string:'$'; 289, identifier:key; 290, string:'$'; 291, subscript; 291, 292; 291, 293; 292, identifier:key_value; 293, identifier:key; 294, if_statement; 294, 295; 294, 300; 295, call; 295, 296; 295, 297; 296, identifier:hasattr; 297, argument_list; 297, 298; 297, 299; 298, identifier:self; 299, string:'service_dependencies'; 300, block; 300, 301; 301, for_statement; 301, 302; 301, 305; 301, 311; 302, pattern_list; 302, 303; 302, 304; 303, identifier:i; 304, identifier:servicedep; 305, call; 305, 306; 305, 307; 306, identifier:enumerate; 307, argument_list; 307, 308; 308, attribute; 308, 309; 308, 310; 309, identifier:new_s; 310, identifier:service_dependencies; 311, block; 311, 312; 312, expression_statement; 312, 313; 313, assignment; 313, 314; 313, 319; 314, subscript; 314, 315; 314, 318; 315, attribute; 315, 316; 315, 317; 316, identifier:new_s; 317, identifier:service_dependencies; 318, identifier:i; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:servicedep; 322, identifier:replace; 323, argument_list; 323, 324; 323, 329; 324, binary_operator:+; 324, 325; 324, 328; 325, binary_operator:+; 325, 326; 325, 327; 326, string:'$'; 327, identifier:key; 328, string:'$'; 329, subscript; 329, 330; 329, 331; 330, identifier:key_value; 331, identifier:key; 332, expression_statement; 332, 333; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:duplicates; 336, identifier:append; 337, argument_list; 337, 338; 338, identifier:new_s; 339, return_statement; 339, 340; 340, identifier:duplicates | def duplicate(self, host):
duplicates = []
prop = self.duplicate_foreach.strip().upper()
if prop not in host.customs:
return duplicates
entry = host.customs[prop]
not_entry = host.customs.get('_' + '!' + prop[1:], '').split(',')
not_keys = strip_and_uniq(not_entry)
default_value = getattr(self, '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']
if key in not_keys:
continue
new_s = self.copy()
new_s.host_name = host.get_name()
if self.is_tpl():
new_s.register = 1
for key in key_value:
if key == 'KEY':
if hasattr(self, 'service_description'):
safe_key_value = re.sub(r'[' + "`~!$%^&*\"|'<>?,()=" + ']+', '_',
key_value[key])
new_s.service_description = self.service_description.replace(
'$' + key + '$', safe_key_value
)
_the_expandables = ['check_command', 'aggregation', 'event_handler']
for prop in _the_expandables:
if hasattr(self, prop):
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]
)
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, 13; 8, 17; 8, 57; 8, 67; 8, 84; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:duplicate_for_hosts; 12, list:[]; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:not_hosts; 16, list:[]; 17, for_statement; 17, 18; 17, 19; 17, 20; 18, identifier:hname; 19, identifier:hnames; 20, block; 20, 21; 20, 29; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:hname; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:hname; 27, identifier:strip; 28, argument_list; 29, if_statement; 29, 30; 29, 36; 29, 48; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:hname; 33, identifier:startswith; 34, argument_list; 34, 35; 35, string:'!'; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:not_hosts; 41, identifier:append; 42, argument_list; 42, 43; 43, subscript; 43, 44; 43, 45; 44, identifier:hname; 45, slice; 45, 46; 45, 47; 46, integer:1; 47, colon; 48, else_clause; 48, 49; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:duplicate_for_hosts; 54, identifier:append; 55, argument_list; 55, 56; 56, identifier:hname; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:duplicate_for_hosts; 60, call; 60, 61; 60, 62; 61, identifier:list; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:set; 65, argument_list; 65, 66; 66, identifier:duplicate_for_hosts; 67, for_statement; 67, 68; 67, 69; 67, 70; 68, identifier:hname; 69, identifier:not_hosts; 70, block; 70, 71; 71, try_statement; 71, 72; 71, 80; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:duplicate_for_hosts; 77, identifier:remove; 78, argument_list; 78, 79; 79, identifier:hname; 80, except_clause; 80, 81; 80, 82; 81, identifier:IndexError; 82, block; 82, 83; 83, pass_statement; 84, for_statement; 84, 85; 84, 86; 84, 87; 85, identifier:hname; 86, identifier:duplicate_for_hosts; 87, block; 87, 88; 87, 97; 87, 118; 87, 127; 87, 135; 87, 141; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:host; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:hosts; 94, identifier:find_by_name; 95, argument_list; 95, 96; 96, identifier:hname; 97, if_statement; 97, 98; 97, 101; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:host; 100, None; 101, block; 101, 102; 101, 117; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:service; 106, identifier:add_error; 107, argument_list; 107, 108; 108, binary_operator:%; 108, 109; 108, 110; 109, string:"Error: The hostname %s is unknown for the service %s!"; 110, tuple; 110, 111; 110, 112; 111, identifier:hname; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:service; 115, identifier:get_name; 116, argument_list; 117, continue_statement; 118, if_statement; 118, 119; 118, 125; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:host; 122, identifier:is_excluded_for; 123, argument_list; 123, 124; 124, identifier:service; 125, block; 125, 126; 126, continue_statement; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:new_s; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:service; 133, identifier:copy; 134, argument_list; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:new_s; 139, identifier:host_name; 140, identifier:hname; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:add_item; 146, argument_list; 146, 147; 147, identifier:new_s | def explode_services_from_hosts(self, hosts, service, hnames):
duplicate_for_hosts = []
not_hosts = []
for hname in hnames:
hname = hname.strip()
if hname.startswith('!'):
not_hosts.append(hname[1:])
else:
duplicate_for_hosts.append(hname)
duplicate_for_hosts = list(set(duplicate_for_hosts))
for hname in not_hosts:
try:
duplicate_for_hosts.remove(hname)
except IndexError:
pass
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; 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, block; 10, 11; 10, 24; 10, 132; 10, 162; 10, 179; 10, 212; 10, 216; 10, 248; 10, 259; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:itemkeys; 14, call; 14, 15; 14, 16; 15, identifier:list; 16, argument_list; 16, 17; 17, call; 17, 18; 17, 23; 18, attribute; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:items; 22, identifier:keys; 23, argument_list; 24, for_statement; 24, 25; 24, 26; 24, 27; 25, identifier:s_id; 26, identifier:itemkeys; 27, block; 27, 28; 27, 36; 27, 45; 27, 53; 27, 62; 27, 91; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:serv; 31, subscript; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:items; 35, identifier:s_id; 36, expression_statement; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:explode_host_groups_into_hosts; 41, argument_list; 41, 42; 41, 43; 41, 44; 42, identifier:serv; 43, identifier:hosts; 44, identifier:hostgroups; 45, expression_statement; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:explode_contact_groups_into_contacts; 50, argument_list; 50, 51; 50, 52; 51, identifier:serv; 52, identifier:contactgroups; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:hnames; 56, call; 56, 57; 56, 58; 57, identifier:getattr; 58, argument_list; 58, 59; 58, 60; 58, 61; 59, identifier:serv; 60, string:"host_name"; 61, string:''; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:hnames; 65, call; 65, 66; 65, 67; 66, identifier:list; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 70; 69, identifier:set; 70, argument_list; 70, 71; 71, list_comprehension; 71, 72; 71, 77; 71, 85; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:n; 75, identifier:strip; 76, argument_list; 77, for_in_clause; 77, 78; 77, 79; 78, identifier:n; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:hnames; 82, identifier:split; 83, argument_list; 83, 84; 84, string:','; 85, if_clause; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:n; 89, identifier:strip; 90, argument_list; 91, if_statement; 91, 92; 91, 98; 91, 106; 92, comparison_operator:==; 92, 93; 92, 97; 93, call; 93, 94; 93, 95; 94, identifier:len; 95, argument_list; 95, 96; 96, identifier:hnames; 97, integer:1; 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:index_item; 104, argument_list; 104, 105; 105, identifier:serv; 106, else_clause; 106, 107; 107, block; 107, 108; 107, 125; 108, if_statement; 108, 109; 108, 115; 109, comparison_operator:>=; 109, 110; 109, 114; 110, call; 110, 111; 110, 112; 111, identifier:len; 112, argument_list; 112, 113; 113, identifier:hnames; 114, integer:2; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:explode_services_from_hosts; 121, argument_list; 121, 122; 121, 123; 121, 124; 122, identifier:hosts; 123, identifier:serv; 124, identifier:hnames; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:remove_item; 130, argument_list; 130, 131; 131, identifier:serv; 132, for_statement; 132, 133; 132, 134; 132, 137; 133, identifier:s_id; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:templates; 137, block; 137, 138; 137, 146; 137, 154; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:template; 141, subscript; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:templates; 145, identifier:s_id; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:self; 150, identifier:explode_contact_groups_into_contacts; 151, argument_list; 151, 152; 151, 153; 152, identifier:template; 153, identifier:contactgroups; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:explode_services_from_templates; 159, argument_list; 159, 160; 159, 161; 160, identifier:hosts; 161, identifier:template; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:duplicates; 165, list_comprehension; 165, 166; 165, 169; 165, 172; 166, attribute; 166, 167; 166, 168; 167, identifier:serv; 168, identifier:uuid; 169, for_in_clause; 169, 170; 169, 171; 170, identifier:serv; 171, identifier:self; 172, if_clause; 172, 173; 173, call; 173, 174; 173, 175; 174, identifier:getattr; 175, argument_list; 175, 176; 175, 177; 175, 178; 176, identifier:serv; 177, string:'duplicate_foreach'; 178, string:''; 179, for_statement; 179, 180; 179, 181; 179, 182; 180, identifier:s_id; 181, identifier:duplicates; 182, block; 182, 183; 182, 191; 182, 199; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:serv; 186, subscript; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:items; 190, identifier:s_id; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:explode_services_duplicates; 196, argument_list; 196, 197; 196, 198; 197, identifier:hosts; 198, identifier:serv; 199, if_statement; 199, 200; 199, 204; 200, not_operator; 200, 201; 201, attribute; 201, 202; 201, 203; 202, identifier:serv; 203, identifier:configuration_errors; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:remove_item; 210, argument_list; 210, 211; 211, identifier:serv; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:to_remove; 215, list:[]; 216, for_statement; 216, 217; 216, 218; 216, 219; 217, identifier:service; 218, identifier:self; 219, block; 219, 220; 219, 231; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 223; 222, identifier:host; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:hosts; 226, identifier:find_by_name; 227, argument_list; 227, 228; 228, attribute; 228, 229; 228, 230; 229, identifier:service; 230, identifier:host_name; 231, if_statement; 231, 232; 231, 240; 232, boolean_operator:and; 232, 233; 232, 234; 233, identifier:host; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:host; 237, identifier:is_excluded_for; 238, argument_list; 238, 239; 239, identifier:service; 240, block; 240, 241; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:to_remove; 245, identifier:append; 246, argument_list; 246, 247; 247, identifier:service; 248, for_statement; 248, 249; 248, 250; 248, 251; 249, identifier:service; 250, identifier:to_remove; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:remove_item; 257, argument_list; 257, 258; 258, identifier:service; 259, for_statement; 259, 260; 259, 261; 259, 262; 260, identifier:serv; 261, identifier:self; 262, block; 262, 263; 262, 271; 263, expression_statement; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:register_service_into_servicegroups; 268, argument_list; 268, 269; 268, 270; 269, identifier:serv; 270, identifier:servicegroups; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:register_service_dependencies; 276, argument_list; 276, 277; 276, 278; 277, identifier:serv; 278, identifier:servicedependencies | def explode(self, hosts, hostgroups, contactgroups, servicegroups, servicedependencies):
itemkeys = list(self.items.keys())
for s_id in itemkeys:
serv = self.items[s_id]
self.explode_host_groups_into_hosts(serv, hosts, hostgroups)
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()]))
if len(hnames) == 1:
self.index_item(serv)
else:
if len(hnames) >= 2:
self.explode_services_from_hosts(hosts, serv, hnames)
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)
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)
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, 45; 10, 53; 10, 68; 10, 78; 10, 85; 10, 100; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:short_states; 14, dictionary; 14, 15; 14, 18; 14, 21; 14, 24; 14, 27; 14, 30; 14, 33; 14, 36; 14, 39; 14, 42; 15, pair; 15, 16; 15, 17; 16, string:u'WARNING'; 17, string:'w'; 18, pair; 18, 19; 18, 20; 19, string:u'UNKNOWN'; 20, string:'u'; 21, pair; 21, 22; 21, 23; 22, string:u'CRITICAL'; 23, string:'c'; 24, pair; 24, 25; 24, 26; 25, string:u'RECOVERY'; 26, string:'r'; 27, pair; 27, 28; 27, 29; 28, string:u'FLAPPING'; 29, string:'f'; 30, pair; 30, 31; 30, 32; 31, string:u'DOWNTIME'; 32, string:'s'; 33, pair; 33, 34; 33, 35; 34, string:u'DOWN'; 35, string:'d'; 36, pair; 36, 37; 36, 38; 37, string:u'UNREACHABLE'; 38, string:'u'; 39, pair; 39, 40; 39, 41; 40, string:u'OK'; 41, string:'o'; 42, pair; 42, 43; 42, 44; 43, string:u'UP'; 44, string:'o'; 45, if_statement; 45, 46; 45, 50; 46, not_operator; 46, 47; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:time_based; 50, block; 50, 51; 51, return_statement; 51, 52; 52, None; 53, if_statement; 53, 54; 53, 65; 54, boolean_operator:and; 54, 55; 54, 58; 55, comparison_operator:in; 55, 56; 55, 57; 56, identifier:status; 57, identifier:short_states; 58, comparison_operator:not; 58, 59; 58, 62; 59, subscript; 59, 60; 59, 61; 60, identifier:short_states; 61, identifier:status; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:escalation_options; 65, block; 65, 66; 66, return_statement; 66, 67; 67, None; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:start; 71, binary_operator:+; 71, 72; 71, 77; 72, binary_operator:*; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:first_notification_time; 76, identifier:interval; 77, identifier:creation_time; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:>; 79, 80; 79, 81; 80, identifier:start; 81, identifier:t_wished; 82, block; 82, 83; 83, return_statement; 83, 84; 84, None; 85, if_statement; 85, 86; 85, 97; 86, boolean_operator:and; 86, 87; 86, 90; 87, comparison_operator:is; 87, 88; 87, 89; 88, identifier:escal_period; 89, None; 90, not_operator; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:escal_period; 94, identifier:is_time_valid; 95, argument_list; 95, 96; 96, identifier:start; 97, block; 97, 98; 98, return_statement; 98, 99; 99, None; 100, return_statement; 100, 101; 101, identifier:start | def get_next_notif_time(self, t_wished, status, creation_time, interval, escal_period):
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 not self.time_based:
return None
if status in short_states and short_states[status] not in self.escalation_options:
return None
start = self.first_notification_time * interval + creation_time
if start > t_wished:
return None
if escal_period is not None and not escal_period.is_time_valid(start):
return None
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; 7, for_statement; 7, 8; 7, 9; 7, 10; 8, identifier:escalation; 9, identifier:self; 10, block; 10, 11; 10, 20; 10, 32; 10, 48; 11, if_statement; 11, 12; 11, 18; 12, not_operator; 12, 13; 13, call; 13, 14; 13, 15; 14, identifier:hasattr; 15, argument_list; 15, 16; 15, 17; 16, identifier:escalation; 17, string:'host_name'; 18, block; 18, 19; 19, continue_statement; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 25; 22, pattern_list; 22, 23; 22, 24; 23, identifier:es_hname; 24, identifier:sdesc; 25, expression_list; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:escalation; 28, identifier:host_name; 29, attribute; 29, 30; 29, 31; 30, identifier:escalation; 31, identifier:service_description; 32, if_statement; 32, 33; 32, 46; 33, boolean_operator:or; 33, 34; 33, 40; 34, not_operator; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:es_hname; 38, identifier:strip; 39, argument_list; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:sdesc; 44, identifier:strip; 45, argument_list; 46, block; 46, 47; 47, continue_statement; 48, for_statement; 48, 49; 48, 50; 48, 59; 49, identifier:hname; 50, call; 50, 51; 50, 52; 51, identifier:strip_and_uniq; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:es_hname; 56, identifier:split; 57, argument_list; 57, 58; 58, string:','; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 68; 60, 108; 61, comparison_operator:==; 61, 62; 61, 67; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:sdesc; 65, identifier:strip; 66, argument_list; 67, string:'*'; 68, block; 68, 69; 68, 78; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:slist; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:services; 75, identifier:find_srvs_by_hostname; 76, argument_list; 76, 77; 77, identifier:hname; 78, if_statement; 78, 79; 78, 82; 79, comparison_operator:is; 79, 80; 79, 81; 80, identifier:slist; 81, None; 82, block; 82, 83; 82, 93; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:slist; 86, list_comprehension; 86, 87; 86, 90; 87, subscript; 87, 88; 87, 89; 88, identifier:services; 89, identifier:serv; 90, for_in_clause; 90, 91; 90, 92; 91, identifier:serv; 92, identifier:slist; 93, for_statement; 93, 94; 93, 95; 93, 96; 94, identifier:serv; 95, identifier:slist; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 104; 99, attribute; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:serv; 102, identifier:escalations; 103, identifier:append; 104, argument_list; 104, 105; 105, attribute; 105, 106; 105, 107; 106, identifier:escalation; 107, identifier:uuid; 108, else_clause; 108, 109; 109, block; 109, 110; 110, for_statement; 110, 111; 110, 112; 110, 121; 111, identifier:sname; 112, call; 112, 113; 112, 114; 113, identifier:strip_and_uniq; 114, argument_list; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:sdesc; 118, identifier:split; 119, argument_list; 119, 120; 120, string:','; 121, block; 121, 122; 121, 132; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:serv; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:services; 128, identifier:find_srv_by_name_and_hostname; 129, argument_list; 129, 130; 129, 131; 130, identifier:hname; 131, identifier:sname; 132, if_statement; 132, 133; 132, 136; 133, comparison_operator:is; 133, 134; 133, 135; 134, identifier:serv; 135, None; 136, block; 136, 137; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 144; 139, attribute; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:serv; 142, identifier:escalations; 143, identifier:append; 144, argument_list; 144, 145; 145, attribute; 145, 146; 145, 147; 146, identifier:escalation; 147, identifier:uuid | def linkify_es_by_s(self, services):
for escalation in self:
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; 2, function_name:get_contacts_by_explosion; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:contactgroups; 6, block; 6, 7; 6, 13; 6, 43; 6, 49; 6, 57; 6, 100; 6, 111; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:already_exploded; 12, True; 13, if_statement; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:rec_tag; 17, block; 17, 18; 17, 30; 17, 41; 18, expression_statement; 18, 19; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:logger; 22, identifier:error; 23, argument_list; 23, 24; 23, 25; 24, string:"[contactgroup::%s] got a loop in contactgroup definition"; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:get_name; 29, argument_list; 30, if_statement; 30, 31; 30, 36; 31, call; 31, 32; 31, 33; 32, identifier:hasattr; 33, argument_list; 33, 34; 33, 35; 34, identifier:self; 35, string:'members'; 36, block; 36, 37; 37, return_statement; 37, 38; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:members; 41, return_statement; 41, 42; 42, string:''; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:rec_tag; 48, True; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:cg_mbrs; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:get_contactgroup_members; 56, argument_list; 57, for_statement; 57, 58; 57, 59; 57, 60; 58, identifier:cg_mbr; 59, identifier:cg_mbrs; 60, block; 60, 61; 60, 74; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:contactgroup; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:contactgroups; 67, identifier:find_by_name; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:cg_mbr; 72, identifier:strip; 73, argument_list; 74, if_statement; 74, 75; 74, 78; 75, comparison_operator:is; 75, 76; 75, 77; 76, identifier:contactgroup; 77, None; 78, block; 78, 79; 78, 88; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:value; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:contactgroup; 85, identifier:get_contacts_by_explosion; 86, argument_list; 86, 87; 87, identifier:contactgroups; 88, if_statement; 88, 89; 88, 92; 89, comparison_operator:is; 89, 90; 89, 91; 90, identifier:value; 91, None; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:self; 97, identifier:add_members; 98, argument_list; 98, 99; 99, identifier:value; 100, if_statement; 100, 101; 100, 106; 101, call; 101, 102; 101, 103; 102, identifier:hasattr; 103, argument_list; 103, 104; 103, 105; 104, identifier:self; 105, string:'members'; 106, block; 106, 107; 107, return_statement; 107, 108; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:members; 111, return_statement; 111, 112; 112, string:'' | def get_contacts_by_explosion(self, contactgroups):
self.already_exploded = True
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 ''
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; 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, block; 12, 13; 12, 17; 12, 23; 12, 329; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:now; 16, identifier:when; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:cls; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:__class__; 23, if_statement; 23, 24; 23, 37; 24, boolean_operator:and; 24, 25; 24, 33; 25, boolean_operator:and; 25, 26; 25, 30; 26, not_operator; 26, 27; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:in_checking; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:freshness_threshold; 33, not_operator; 33, 34; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:freshness_expired; 37, block; 37, 38; 37, 59; 37, 74; 38, if_statement; 38, 39; 38, 46; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:getenv; 43, argument_list; 43, 44; 43, 45; 44, string:'ALIGNAK_LOG_CHECKS'; 45, None; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:logger; 51, identifier:info; 52, argument_list; 52, 53; 52, 54; 53, string:"--ALC-- -> checking freshness for: %s"; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:get_full_name; 58, argument_list; 59, if_statement; 59, 60; 59, 64; 60, not_operator; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:last_state_update; 64, block; 64, 65; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:last_state_update; 70, call; 70, 71; 70, 72; 71, identifier:int; 72, argument_list; 72, 73; 73, identifier:now; 74, if_statement; 74, 75; 74, 90; 75, comparison_operator:<; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:last_state_update; 79, binary_operator:-; 79, 80; 79, 81; 79, 82; 80, identifier:now; 81, line_continuation:\; 82, parenthesized_expression; 82, 83; 83, binary_operator:+; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:freshness_threshold; 87, attribute; 87, 88; 87, 89; 88, identifier:cls; 89, identifier:additional_freshness_latency; 90, block; 90, 91; 90, 99; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:timeperiod; 94, subscript; 94, 95; 94, 96; 95, identifier:timeperiods; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:check_period; 99, if_statement; 99, 100; 99, 110; 99, 313; 100, boolean_operator:or; 100, 101; 100, 104; 101, comparison_operator:is; 101, 102; 101, 103; 102, identifier:timeperiod; 103, None; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:timeperiod; 107, identifier:is_time_valid; 108, argument_list; 108, 109; 109, identifier:now; 110, block; 110, 111; 110, 126; 110, 140; 110, 146; 110, 156; 110, 180; 110, 311; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:chk; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:launch_check; 118, argument_list; 118, 119; 118, 120; 118, 121; 118, 122; 118, 123; 118, 124; 118, 125; 119, identifier:now; 120, identifier:hosts; 121, identifier:services; 122, identifier:timeperiods; 123, identifier:macromodulations; 124, identifier:checkmodulations; 125, identifier:checks; 126, if_statement; 126, 127; 126, 129; 127, not_operator; 127, 128; 128, identifier:chk; 129, block; 129, 130; 129, 138; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:logger; 134, identifier:warning; 135, argument_list; 135, 136; 135, 137; 136, string:"No raised freshness check for: %s"; 137, identifier:self; 138, return_statement; 138, 139; 139, None; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:chk; 144, identifier:freshness_expiry_check; 145, True; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:chk; 150, identifier:check_time; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:time; 154, identifier:time; 155, argument_list; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:chk; 160, identifier:output; 161, binary_operator:%; 161, 162; 161, 163; 162, string:"Freshness period expired: %s"; 163, parenthesized_expression; 163, 164; 164, call; 164, 165; 164, 178; 165, attribute; 165, 166; 165, 177; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:datetime; 169, identifier:utcfromtimestamp; 170, argument_list; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:int; 173, argument_list; 173, 174; 174, attribute; 174, 175; 174, 176; 175, identifier:chk; 176, identifier:check_time; 177, identifier:strftime; 178, argument_list; 178, 179; 179, string:"%Y-%m-%d %H:%M:%S %Z"; 180, if_statement; 180, 181; 180, 186; 180, 236; 181, comparison_operator:==; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:self; 184, identifier:my_type; 185, string:'host'; 186, block; 186, 187; 187, if_statement; 187, 188; 187, 193; 187, 200; 187, 213; 187, 228; 188, comparison_operator:==; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:self; 191, identifier:freshness_state; 192, string:'o'; 193, block; 193, 194; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:chk; 198, identifier:exit_status; 199, integer:0; 200, elif_clause; 200, 201; 200, 206; 201, comparison_operator:==; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:self; 204, identifier:freshness_state; 205, string:'d'; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:chk; 211, identifier:exit_status; 212, integer:2; 213, elif_clause; 213, 214; 213, 221; 214, comparison_operator:in; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:freshness_state; 218, list:['u', 'x']; 218, 219; 218, 220; 219, string:'u'; 220, string:'x'; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:chk; 226, identifier:exit_status; 227, integer:4; 228, else_clause; 228, 229; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:chk; 234, identifier:exit_status; 235, integer:3; 236, else_clause; 236, 237; 237, block; 237, 238; 238, if_statement; 238, 239; 238, 244; 238, 251; 238, 264; 238, 277; 238, 290; 238, 303; 239, comparison_operator:==; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:freshness_state; 243, string:'o'; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:chk; 249, identifier:exit_status; 250, integer:0; 251, elif_clause; 251, 252; 251, 257; 252, comparison_operator:==; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:freshness_state; 256, string:'w'; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:chk; 262, identifier:exit_status; 263, integer:1; 264, elif_clause; 264, 265; 264, 270; 265, comparison_operator:==; 265, 266; 265, 269; 266, attribute; 266, 267; 266, 268; 267, identifier:self; 268, identifier:freshness_state; 269, string:'c'; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:chk; 275, identifier:exit_status; 276, integer:2; 277, elif_clause; 277, 278; 277, 283; 278, comparison_operator:==; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:freshness_state; 282, string:'u'; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 289; 286, attribute; 286, 287; 286, 288; 287, identifier:chk; 288, identifier:exit_status; 289, integer:3; 290, elif_clause; 290, 291; 290, 296; 291, comparison_operator:==; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, identifier:self; 294, identifier:freshness_state; 295, string:'x'; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:chk; 301, identifier:exit_status; 302, integer:4; 303, else_clause; 303, 304; 304, block; 304, 305; 305, expression_statement; 305, 306; 306, assignment; 306, 307; 306, 310; 307, attribute; 307, 308; 307, 309; 308, identifier:chk; 309, identifier:exit_status; 310, integer:3; 311, return_statement; 311, 312; 312, identifier:chk; 313, else_clause; 313, 314; 314, block; 314, 315; 315, expression_statement; 315, 316; 316, call; 316, 317; 316, 320; 317, attribute; 317, 318; 317, 319; 318, identifier:logger; 319, identifier:debug; 320, argument_list; 320, 321; 320, 324; 321, concatenated_string; 321, 322; 321, 323; 322, string:"Ignored freshness check for %s, because "; 323, string:"we are not in the check period."; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:self; 327, identifier:get_full_name; 328, argument_list; 329, return_statement; 329, 330; 330, None | def do_check_freshness(self, hosts, services, timeperiods, macromodulations, checkmodulations,
checks, when):
now = when
cls = self.__class__
if not self.in_checking and self.freshness_threshold and not self.freshness_expired:
if os.getenv('ALIGNAK_LOG_CHECKS', None):
logger.info("--ALC-- -> checking freshness for: %s", self.get_full_name())
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):
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, 26; 9, 30; 9, 83; 9, 143; 10, if_statement; 10, 11; 10, 17; 11, comparison_operator:==; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:my_own_business_impact; 15, unary_operator:-; 15, 16; 16, integer:1; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:my_own_business_impact; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:business_impact; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:in_modulation; 29, False; 30, for_statement; 30, 31; 30, 32; 30, 35; 31, identifier:bi_modulation_id; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:business_impact_modulations; 35, block; 35, 36; 35, 42; 35, 50; 35, 58; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:bi_modulation; 39, subscript; 39, 40; 39, 41; 40, identifier:bi_modulations; 41, identifier:bi_modulation_id; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:now; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:time; 48, identifier:time; 49, argument_list; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:period; 53, subscript; 53, 54; 53, 55; 54, identifier:timeperiods; 55, attribute; 55, 56; 55, 57; 56, identifier:bi_modulation; 57, identifier:modulation_period; 58, if_statement; 58, 59; 58, 69; 59, boolean_operator:or; 59, 60; 59, 63; 60, comparison_operator:is; 60, 61; 60, 62; 61, identifier:period; 62, None; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:period; 66, identifier:is_time_valid; 67, argument_list; 67, 68; 68, identifier:now; 69, block; 69, 70; 69, 78; 69, 82; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:business_impact; 75, attribute; 75, 76; 75, 77; 76, identifier:bi_modulation; 77, identifier:business_impact; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:in_modulation; 81, True; 82, break_statement; 83, if_statement; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:impacts; 87, block; 87, 88; 87, 106; 87, 127; 87, 142; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:bp_impacts; 91, list_comprehension; 91, 92; 91, 97; 91, 102; 92, attribute; 92, 93; 92, 96; 93, subscript; 93, 94; 93, 95; 94, identifier:hosts; 95, identifier:elem; 96, identifier:business_impact; 97, for_in_clause; 97, 98; 97, 99; 98, identifier:elem; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:impacts; 102, if_clause; 102, 103; 103, comparison_operator:in; 103, 104; 103, 105; 104, identifier:elem; 105, identifier:hosts; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:bp_impacts; 110, identifier:extend; 111, argument_list; 111, 112; 112, list_comprehension; 112, 113; 112, 118; 112, 123; 113, attribute; 113, 114; 113, 117; 114, subscript; 114, 115; 114, 116; 115, identifier:services; 116, identifier:elem; 117, identifier:business_impact; 118, for_in_clause; 118, 119; 118, 120; 119, identifier:elem; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:impacts; 123, if_clause; 123, 124; 124, comparison_operator:in; 124, 125; 124, 126; 125, identifier:elem; 126, identifier:services; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:business_impact; 132, call; 132, 133; 132, 134; 133, identifier:max; 134, argument_list; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:business_impact; 138, call; 138, 139; 138, 140; 139, identifier:max; 140, argument_list; 140, 141; 141, identifier:bp_impacts; 142, return_statement; 143, if_statement; 143, 144; 143, 153; 144, boolean_operator:and; 144, 145; 144, 151; 145, comparison_operator:!=; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:my_own_business_impact; 149, unary_operator:-; 149, 150; 150, integer:1; 151, not_operator; 151, 152; 152, identifier:in_modulation; 153, block; 153, 154; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:business_impact; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:my_own_business_impact | def update_business_impact_value(self, hosts, services, timeperiods, bi_modulations):
if self.my_own_business_impact == -1:
self.my_own_business_impact = self.business_impact
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
break
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 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; 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, block; 10, 11; 10, 22; 10, 30; 10, 36; 10, 42; 10, 46; 10, 205; 11, if_statement; 11, 12; 11, 19; 12, comparison_operator:in; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:prob; 15, identifier:uuid; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:source_problems; 19, block; 19, 20; 20, return_statement; 20, 21; 21, list:[]; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:now; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:time; 28, identifier:time; 29, argument_list; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:was_an_impact; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:is_impact; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:is_impact; 41, True; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:impacts; 45, list:[]; 46, if_statement; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:is_impact; 50, block; 50, 51; 50, 59; 50, 74; 50, 84; 50, 93; 50, 113; 50, 192; 51, expression_statement; 51, 52; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:logger; 55, identifier:debug; 56, argument_list; 56, 57; 56, 58; 57, string:"I am impacted: %s"; 58, identifier:self; 59, if_statement; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:is_problem; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:no_more_a_problem; 69, argument_list; 69, 70; 69, 71; 69, 72; 69, 73; 70, identifier:hosts; 71, identifier:services; 72, identifier:timeperiods; 73, identifier:bi_modulations; 74, if_statement; 74, 75; 74, 77; 75, not_operator; 75, 76; 76, identifier:was_an_impact; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:set_impact_state; 83, argument_list; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:impacts; 88, identifier:append; 89, argument_list; 89, 90; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:uuid; 93, if_statement; 93, 94; 93, 101; 94, comparison_operator:not; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:prob; 97, identifier:uuid; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:source_problems; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:source_problems; 108, identifier:append; 109, argument_list; 109, 110; 110, attribute; 110, 111; 110, 112; 111, identifier:prob; 112, identifier:uuid; 113, for_statement; 113, 114; 113, 119; 113, 122; 114, tuple_pattern; 114, 115; 114, 116; 114, 117; 114, 118; 115, identifier:impacted_item_id; 116, identifier:status; 117, identifier:timeperiod_id; 118, identifier:_; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:act_depend_of_me; 122, block; 122, 123; 122, 142; 122, 148; 123, if_statement; 123, 124; 123, 127; 123, 134; 124, comparison_operator:in; 124, 125; 124, 126; 125, identifier:impacted_item_id; 126, identifier:hosts; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:impact; 131, subscript; 131, 132; 131, 133; 132, identifier:hosts; 133, identifier:impacted_item_id; 134, else_clause; 134, 135; 135, block; 135, 136; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:impact; 139, subscript; 139, 140; 139, 141; 140, identifier:services; 141, identifier:impacted_item_id; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:timeperiod; 145, subscript; 145, 146; 145, 147; 146, identifier:timeperiods; 147, identifier:timeperiod_id; 148, for_statement; 148, 149; 148, 150; 148, 151; 149, identifier:stat; 150, identifier:status; 151, block; 151, 152; 152, if_statement; 152, 153; 152, 159; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:is_state; 157, argument_list; 157, 158; 158, identifier:stat; 159, block; 159, 160; 160, if_statement; 160, 161; 160, 171; 161, boolean_operator:or; 161, 162; 161, 165; 162, comparison_operator:is; 162, 163; 162, 164; 163, identifier:timeperiod; 164, None; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:timeperiod; 168, identifier:is_time_valid; 169, argument_list; 169, 170; 170, identifier:now; 171, block; 171, 172; 171, 185; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:new_impacts; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:impact; 178, identifier:register_a_problem; 179, argument_list; 179, 180; 179, 181; 179, 182; 179, 183; 179, 184; 180, identifier:prob; 181, identifier:hosts; 182, identifier:services; 183, identifier:timeperiods; 184, identifier:bi_modulations; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:impacts; 189, identifier:extend; 190, argument_list; 190, 191; 191, identifier:new_impacts; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 199; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:broks; 198, identifier:append; 199, argument_list; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:get_update_status_brok; 204, argument_list; 205, return_statement; 205, 206; 206, identifier:impacts | def register_a_problem(self, prob, hosts, services, timeperiods, bi_modulations):
if prob.uuid in self.source_problems:
return []
now = time.time()
was_an_impact = self.is_impact
self.is_impact = True
impacts = []
if self.is_impact:
logger.debug("I am impacted: %s", self)
if self.is_problem:
self.no_more_a_problem(hosts, services, timeperiods, bi_modulations)
if not was_an_impact:
self.set_impact_state()
impacts.append(self.uuid)
if prob.uuid not in self.source_problems:
self.source_problems.append(prob.uuid)
for (impacted_item_id, status, timeperiod_id, _) in self.act_depend_of_me:
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):
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)
self.broks.append(self.get_update_status_brok())
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, 12; 7, 86; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:enable_action; 11, False; 12, for_statement; 12, 13; 12, 18; 12, 21; 13, tuple_pattern; 13, 14; 13, 15; 13, 16; 13, 17; 14, identifier:dep_id; 15, identifier:status; 16, identifier:_; 17, identifier:_; 18, attribute; 18, 19; 18, 20; 19, identifier:self; 20, identifier:act_depend_of; 21, block; 21, 22; 22, if_statement; 22, 23; 22, 26; 22, 31; 23, comparison_operator:in; 23, 24; 23, 25; 24, string:'n'; 25, identifier:status; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:enable_action; 30, True; 31, else_clause; 31, 32; 32, block; 32, 33; 32, 52; 32, 56; 32, 69; 32, 78; 33, if_statement; 33, 34; 33, 37; 33, 44; 34, comparison_operator:in; 34, 35; 34, 36; 35, identifier:dep_id; 36, identifier:hosts; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:dep; 41, subscript; 41, 42; 41, 43; 42, identifier:hosts; 43, identifier:dep_id; 44, else_clause; 44, 45; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:dep; 49, subscript; 49, 50; 49, 51; 50, identifier:services; 51, identifier:dep_id; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:p_is_down; 55, False; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:dep_match; 59, list_comprehension; 59, 60; 59, 66; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:dep; 63, identifier:is_state; 64, argument_list; 64, 65; 65, identifier:stat; 66, for_in_clause; 66, 67; 66, 68; 67, identifier:stat; 68, identifier:status; 69, if_statement; 69, 70; 69, 73; 70, comparison_operator:in; 70, 71; 70, 72; 71, True; 72, identifier:dep_match; 73, block; 73, 74; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:p_is_down; 77, True; 78, if_statement; 78, 79; 78, 81; 79, not_operator; 79, 80; 80, identifier:p_is_down; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:enable_action; 85, True; 86, return_statement; 86, 87; 87, identifier:enable_action | def is_enable_action_dependent(self, hosts, services):
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]
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, 14; 5, 33; 5, 101; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:was_in_hard_unknown_reach_phase; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:in_hard_unknown_reach_phase; 14, if_statement; 14, 15; 14, 26; 15, boolean_operator:or; 15, 16; 15, 21; 16, comparison_operator:!=; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:state_type; 20, string:'HARD'; 21, comparison_operator:!=; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:last_state_type; 25, string:'HARD'; 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:in_hard_unknown_reach_phase; 32, False; 33, if_statement; 33, 34; 33, 38; 33, 80; 34, not_operator; 34, 35; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:in_hard_unknown_reach_phase; 38, block; 38, 39; 39, if_statement; 39, 40; 39, 64; 40, boolean_operator:or; 40, 41; 40, 52; 40, 53; 41, boolean_operator:and; 41, 42; 41, 47; 42, comparison_operator:==; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:state; 46, string:'UNKNOWN'; 47, comparison_operator:!=; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:last_state; 51, string:'UNKNOWN'; 52, line_continuation:\; 53, boolean_operator:and; 53, 54; 53, 59; 54, comparison_operator:==; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:state; 58, string:'UNREACHABLE'; 59, comparison_operator:!=; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:last_state; 63, string:'UNREACHABLE'; 64, block; 64, 65; 64, 71; 64, 79; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:in_hard_unknown_reach_phase; 70, True; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:state_before_hard_unknown_reach_phase; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:last_state; 79, return_statement; 80, else_clause; 80, 81; 81, block; 81, 82; 82, if_statement; 82, 83; 82, 94; 83, boolean_operator:and; 83, 84; 83, 89; 84, comparison_operator:!=; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:state; 88, string:'UNKNOWN'; 89, comparison_operator:!=; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:state; 93, string:'UNREACHABLE'; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:in_hard_unknown_reach_phase; 100, False; 101, if_statement; 101, 102; 101, 110; 102, boolean_operator:and; 102, 103; 102, 107; 103, not_operator; 103, 104; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:in_hard_unknown_reach_phase; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:was_in_hard_unknown_reach_phase; 110, block; 110, 111; 111, if_statement; 111, 112; 111, 119; 112, comparison_operator:!=; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:state; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:state_before_hard_unknown_reach_phase; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:was_in_hard_unknown_reach_phase; 125, False | def update_hard_unknown_phase_state(self):
self.was_in_hard_unknown_reach_phase = self.in_hard_unknown_reach_phase
if self.state_type != 'HARD' or self.last_state_type != 'HARD':
self.in_hard_unknown_reach_phase = False
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
self.state_before_hard_unknown_reach_phase = self.last_state
return
else:
if self.state != 'UNKNOWN' and self.state != 'UNREACHABLE':
self.in_hard_unknown_reach_phase = False
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; 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, block; 8, 9; 8, 13; 8, 21; 8, 27; 8, 33; 8, 45; 8, 107; 8, 119; 8, 134; 8, 138; 8, 144; 8, 152; 8, 214; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:res; 12, None; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:now; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:time; 19, identifier:time; 20, argument_list; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:cls; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:__class__; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:notification_interval; 30, attribute; 30, 31; 30, 32; 31, identifier:self; 32, identifier:notification_interval; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:in_notif_time; 36, binary_operator:-; 36, 37; 36, 42; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:time; 40, identifier:time; 41, argument_list; 42, attribute; 42, 43; 42, 44; 43, identifier:notif; 44, identifier:creation_time; 45, for_statement; 45, 46; 45, 47; 45, 50; 46, identifier:escalation_id; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:escalations; 50, block; 50, 51; 50, 57; 50, 65; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:escalation; 54, subscript; 54, 55; 54, 56; 55, identifier:escalations; 56, identifier:escalation_id; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:escalation_period; 60, subscript; 60, 61; 60, 62; 61, identifier:timeperiods; 62, attribute; 62, 63; 62, 64; 63, identifier:escalation; 64, identifier:escalation_period; 65, if_statement; 65, 66; 65, 85; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:escalation; 69, identifier:is_eligible; 70, argument_list; 70, 71; 70, 74; 70, 77; 70, 80; 70, 81; 70, 84; 71, attribute; 71, 72; 71, 73; 72, identifier:notif; 73, identifier:t_to_go; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:state; 77, attribute; 77, 78; 77, 79; 78, identifier:notif; 79, identifier:notif_nb; 80, identifier:in_notif_time; 81, attribute; 81, 82; 81, 83; 82, identifier:cls; 83, identifier:interval_length; 84, identifier:escalation_period; 85, block; 85, 86; 86, if_statement; 86, 87; 86, 100; 87, boolean_operator:and; 87, 88; 87, 94; 87, 95; 88, comparison_operator:!=; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:escalation; 91, identifier:notification_interval; 92, unary_operator:-; 92, 93; 93, integer:1; 94, line_continuation:\; 95, comparison_operator:<; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:escalation; 98, identifier:notification_interval; 99, identifier:notification_interval; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:notification_interval; 104, attribute; 104, 105; 104, 106; 105, identifier:escalation; 106, identifier:notification_interval; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:std_time; 110, binary_operator:+; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:notif; 113, identifier:t_to_go; 114, binary_operator:*; 114, 115; 114, 116; 115, identifier:notification_interval; 116, attribute; 116, 117; 116, 118; 117, identifier:cls; 118, identifier:interval_length; 119, if_statement; 119, 120; 119, 123; 120, comparison_operator:<; 120, 121; 120, 122; 121, identifier:std_time; 122, identifier:now; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:std_time; 127, binary_operator:+; 127, 128; 127, 129; 128, identifier:now; 129, binary_operator:*; 129, 130; 129, 131; 130, identifier:notification_interval; 131, attribute; 131, 132; 131, 133; 132, identifier:cls; 133, identifier:interval_length; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:res; 137, identifier:std_time; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:creation_time; 141, attribute; 141, 142; 141, 143; 142, identifier:notif; 143, identifier:creation_time; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:in_notif_time; 147, binary_operator:-; 147, 148; 147, 149; 148, identifier:now; 149, attribute; 149, 150; 149, 151; 150, identifier:notif; 151, identifier:creation_time; 152, for_statement; 152, 153; 152, 154; 152, 157; 153, identifier:escalation_id; 154, attribute; 154, 155; 154, 156; 155, identifier:self; 156, identifier:escalations; 157, block; 157, 158; 157, 164; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:escalation; 161, subscript; 161, 162; 161, 163; 162, identifier:escalations; 163, identifier:escalation_id; 164, if_statement; 164, 165; 164, 174; 165, comparison_operator:not; 165, 166; 165, 171; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:escalation; 169, identifier:get_name; 170, argument_list; 171, attribute; 171, 172; 171, 173; 172, identifier:notif; 173, identifier:already_start_escalations; 174, block; 174, 175; 174, 183; 174, 200; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:escalation_period; 178, subscript; 178, 179; 178, 180; 179, identifier:timeperiods; 180, attribute; 180, 181; 180, 182; 181, identifier:escalation; 182, identifier:escalation_period; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:next_t; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:escalation; 189, identifier:get_next_notif_time; 190, argument_list; 190, 191; 190, 192; 190, 195; 190, 196; 190, 199; 191, identifier:std_time; 192, attribute; 192, 193; 192, 194; 193, identifier:self; 194, identifier:state; 195, identifier:creation_time; 196, attribute; 196, 197; 196, 198; 197, identifier:cls; 198, identifier:interval_length; 199, identifier:escalation_period; 200, if_statement; 200, 201; 200, 209; 201, boolean_operator:and; 201, 202; 201, 205; 202, comparison_operator:is; 202, 203; 202, 204; 203, identifier:next_t; 204, None; 205, comparison_operator:<; 205, 206; 205, 207; 205, 208; 206, identifier:now; 207, identifier:next_t; 208, identifier:res; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:res; 213, identifier:next_t; 214, return_statement; 214, 215; 215, identifier:res | def get_next_notification_time(self, notif, escalations, timeperiods):
res = None
now = time.time()
cls = self.__class__
notification_interval = self.notification_interval
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
std_time = notif.t_to_go + notification_interval * cls.interval_length
if std_time < now:
std_time = now + notification_interval * cls.interval_length
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 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 next_t is not None and now < next_t < res:
res = next_t
return res |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 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, block; 9, 10; 9, 19; 9, 32; 9, 38; 9, 44; 9, 50; 9, 60; 9, 76; 9, 80; 9, 84; 9, 94; 9, 153; 9, 165; 9, 176; 9, 185; 9, 197; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:got_business_rule; 13, call; 13, 14; 13, 15; 14, identifier:getattr; 15, argument_list; 15, 16; 15, 17; 15, 18; 16, identifier:self; 17, string:'got_business_rule'; 18, False; 19, if_statement; 19, 20; 19, 29; 20, boolean_operator:or; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:got_business_rule; 23, False; 24, comparison_operator:is; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:business_rule; 28, None; 29, block; 29, 30; 30, return_statement; 30, 31; 31, string:""; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:output_template; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:business_rule_output_template; 38, if_statement; 38, 39; 38, 41; 39, not_operator; 39, 40; 40, identifier:output_template; 41, block; 41, 42; 42, return_statement; 42, 43; 43, string:""; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:macroresolver; 47, call; 47, 48; 47, 49; 48, identifier:MacroResolver; 49, argument_list; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:elts; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:re; 56, identifier:findall; 57, argument_list; 57, 58; 57, 59; 58, string:r"\$\((.*)\)\$"; 59, identifier:output_template; 60, if_statement; 60, 61; 60, 63; 60, 68; 61, not_operator; 61, 62; 62, identifier:elts; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:child_template_string; 67, string:""; 68, else_clause; 68, 69; 69, block; 69, 70; 70, expression_statement; 70, 71; 71, assignment; 71, 72; 71, 73; 72, identifier:child_template_string; 73, subscript; 73, 74; 73, 75; 74, identifier:elts; 75, integer:0; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:children_output; 79, string:""; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:ok_count; 83, integer:0; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:items; 87, call; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:business_rule; 92, identifier:list_all_elements; 93, argument_list; 94, for_statement; 94, 95; 94, 96; 94, 97; 95, identifier:item_uuid; 96, identifier:items; 97, block; 97, 98; 97, 120; 97, 132; 97, 141; 98, if_statement; 98, 99; 98, 102; 98, 109; 99, comparison_operator:in; 99, 100; 99, 101; 100, identifier:item_uuid; 101, identifier:hosts; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:item; 106, subscript; 106, 107; 106, 108; 107, identifier:hosts; 108, identifier:item_uuid; 109, elif_clause; 109, 110; 109, 113; 110, comparison_operator:in; 110, 111; 110, 112; 111, identifier:item_uuid; 112, identifier:services; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:item; 117, subscript; 117, 118; 117, 119; 118, identifier:services; 119, identifier:item_uuid; 120, if_statement; 120, 121; 120, 126; 121, comparison_operator:==; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:item; 124, identifier:last_hard_state_id; 125, integer:0; 126, block; 126, 127; 126, 131; 127, expression_statement; 127, 128; 128, augmented_assignment:+=; 128, 129; 128, 130; 129, identifier:ok_count; 130, integer:1; 131, continue_statement; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:data; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:item; 138, identifier:get_data_for_checks; 139, argument_list; 139, 140; 140, identifier:hosts; 141, expression_statement; 141, 142; 142, augmented_assignment:+=; 142, 143; 142, 144; 143, identifier:children_output; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:macroresolver; 147, identifier:resolve_simple_macros_in_string; 148, argument_list; 148, 149; 148, 150; 148, 151; 148, 152; 149, identifier:child_template_string; 150, identifier:data; 151, identifier:macromodulations; 152, identifier:timeperiods; 153, if_statement; 153, 154; 153, 160; 154, comparison_operator:==; 154, 155; 154, 156; 155, identifier:ok_count; 156, call; 156, 157; 156, 158; 157, identifier:len; 158, argument_list; 158, 159; 159, identifier:items; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:children_output; 164, string:"all checks were successful."; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:template_string; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:re; 171, identifier:sub; 172, argument_list; 172, 173; 172, 174; 172, 175; 173, string:r"\$\(.*\)\$"; 174, identifier:children_output; 175, identifier:output_template; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:data; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, identifier:self; 182, identifier:get_data_for_checks; 183, argument_list; 183, 184; 184, identifier:hosts; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:output; 188, call; 188, 189; 188, 192; 189, attribute; 189, 190; 189, 191; 190, identifier:macroresolver; 191, identifier:resolve_simple_macros_in_string; 192, argument_list; 192, 193; 192, 194; 192, 195; 192, 196; 193, identifier:template_string; 194, identifier:data; 195, identifier:macromodulations; 196, identifier:timeperiods; 197, return_statement; 197, 198; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:output; 201, identifier:strip; 202, argument_list | def get_business_rule_output(self, hosts, services, macromodulations, timeperiods):
got_business_rule = getattr(self, 'got_business_rule', False)
if got_business_rule is False or self.business_rule is None:
return ""
output_template = self.business_rule_output_template
if not output_template:
return ""
macroresolver = MacroResolver()
elts = re.findall(r"\$\((.*)\)\$", output_template)
if not elts:
child_template_string = ""
else:
child_template_string = elts[0]
children_output = ""
ok_count = 0
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]
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."
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; 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, block; 7, 8; 7, 12; 7, 93; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:acknowledged; 11, integer:0; 12, for_statement; 12, 13; 12, 14; 12, 17; 13, identifier:src_prob_id; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:source_problems; 17, block; 17, 18; 17, 37; 18, if_statement; 18, 19; 18, 22; 18, 29; 19, comparison_operator:in; 19, 20; 19, 21; 20, identifier:src_prob_id; 21, identifier:hosts; 22, block; 22, 23; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:src_prob; 26, subscript; 26, 27; 26, 28; 27, identifier:hosts; 28, identifier:src_prob_id; 29, else_clause; 29, 30; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:src_prob; 34, subscript; 34, 35; 34, 36; 35, identifier:services; 36, identifier:src_prob_id; 37, if_statement; 37, 38; 37, 43; 38, comparison_operator:!=; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:src_prob; 41, identifier:last_hard_state_id; 42, integer:0; 43, block; 43, 44; 44, if_statement; 44, 45; 44, 48; 44, 53; 45, attribute; 45, 46; 45, 47; 46, identifier:src_prob; 47, identifier:problem_has_been_acknowledged; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, augmented_assignment:+=; 50, 51; 50, 52; 51, identifier:acknowledged; 52, integer:1; 53, elif_clause; 53, 54; 53, 59; 54, comparison_operator:is; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:business_rule_downtime_as_ack; 58, True; 59, block; 59, 60; 60, if_statement; 60, 61; 60, 66; 60, 71; 61, comparison_operator:>; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:src_prob; 64, identifier:scheduled_downtime_depth; 65, integer:0; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, augmented_assignment:+=; 68, 69; 68, 70; 69, identifier:acknowledged; 70, integer:1; 71, elif_clause; 71, 72; 71, 88; 72, boolean_operator:and; 72, 73; 72, 78; 72, 79; 73, call; 73, 74; 73, 75; 74, identifier:hasattr; 75, argument_list; 75, 76; 75, 77; 76, identifier:src_prob; 77, string:"host"; 78, line_continuation:\; 79, comparison_operator:>; 79, 80; 79, 87; 80, attribute; 80, 81; 80, 86; 81, subscript; 81, 82; 81, 83; 82, identifier:hosts; 83, attribute; 83, 84; 83, 85; 84, identifier:src_prob; 85, identifier:host; 86, identifier:scheduled_downtime_depth; 87, integer:0; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, augmented_assignment:+=; 90, 91; 90, 92; 91, identifier:acknowledged; 92, integer:1; 93, return_statement; 93, 94; 94, comparison_operator:==; 94, 95; 94, 96; 95, identifier:acknowledged; 96, call; 96, 97; 96, 98; 97, identifier:len; 98, argument_list; 98, 99; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:source_problems | def business_rule_notification_is_blocked(self, hosts, services):
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:
acknowledged += 1
elif self.business_rule_downtime_as_ack is True:
if src_prob.scheduled_downtime_depth > 0:
acknowledged += 1
elif hasattr(src_prob, "host") and \
hosts[src_prob.host].scheduled_downtime_depth > 0:
acknowledged += 1
return acknowledged == len(self.source_problems) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 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, block; 15, 16; 15, 20; 15, 35; 15, 275; 15, 310; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:comm; 19, None; 20, expression_statement; 20, 21; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:logger; 24, identifier:debug; 25, argument_list; 25, 26; 25, 27; 25, 30; 26, string:"Acknowledge requested for %s %s."; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:my_type; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:get_name; 34, argument_list; 35, if_statement; 35, 36; 35, 43; 35, 258; 36, comparison_operator:!=; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:state; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:ok_up; 43, block; 43, 44; 43, 67; 43, 80; 43, 86; 43, 92; 43, 116; 43, 125; 43, 185; 43, 212; 43, 219; 43, 229; 43, 239; 43, 252; 44, if_statement; 44, 45; 44, 52; 45, boolean_operator:and; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:problem_has_been_acknowledged; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:acknowledgement; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:del_comment; 58, argument_list; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:getattr; 61, argument_list; 61, 62; 61, 65; 61, 66; 62, attribute; 62, 63; 62, 64; 63, identifier:self; 64, identifier:acknowledgement; 65, string:'comment_id'; 66, None; 67, if_statement; 67, 68; 67, 69; 68, identifier:notify; 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:create_notifications; 75, argument_list; 75, 76; 75, 77; 75, 78; 75, 79; 76, string:'ACKNOWLEDGEMENT'; 77, identifier:notification_period; 78, identifier:hosts; 79, identifier:services; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:problem_has_been_acknowledged; 85, True; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:sticky; 89, comparison_operator:==; 89, 90; 89, 91; 90, identifier:sticky; 91, integer:2; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:data; 95, dictionary; 95, 96; 95, 101; 95, 104; 95, 107; 95, 110; 95, 113; 96, pair; 96, 97; 96, 98; 97, string:'ref'; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:uuid; 101, pair; 101, 102; 101, 103; 102, string:'sticky'; 103, identifier:sticky; 104, pair; 104, 105; 104, 106; 105, string:'author'; 106, identifier:author; 107, pair; 107, 108; 107, 109; 108, string:'comment'; 109, identifier:comment; 110, pair; 110, 111; 110, 112; 111, string:'end_time'; 112, identifier:end_time; 113, pair; 113, 114; 113, 115; 114, string:'notify'; 115, identifier:notify; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 121; 118, attribute; 118, 119; 118, 120; 119, identifier:self; 120, identifier:acknowledgement; 121, call; 121, 122; 121, 123; 122, identifier:Acknowledge; 123, argument_list; 123, 124; 124, identifier:data; 125, if_statement; 125, 126; 125, 131; 125, 156; 126, comparison_operator:==; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:my_type; 130, string:'host'; 131, block; 131, 132; 131, 136; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:comment_type; 135, integer:1; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:broks; 142, identifier:append; 143, argument_list; 143, 144; 144, call; 144, 145; 144, 150; 145, attribute; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:acknowledgement; 149, identifier:get_raise_brok; 150, argument_list; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:get_name; 155, argument_list; 156, else_clause; 156, 157; 157, block; 157, 158; 157, 162; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:comment_type; 161, integer:2; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:self; 167, identifier:broks; 168, identifier:append; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:self; 174, identifier:acknowledgement; 175, identifier:get_raise_brok; 176, argument_list; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:self; 179, identifier:host_name; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:get_name; 184, argument_list; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:data; 188, dictionary; 188, 189; 188, 192; 188, 195; 188, 198; 188, 201; 188, 204; 188, 207; 189, pair; 189, 190; 189, 191; 190, string:'author'; 191, identifier:author; 192, pair; 192, 193; 192, 194; 193, string:'comment'; 194, identifier:comment; 195, pair; 195, 196; 195, 197; 196, string:'comment_type'; 197, identifier:comment_type; 198, pair; 198, 199; 198, 200; 199, string:'entry_type'; 200, integer:4; 201, pair; 201, 202; 201, 203; 202, string:'source'; 203, integer:0; 204, pair; 204, 205; 204, 206; 205, string:'expires'; 206, False; 207, pair; 207, 208; 207, 209; 208, string:'ref'; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:uuid; 212, expression_statement; 212, 213; 213, assignment; 213, 214; 213, 215; 214, identifier:comm; 215, call; 215, 216; 215, 217; 216, identifier:Comment; 217, argument_list; 217, 218; 218, identifier:data; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 226; 221, attribute; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:acknowledgement; 225, identifier:comment_id; 226, attribute; 226, 227; 226, 228; 227, identifier:comm; 228, identifier:uuid; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 238; 231, subscript; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:self; 234, identifier:comments; 235, attribute; 235, 236; 235, 237; 236, identifier:comm; 237, identifier:uuid; 238, identifier:comm; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 246; 241, attribute; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:self; 244, identifier:broks; 245, identifier:append; 246, argument_list; 246, 247; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:self; 250, identifier:get_update_status_brok; 251, argument_list; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:raise_acknowledge_log_entry; 257, argument_list; 258, else_clause; 258, 259; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:logger; 264, identifier:debug; 265, argument_list; 265, 266; 265, 267; 265, 270; 266, string:"Acknowledge requested for %s %s but element state is OK/UP."; 267, attribute; 267, 268; 267, 269; 268, identifier:self; 269, identifier:my_type; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:self; 273, identifier:get_name; 274, argument_list; 275, if_statement; 275, 276; 275, 281; 276, comparison_operator:==; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:self; 279, identifier:my_type; 280, string:'host'; 281, block; 281, 282; 282, for_statement; 282, 283; 282, 284; 282, 287; 283, identifier:service_uuid; 284, attribute; 284, 285; 284, 286; 285, identifier:self; 286, identifier:services; 287, block; 287, 288; 287, 294; 288, if_statement; 288, 289; 288, 292; 289, comparison_operator:not; 289, 290; 289, 291; 290, identifier:service_uuid; 291, identifier:services; 292, block; 292, 293; 293, continue_statement; 294, expression_statement; 294, 295; 295, call; 295, 296; 295, 301; 296, attribute; 296, 297; 296, 300; 297, subscript; 297, 298; 297, 299; 298, identifier:services; 299, identifier:service_uuid; 300, identifier:acknowledge_problem; 301, argument_list; 301, 302; 301, 303; 301, 304; 301, 305; 301, 306; 301, 307; 301, 308; 301, 309; 302, identifier:notification_period; 303, identifier:hosts; 304, identifier:services; 305, identifier:sticky; 306, identifier:notify; 307, identifier:author; 308, identifier:comment; 309, identifier:end_time; 310, return_statement; 310, 311; 311, identifier:comm | def acknowledge_problem(self, notification_period, hosts, services, sticky, notify, author,
comment, end_time=0):
comm = None
logger.debug("Acknowledge requested for %s %s.", self.my_type, self.get_name())
if self.state != self.ok_up:
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())
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; 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, block; 14, 15; 14, 24; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:logger_; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:logging; 21, identifier:getLogger; 22, argument_list; 22, 23; 23, identifier:ALIGNAK_LOGGER_NAME; 24, for_statement; 24, 25; 24, 26; 24, 29; 24, 117; 25, identifier:handler; 26, attribute; 26, 27; 26, 28; 27, identifier:logger_; 28, identifier:handlers; 29, block; 29, 30; 29, 35; 30, if_statement; 30, 31; 30, 33; 31, not_operator; 31, 32; 32, identifier:process_name; 33, block; 33, 34; 34, break_statement; 35, if_statement; 35, 36; 35, 44; 36, comparison_operator:==; 36, 37; 36, 43; 37, call; 37, 38; 37, 39; 38, identifier:getattr; 39, argument_list; 39, 40; 39, 41; 39, 42; 40, identifier:handler; 41, string:'_name'; 42, None; 43, string:'daemons'; 44, block; 44, 45; 44, 116; 45, for_statement; 45, 46; 45, 47; 45, 50; 46, identifier:hdlr; 47, attribute; 47, 48; 47, 49; 48, identifier:logger_; 49, identifier:handlers; 50, block; 50, 51; 50, 86; 51, if_statement; 51, 52; 51, 59; 52, comparison_operator:in; 52, 53; 52, 54; 53, string:'alignak_tests'; 54, attribute; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:hdlr; 57, identifier:formatter; 58, identifier:_fmt; 59, block; 59, 60; 59, 79; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:formatter; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:logging; 66, identifier:Formatter; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 76; 69, attribute; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:hdlr; 73, identifier:formatter; 74, identifier:_fmt; 75, identifier:replace; 76, argument_list; 76, 77; 76, 78; 77, string:"alignak_tests"; 78, identifier:process_name; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:hdlr; 83, identifier:setFormatter; 84, argument_list; 84, 85; 85, identifier:formatter; 86, if_statement; 86, 87; 86, 99; 87, boolean_operator:and; 87, 88; 87, 94; 88, call; 88, 89; 88, 90; 89, identifier:getattr; 90, argument_list; 90, 91; 90, 92; 90, 93; 91, identifier:hdlr; 92, string:'filename'; 93, None; 94, comparison_operator:in; 94, 95; 94, 96; 95, string:'alignak_tests'; 96, attribute; 96, 97; 96, 98; 97, identifier:hdlr; 98, identifier:filename; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:hdlr; 104, identifier:filename; 105, call; 105, 106; 105, 113; 106, attribute; 106, 107; 106, 112; 107, attribute; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:hdlr; 110, identifier:filename; 111, identifier:_fmt; 112, identifier:replace; 113, argument_list; 113, 114; 113, 115; 114, string:"alignak_tests"; 115, identifier:process_name; 116, break_statement; 117, else_clause; 117, 118; 118, block; 118, 119; 118, 141; 118, 355; 119, if_statement; 119, 120; 119, 132; 120, boolean_operator:or; 120, 121; 120, 123; 121, not_operator; 121, 122; 122, identifier:logger_configuration_file; 123, not_operator; 123, 124; 124, call; 124, 125; 124, 130; 125, attribute; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:os; 128, identifier:path; 129, identifier:exists; 130, argument_list; 130, 131; 131, identifier:logger_configuration_file; 132, block; 132, 133; 132, 140; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:print; 136, argument_list; 136, 137; 137, binary_operator:%; 137, 138; 137, 139; 138, string:"The logger configuration file does not exist: %s"; 139, identifier:logger_configuration_file; 140, return_statement; 141, with_statement; 141, 142; 141, 152; 142, with_clause; 142, 143; 143, with_item; 143, 144; 144, as_pattern; 144, 145; 144, 150; 145, call; 145, 146; 145, 147; 146, identifier:open; 147, argument_list; 147, 148; 147, 149; 148, identifier:logger_configuration_file; 149, string:'rt'; 150, as_pattern_target; 150, 151; 151, identifier:_file; 152, block; 152, 153; 152, 162; 152, 166; 152, 177; 152, 185; 152, 193; 152, 232; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:config; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:json; 159, identifier:load; 160, argument_list; 160, 161; 161, identifier:_file; 162, expression_statement; 162, 163; 163, assignment; 163, 164; 163, 165; 164, identifier:truncate; 165, False; 166, if_statement; 166, 167; 166, 172; 167, boolean_operator:and; 167, 168; 167, 170; 168, not_operator; 168, 169; 169, identifier:process_name; 170, not_operator; 170, 171; 171, identifier:log_dir; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:truncate; 176, True; 177, if_statement; 177, 178; 177, 180; 178, not_operator; 178, 179; 179, identifier:process_name; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:process_name; 184, string:'alignak_tests'; 185, if_statement; 185, 186; 185, 188; 186, not_operator; 186, 187; 187, identifier:log_dir; 188, block; 188, 189; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:log_dir; 192, string:'/tmp'; 193, for_statement; 193, 194; 193, 195; 193, 198; 194, identifier:formatter; 195, subscript; 195, 196; 195, 197; 196, identifier:config; 197, string:'formatters'; 198, block; 198, 199; 198, 209; 199, if_statement; 199, 200; 199, 207; 200, comparison_operator:not; 200, 201; 200, 202; 201, string:'format'; 202, subscript; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:config; 205, string:'formatters'; 206, identifier:formatter; 207, block; 207, 208; 208, continue_statement; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 218; 210, 219; 211, subscript; 211, 212; 211, 217; 212, subscript; 212, 213; 212, 216; 213, subscript; 213, 214; 213, 215; 214, identifier:config; 215, string:'formatters'; 216, identifier:formatter; 217, string:'format'; 218, line_continuation:\; 219, call; 219, 220; 219, 229; 220, attribute; 220, 221; 220, 228; 221, subscript; 221, 222; 221, 227; 222, subscript; 222, 223; 222, 226; 223, subscript; 223, 224; 223, 225; 224, identifier:config; 225, string:'formatters'; 226, identifier:formatter; 227, string:'format'; 228, identifier:replace; 229, argument_list; 229, 230; 229, 231; 230, string:"%(daemon)s"; 231, identifier:process_name; 232, for_statement; 232, 233; 232, 234; 232, 237; 233, identifier:hdlr; 234, subscript; 234, 235; 234, 236; 235, identifier:config; 236, string:'handlers'; 237, block; 237, 238; 237, 248; 237, 290; 237, 313; 238, if_statement; 238, 239; 238, 246; 239, comparison_operator:not; 239, 240; 239, 241; 240, string:'filename'; 241, subscript; 241, 242; 241, 245; 242, subscript; 242, 243; 242, 244; 243, identifier:config; 244, string:'handlers'; 245, identifier:hdlr; 246, block; 246, 247; 247, continue_statement; 248, if_statement; 248, 249; 248, 254; 248, 265; 249, boolean_operator:and; 249, 250; 249, 251; 250, identifier:log_file; 251, comparison_operator:==; 251, 252; 251, 253; 252, identifier:hdlr; 253, string:'daemons'; 254, block; 254, 255; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 264; 257, subscript; 257, 258; 257, 263; 258, subscript; 258, 259; 258, 262; 259, subscript; 259, 260; 259, 261; 260, identifier:config; 261, string:'handlers'; 262, identifier:hdlr; 263, string:'filename'; 264, identifier:log_file; 265, else_clause; 265, 266; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 276; 268, 277; 269, subscript; 269, 270; 269, 275; 270, subscript; 270, 271; 270, 274; 271, subscript; 271, 272; 271, 273; 272, identifier:config; 273, string:'handlers'; 274, identifier:hdlr; 275, string:'filename'; 276, line_continuation:\; 277, call; 277, 278; 277, 287; 278, attribute; 278, 279; 278, 286; 279, subscript; 279, 280; 279, 285; 280, subscript; 280, 281; 280, 284; 281, subscript; 281, 282; 281, 283; 282, identifier:config; 283, string:'handlers'; 284, identifier:hdlr; 285, string:'filename'; 286, identifier:replace; 287, argument_list; 287, 288; 287, 289; 288, string:"%(logdir)s"; 289, identifier:log_dir; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 299; 291, 300; 292, subscript; 292, 293; 292, 298; 293, subscript; 293, 294; 293, 297; 294, subscript; 294, 295; 294, 296; 295, identifier:config; 296, string:'handlers'; 297, identifier:hdlr; 298, string:'filename'; 299, line_continuation:\; 300, call; 300, 301; 300, 310; 301, attribute; 301, 302; 301, 309; 302, subscript; 302, 303; 302, 308; 303, subscript; 303, 304; 303, 307; 304, subscript; 304, 305; 304, 306; 305, identifier:config; 306, string:'handlers'; 307, identifier:hdlr; 308, string:'filename'; 309, identifier:replace; 310, argument_list; 310, 311; 310, 312; 311, string:"%(daemon)s"; 312, identifier:process_name; 313, if_statement; 313, 314; 313, 330; 314, boolean_operator:and; 314, 315; 314, 316; 315, identifier:truncate; 316, call; 316, 317; 316, 322; 317, attribute; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:os; 320, identifier:path; 321, identifier:exists; 322, argument_list; 322, 323; 323, subscript; 323, 324; 323, 329; 324, subscript; 324, 325; 324, 328; 325, subscript; 325, 326; 325, 327; 326, identifier:config; 327, string:'handlers'; 328, identifier:hdlr; 329, string:'filename'; 330, block; 330, 331; 331, with_statement; 331, 332; 331, 348; 332, with_clause; 332, 333; 333, with_item; 333, 334; 334, as_pattern; 334, 335; 334, 346; 335, call; 335, 336; 335, 337; 336, identifier:open; 337, argument_list; 337, 338; 337, 345; 338, subscript; 338, 339; 338, 344; 339, subscript; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:config; 342, string:'handlers'; 343, identifier:hdlr; 344, string:'filename'; 345, string:"w"; 346, as_pattern_target; 346, 347; 347, identifier:file_log_file; 348, block; 348, 349; 349, expression_statement; 349, 350; 350, call; 350, 351; 350, 354; 351, attribute; 351, 352; 351, 353; 352, identifier:file_log_file; 353, identifier:truncate; 354, argument_list; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 358; 357, identifier:logger_dictConfig; 358, argument_list; 358, 359; 359, identifier:config | def setup_logger(logger_configuration_file, log_dir=None, process_name='', log_file=''):
logger_ = logging.getLogger(ALIGNAK_LOGGER_NAME)
for handler in logger_.handlers:
if not process_name:
break
if getattr(handler, '_name', None) == 'daemons':
for hdlr in logger_.handlers:
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)
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'
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)
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()
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, 23; 14, 50; 14, 56; 14, 87; 15, if_statement; 15, 16; 15, 20; 16, not_operator; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:service_notifications_enabled; 20, block; 20, 21; 21, return_statement; 21, 22; 22, False; 23, for_statement; 23, 24; 23, 25; 23, 28; 24, identifier:downtime_id; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:downtimes; 28, block; 28, 29; 28, 37; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:downtime; 32, subscript; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:downtimes; 36, identifier:downtime_id; 37, if_statement; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:downtime; 40, identifier:is_in_effect; 41, block; 41, 42; 41, 48; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:in_scheduled_downtime; 47, True; 48, return_statement; 48, 49; 49, False; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:in_scheduled_downtime; 55, False; 56, for_statement; 56, 57; 56, 58; 56, 61; 57, identifier:notifway_id; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:notificationways; 61, block; 61, 62; 61, 68; 61, 82; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:notifway; 65, subscript; 65, 66; 65, 67; 66, identifier:notifways; 67, identifier:notifway_id; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:nw_b; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:notifway; 74, identifier:want_service_notification; 75, argument_list; 75, 76; 75, 77; 75, 78; 75, 79; 75, 80; 75, 81; 76, identifier:timeperiods; 77, identifier:timestamp; 78, identifier:state; 79, identifier:n_type; 80, identifier:business_impact; 81, identifier:cmd; 82, if_statement; 82, 83; 82, 84; 83, identifier:nw_b; 84, block; 84, 85; 85, return_statement; 85, 86; 86, True; 87, return_statement; 87, 88; 88, False | def want_service_notification(self, notifways, timeperiods,
timestamp, state, n_type, business_impact, cmd=None):
if not self.service_notifications_enabled:
return False
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
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
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, 15; 7, 34; 7, 74; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:apply_partial_inheritance; 13, argument_list; 13, 14; 14, string:'contactgroups'; 15, for_statement; 15, 16; 15, 17; 15, 20; 16, identifier:prop; 17, attribute; 17, 18; 17, 19; 18, identifier:Contact; 19, identifier:special_properties; 20, block; 20, 21; 20, 27; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:==; 22, 23; 22, 24; 23, identifier:prop; 24, string:'contact_name'; 25, block; 25, 26; 26, continue_statement; 27, expression_statement; 27, 28; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:apply_partial_inheritance; 32, argument_list; 32, 33; 33, identifier:prop; 34, for_statement; 34, 35; 34, 36; 34, 37; 35, identifier:contact; 36, identifier:self; 37, block; 37, 38; 37, 54; 38, if_statement; 38, 39; 38, 52; 39, not_operator; 39, 40; 40, parenthesized_expression; 40, 41; 41, boolean_operator:and; 41, 42; 41, 47; 42, call; 42, 43; 42, 44; 43, identifier:hasattr; 44, argument_list; 44, 45; 44, 46; 45, identifier:contact; 46, string:'contact_name'; 47, call; 47, 48; 47, 49; 48, identifier:hasattr; 49, argument_list; 49, 50; 49, 51; 50, identifier:contact; 51, string:'contactgroups'; 52, block; 52, 53; 53, continue_statement; 54, for_statement; 54, 55; 54, 56; 54, 59; 55, identifier:contactgroup; 56, attribute; 56, 57; 56, 58; 57, identifier:contact; 58, identifier:contactgroups; 59, block; 59, 60; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:contactgroups; 64, identifier:add_member; 65, argument_list; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:contact; 68, identifier:contact_name; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:contactgroup; 72, identifier:strip; 73, argument_list; 74, for_statement; 74, 75; 74, 76; 74, 77; 75, identifier:contact; 76, identifier:self; 77, block; 77, 78; 77, 82; 77, 86; 77, 135; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:need_notificationway; 81, False; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:params; 85, dictionary; 86, for_statement; 86, 87; 86, 88; 86, 91; 87, identifier:param; 88, attribute; 88, 89; 88, 90; 89, identifier:Contact; 90, identifier:simple_way_parameters; 91, block; 91, 92; 92, if_statement; 92, 93; 92, 98; 92, 113; 93, call; 93, 94; 93, 95; 94, identifier:hasattr; 95, argument_list; 95, 96; 95, 97; 96, identifier:contact; 97, identifier:param; 98, block; 98, 99; 98, 103; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:need_notificationway; 102, True; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 108; 105, subscript; 105, 106; 105, 107; 106, identifier:params; 107, identifier:param; 108, call; 108, 109; 108, 110; 109, identifier:getattr; 110, argument_list; 110, 111; 110, 112; 111, identifier:contact; 112, identifier:param; 113, elif_clause; 113, 114; 113, 121; 114, attribute; 114, 115; 114, 120; 115, subscript; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:contact; 118, identifier:properties; 119, identifier:param; 120, identifier:has_default; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:setattr; 125, argument_list; 125, 126; 125, 127; 125, 128; 126, identifier:contact; 127, identifier:param; 128, attribute; 128, 129; 128, 134; 129, subscript; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:contact; 132, identifier:properties; 133, identifier:param; 134, identifier:default; 135, if_statement; 135, 136; 135, 137; 136, identifier:need_notificationway; 137, block; 137, 138; 137, 152; 137, 158; 137, 166; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:cname; 141, call; 141, 142; 141, 143; 142, identifier:getattr; 143, argument_list; 143, 144; 143, 145; 143, 146; 144, identifier:contact; 145, string:'contact_name'; 146, call; 146, 147; 146, 148; 147, identifier:getattr; 148, argument_list; 148, 149; 148, 150; 148, 151; 149, identifier:contact; 150, string:'alias'; 151, string:''; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:nw_name; 155, binary_operator:+; 155, 156; 155, 157; 156, identifier:cname; 157, string:'_inner_nw'; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:notificationways; 162, identifier:new_inner_member; 163, argument_list; 163, 164; 163, 165; 164, identifier:nw_name; 165, identifier:params; 166, if_statement; 166, 167; 166, 173; 166, 181; 167, not_operator; 167, 168; 168, call; 168, 169; 168, 170; 169, identifier:hasattr; 170, argument_list; 170, 171; 170, 172; 171, identifier:contact; 172, string:'notificationways'; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:contact; 178, identifier:notificationways; 179, list:[nw_name]; 179, 180; 180, identifier:nw_name; 181, else_clause; 181, 182; 182, block; 182, 183; 182, 194; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:contact; 187, identifier:notificationways; 188, call; 188, 189; 188, 190; 189, identifier:list; 190, argument_list; 190, 191; 191, attribute; 191, 192; 191, 193; 192, identifier:contact; 193, identifier:notificationways; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:contact; 199, identifier:notificationways; 200, identifier:append; 201, argument_list; 201, 202; 202, identifier:nw_name | def explode(self, contactgroups, notificationways):
self.apply_partial_inheritance('contactgroups')
for prop in Contact.special_properties:
if prop == 'contact_name':
continue
self.apply_partial_inheritance(prop)
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())
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:
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, 14; 8, 18; 8, 22; 8, 26; 8, 155; 8, 174; 8, 216; 8, 229; 8, 243; 8, 287; 8, 291; 8, 336; 8, 350; 8, 386; 8, 390; 8, 419; 8, 427; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:msg; 12, list:[[]]; 12, 13; 13, list:[]; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:raw_msg; 17, list:[]; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:escaped; 21, False; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:command_sep_found; 25, False; 26, while_statement; 26, 27; 26, 28; 27, True; 28, block; 28, 29; 28, 39; 28, 46; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:tmp; 32, call; 32, 33; 32, 38; 33, attribute; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:board; 37, identifier:read; 38, argument_list; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:raw_msg; 43, identifier:append; 44, argument_list; 44, 45; 45, identifier:tmp; 46, if_statement; 46, 47; 46, 48; 46, 98; 47, identifier:escaped; 48, block; 48, 49; 49, if_statement; 49, 50; 49, 55; 49, 70; 50, comparison_operator:in; 50, 51; 50, 52; 51, identifier:tmp; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_escaped_characters; 55, block; 55, 56; 55, 66; 56, expression_statement; 56, 57; 57, call; 57, 58; 57, 64; 58, attribute; 58, 59; 58, 63; 59, subscript; 59, 60; 59, 61; 60, identifier:msg; 61, unary_operator:-; 61, 62; 62, integer:1; 63, identifier:append; 64, argument_list; 64, 65; 65, identifier:tmp; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:escaped; 69, False; 70, else_clause; 70, 71; 71, block; 71, 72; 71, 84; 71, 94; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 80; 74, attribute; 74, 75; 74, 79; 75, subscript; 75, 76; 75, 77; 76, identifier:msg; 77, unary_operator:-; 77, 78; 78, integer:1; 79, identifier:append; 80, argument_list; 80, 81; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:_byte_escape_sep; 84, expression_statement; 84, 85; 85, call; 85, 86; 85, 92; 86, attribute; 86, 87; 86, 91; 87, subscript; 87, 88; 87, 89; 88, identifier:msg; 89, unary_operator:-; 89, 90; 90, integer:1; 91, identifier:append; 92, argument_list; 92, 93; 93, identifier:tmp; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:escaped; 97, False; 98, else_clause; 98, 99; 99, block; 99, 100; 100, if_statement; 100, 101; 100, 106; 100, 111; 100, 125; 100, 137; 100, 143; 101, comparison_operator:==; 101, 102; 101, 103; 102, identifier:tmp; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:_byte_escape_sep; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 110; 109, identifier:escaped; 110, True; 111, elif_clause; 111, 112; 111, 117; 112, comparison_operator:==; 112, 113; 112, 114; 113, identifier:tmp; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:_byte_field_sep; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:msg; 122, identifier:append; 123, argument_list; 123, 124; 124, list:[]; 125, elif_clause; 125, 126; 125, 131; 126, comparison_operator:==; 126, 127; 126, 128; 127, identifier:tmp; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:_byte_command_sep; 131, block; 131, 132; 131, 136; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:command_sep_found; 135, True; 136, break_statement; 137, elif_clause; 137, 138; 137, 141; 138, comparison_operator:==; 138, 139; 138, 140; 139, identifier:tmp; 140, string:b''; 141, block; 141, 142; 142, break_statement; 143, else_clause; 143, 144; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 153; 147, attribute; 147, 148; 147, 152; 148, subscript; 148, 149; 148, 150; 149, identifier:msg; 150, unary_operator:-; 150, 151; 151, integer:1; 152, identifier:append; 153, argument_list; 153, 154; 154, identifier:tmp; 155, if_statement; 155, 156; 155, 171; 156, boolean_operator:and; 156, 157; 156, 163; 157, comparison_operator:==; 157, 158; 157, 162; 158, call; 158, 159; 158, 160; 159, identifier:len; 160, argument_list; 160, 161; 161, identifier:msg; 162, integer:1; 163, comparison_operator:==; 163, 164; 163, 170; 164, call; 164, 165; 164, 166; 165, identifier:len; 166, argument_list; 166, 167; 167, subscript; 167, 168; 167, 169; 168, identifier:msg; 169, integer:0; 170, integer:0; 171, block; 171, 172; 172, return_statement; 172, 173; 173, None; 174, if_statement; 174, 175; 174, 177; 175, not_operator; 175, 176; 176, identifier:command_sep_found; 177, block; 177, 178; 177, 187; 177, 198; 177, 211; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:joined_raw; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, string:b''; 184, identifier:join; 185, argument_list; 185, 186; 186, identifier:raw_msg; 187, if_statement; 187, 188; 187, 195; 188, comparison_operator:==; 188, 189; 188, 194; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:joined_raw; 192, identifier:strip; 193, argument_list; 194, string:b''; 195, block; 195, 196; 196, return_statement; 196, 197; 197, None; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:err; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, string:"Incomplete message ({})"; 204, identifier:format; 205, argument_list; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:joined_raw; 209, identifier:decode; 210, argument_list; 211, raise_statement; 211, 212; 212, call; 212, 213; 212, 214; 213, identifier:EOFError; 214, argument_list; 214, 215; 215, identifier:err; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:fields; 219, list_comprehension; 219, 220; 219, 226; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, string:b''; 223, identifier:join; 224, argument_list; 224, 225; 225, identifier:m; 226, for_in_clause; 226, 227; 226, 228; 227, identifier:m; 228, identifier:msg; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:cmd; 232, call; 232, 233; 232, 242; 233, attribute; 233, 234; 233, 241; 234, call; 234, 235; 234, 240; 235, attribute; 235, 236; 235, 239; 236, subscript; 236, 237; 236, 238; 237, identifier:fields; 238, integer:0; 239, identifier:strip; 240, argument_list; 241, identifier:decode; 242, argument_list; 243, try_statement; 243, 244; 243, 256; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:cmd_name; 248, subscript; 248, 249; 248, 252; 249, attribute; 249, 250; 249, 251; 250, identifier:self; 251, identifier:_int_to_cmd_name; 252, call; 252, 253; 252, 254; 253, identifier:int; 254, argument_list; 254, 255; 255, identifier:cmd; 256, except_clause; 256, 257; 256, 260; 257, tuple; 257, 258; 257, 259; 258, identifier:ValueError; 259, identifier:IndexError; 260, block; 260, 261; 261, if_statement; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:give_warnings; 265, block; 265, 266; 265, 270; 265, 279; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 269; 268, identifier:cmd_name; 269, string:"unknown"; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:w; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, string:"Recieved unrecognized command ({})."; 276, identifier:format; 277, argument_list; 277, 278; 278, identifier:cmd; 279, expression_statement; 279, 280; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:warnings; 283, identifier:warn; 284, argument_list; 284, 285; 284, 286; 285, identifier:w; 286, identifier:Warning; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:arg_format_list; 290, list:[]; 291, if_statement; 291, 292; 291, 295; 291, 303; 292, comparison_operator:!=; 292, 293; 292, 294; 293, identifier:arg_formats; 294, None; 295, block; 295, 296; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:arg_format_list; 299, call; 299, 300; 299, 301; 300, identifier:list; 301, argument_list; 301, 302; 302, identifier:arg_formats; 303, else_clause; 303, 304; 304, block; 304, 305; 305, try_statement; 305, 306; 305, 315; 306, block; 306, 307; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:arg_format_list; 310, subscript; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:self; 313, identifier:_cmd_name_to_format; 314, identifier:cmd_name; 315, except_clause; 315, 316; 315, 317; 316, identifier:KeyError; 317, block; 317, 318; 318, expression_statement; 318, 319; 319, assignment; 319, 320; 319, 321; 320, identifier:arg_format_list; 321, list_comprehension; 321, 322; 321, 323; 322, string:"g"; 323, for_in_clause; 323, 324; 323, 325; 324, identifier:i; 325, call; 325, 326; 325, 327; 326, identifier:range; 327, argument_list; 327, 328; 328, call; 328, 329; 328, 330; 329, identifier:len; 330, argument_list; 330, 331; 331, subscript; 331, 332; 331, 333; 332, identifier:fields; 333, slice; 333, 334; 333, 335; 334, integer:1; 335, colon; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:arg_format_list; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:self; 342, identifier:_treat_star_format; 343, argument_list; 343, 344; 343, 345; 344, identifier:arg_format_list; 345, subscript; 345, 346; 345, 347; 346, identifier:fields; 347, slice; 347, 348; 347, 349; 348, integer:1; 349, colon; 350, if_statement; 350, 351; 350, 361; 351, comparison_operator:>; 351, 352; 351, 360; 352, call; 352, 353; 352, 354; 353, identifier:len; 354, argument_list; 354, 355; 355, subscript; 355, 356; 355, 357; 356, identifier:fields; 357, slice; 357, 358; 357, 359; 358, integer:1; 359, colon; 360, integer:0; 361, block; 361, 362; 362, if_statement; 362, 363; 362, 376; 363, comparison_operator:!=; 363, 364; 363, 368; 364, call; 364, 365; 364, 366; 365, identifier:len; 366, argument_list; 366, 367; 367, identifier:arg_format_list; 368, call; 368, 369; 368, 370; 369, identifier:len; 370, argument_list; 370, 371; 371, subscript; 371, 372; 371, 373; 372, identifier:fields; 373, slice; 373, 374; 373, 375; 374, integer:1; 375, colon; 376, block; 376, 377; 376, 381; 377, expression_statement; 377, 378; 378, assignment; 378, 379; 378, 380; 379, identifier:err; 380, string:"Number of argument formats must match the number of recieved arguments."; 381, raise_statement; 381, 382; 382, call; 382, 383; 382, 384; 383, identifier:ValueError; 384, argument_list; 384, 385; 385, identifier:err; 386, expression_statement; 386, 387; 387, assignment; 387, 388; 387, 389; 388, identifier:received; 389, list:[]; 390, for_statement; 390, 391; 390, 394; 390, 402; 391, pattern_list; 391, 392; 391, 393; 392, identifier:i; 393, identifier:f; 394, call; 394, 395; 394, 396; 395, identifier:enumerate; 396, argument_list; 396, 397; 397, subscript; 397, 398; 397, 399; 398, identifier:fields; 399, slice; 399, 400; 399, 401; 400, integer:1; 401, colon; 402, block; 402, 403; 403, expression_statement; 403, 404; 404, call; 404, 405; 404, 408; 405, attribute; 405, 406; 405, 407; 406, identifier:received; 407, identifier:append; 408, argument_list; 408, 409; 409, call; 409, 410; 409, 417; 410, subscript; 410, 411; 410, 414; 411, attribute; 411, 412; 411, 413; 412, identifier:self; 413, identifier:_recv_methods; 414, subscript; 414, 415; 414, 416; 415, identifier:arg_format_list; 416, identifier:i; 417, argument_list; 417, 418; 418, identifier:f; 419, expression_statement; 419, 420; 420, assignment; 420, 421; 420, 422; 421, identifier:message_time; 422, call; 422, 423; 422, 426; 423, attribute; 423, 424; 423, 425; 424, identifier:time; 425, identifier:time; 426, argument_list; 427, return_statement; 427, 428; 428, expression_list; 428, 429; 428, 430; 428, 431; 429, identifier:cmd_name; 430, identifier:received; 431, identifier:message_time | def receive(self,arg_formats=None):
msg = [[]]
raw_msg = []
escaped = False
command_sep_found = False
while True:
tmp = self.board.read()
raw_msg.append(tmp)
if escaped:
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:
if tmp == self._byte_escape_sep:
escaped = True
elif tmp == self._byte_field_sep:
msg.append([])
elif tmp == self._byte_command_sep:
command_sep_found = True
break
elif tmp == b'':
break
else:
msg[-1].append(tmp)
if len(msg) == 1 and len(msg[0]) == 0:
return None
if not command_sep_found:
joined_raw = b''.join(raw_msg)
if joined_raw.strip() == b'':
return None
err = "Incomplete message ({})".format(joined_raw.decode())
raise EOFError(err)
fields = [b''.join(m) for m in msg]
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)
arg_format_list = []
if arg_formats != None:
arg_format_list = list(arg_formats)
else:
try:
arg_format_list = self._cmd_name_to_format[cmd_name]
except KeyError:
arg_format_list = ["g" for i in range(len(fields[1:]))]
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))
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, 19; 8, 29; 8, 39; 8, 58; 8, 72; 8, 82; 8, 86; 8, 95; 8, 110; 8, 136; 8, 157; 8, 166; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:perms; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:kwargs; 15, identifier:get; 16, argument_list; 16, 17; 16, 18; 17, string:'perms'; 18, None; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:password; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:kwargs; 25, identifier:get; 26, argument_list; 26, 27; 26, 28; 27, string:'password'; 28, None; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:public_upload; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:kwargs; 35, identifier:get; 36, argument_list; 36, 37; 36, 38; 37, string:'public_upload'; 38, None; 39, if_statement; 39, 40; 39, 53; 40, boolean_operator:and; 40, 41; 40, 47; 41, parenthesized_expression; 41, 42; 42, call; 42, 43; 42, 44; 43, identifier:isinstance; 44, argument_list; 44, 45; 44, 46; 45, identifier:perms; 46, identifier:int; 47, parenthesized_expression; 47, 48; 48, comparison_operator:>; 48, 49; 48, 50; 49, identifier:perms; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:OCS_PERMISSION_ALL; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:perms; 57, None; 58, if_statement; 58, 59; 58, 69; 59, not_operator; 59, 60; 60, parenthesized_expression; 60, 61; 61, boolean_operator:or; 61, 62; 61, 65; 62, boolean_operator:or; 62, 63; 62, 64; 63, identifier:perms; 64, identifier:password; 65, parenthesized_expression; 65, 66; 66, comparison_operator:is; 66, 67; 66, 68; 67, identifier:public_upload; 68, None; 69, block; 69, 70; 70, return_statement; 70, 71; 71, False; 72, if_statement; 72, 73; 72, 79; 73, not_operator; 73, 74; 74, call; 74, 75; 74, 76; 75, identifier:isinstance; 76, argument_list; 76, 77; 76, 78; 77, identifier:share_id; 78, identifier:int; 79, block; 79, 80; 80, return_statement; 80, 81; 81, False; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:data; 85, dictionary; 86, if_statement; 86, 87; 86, 88; 87, identifier:perms; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, subscript; 91, 92; 91, 93; 92, identifier:data; 93, string:'permissions'; 94, identifier:perms; 95, if_statement; 95, 96; 95, 103; 96, call; 96, 97; 96, 98; 97, identifier:isinstance; 98, argument_list; 98, 99; 98, 100; 99, identifier:password; 100, attribute; 100, 101; 100, 102; 101, identifier:six; 102, identifier:string_types; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:data; 108, string:'password'; 109, identifier:password; 110, if_statement; 110, 111; 110, 122; 111, boolean_operator:and; 111, 112; 111, 116; 112, parenthesized_expression; 112, 113; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:public_upload; 115, None; 116, parenthesized_expression; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:isinstance; 119, argument_list; 119, 120; 119, 121; 120, identifier:public_upload; 121, identifier:bool; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, subscript; 125, 126; 125, 127; 126, identifier:data; 127, string:'publicUpload'; 128, call; 128, 129; 128, 135; 129, attribute; 129, 130; 129, 134; 130, call; 130, 131; 130, 132; 131, identifier:str; 132, argument_list; 132, 133; 133, identifier:public_upload; 134, identifier:lower; 135, argument_list; 136, expression_statement; 136, 137; 137, assignment; 137, 138; 137, 139; 138, identifier:res; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_make_ocs_request; 143, argument_list; 143, 144; 143, 145; 143, 148; 143, 154; 144, string:'PUT'; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:OCS_SERVICE_SHARE; 148, binary_operator:+; 148, 149; 148, 150; 149, string:'shares/'; 150, call; 150, 151; 150, 152; 151, identifier:str; 152, argument_list; 152, 153; 153, identifier:share_id; 154, keyword_argument; 154, 155; 154, 156; 155, identifier:data; 156, identifier:data; 157, if_statement; 157, 158; 157, 163; 158, comparison_operator:==; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:res; 161, identifier:status_code; 162, integer:200; 163, block; 163, 164; 164, return_statement; 164, 165; 165, True; 166, raise_statement; 166, 167; 167, call; 167, 168; 167, 169; 168, identifier:HTTPResponseError; 169, argument_list; 169, 170; 170, identifier:res | def update_share(self, share_id, **kwargs):
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, 24; 10, 28; 10, 153; 10, 166; 10, 225; 11, if_statement; 11, 12; 11, 21; 12, not_operator; 12, 13; 13, parenthesized_expression; 13, 14; 14, call; 14, 15; 14, 16; 15, identifier:isinstance; 16, argument_list; 16, 17; 16, 18; 17, identifier:path; 18, attribute; 18, 19; 18, 20; 19, identifier:six; 20, identifier:string_types; 21, block; 21, 22; 22, return_statement; 22, 23; 23, None; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:data; 27, string:'shares'; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:!=; 29, 30; 29, 31; 30, identifier:path; 31, string:''; 32, block; 32, 33; 32, 37; 32, 51; 32, 58; 32, 68; 32, 83; 32, 93; 32, 115; 32, 125; 32, 144; 33, expression_statement; 33, 34; 34, augmented_assignment:+=; 34, 35; 34, 36; 35, identifier:data; 36, string:'?'; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:path; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:_encode_string; 44, argument_list; 44, 45; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_normalize_path; 49, argument_list; 49, 50; 50, identifier:path; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:args; 54, dictionary; 54, 55; 55, pair; 55, 56; 55, 57; 56, string:'path'; 57, identifier:path; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:reshares; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:kwargs; 64, identifier:get; 65, argument_list; 65, 66; 65, 67; 66, string:'reshares'; 67, False; 68, if_statement; 68, 69; 68, 76; 69, boolean_operator:and; 69, 70; 69, 75; 70, call; 70, 71; 70, 72; 71, identifier:isinstance; 72, argument_list; 72, 73; 72, 74; 73, identifier:reshares; 74, identifier:bool; 75, identifier:reshares; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:args; 81, string:'reshares'; 82, identifier:reshares; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:subfiles; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:kwargs; 89, identifier:get; 90, argument_list; 90, 91; 90, 92; 91, string:'subfiles'; 92, False; 93, if_statement; 93, 94; 93, 101; 94, boolean_operator:and; 94, 95; 94, 100; 95, call; 95, 96; 95, 97; 96, identifier:isinstance; 97, argument_list; 97, 98; 97, 99; 98, identifier:subfiles; 99, identifier:bool; 100, identifier:subfiles; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:args; 106, string:'subfiles'; 107, call; 107, 108; 107, 114; 108, attribute; 108, 109; 108, 113; 109, call; 109, 110; 109, 111; 110, identifier:str; 111, argument_list; 111, 112; 112, identifier:subfiles; 113, identifier:lower; 114, argument_list; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:shared_with_me; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:kwargs; 121, identifier:get; 122, argument_list; 122, 123; 122, 124; 123, string:'shared_with_me'; 124, False; 125, if_statement; 125, 126; 125, 133; 126, boolean_operator:and; 126, 127; 126, 132; 127, call; 127, 128; 127, 129; 128, identifier:isinstance; 129, argument_list; 129, 130; 129, 131; 130, identifier:shared_with_me; 131, identifier:bool; 132, identifier:shared_with_me; 133, block; 133, 134; 133, 140; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 139; 136, subscript; 136, 137; 136, 138; 137, identifier:args; 138, string:'shared_with_me'; 139, string:"true"; 140, delete_statement; 140, 141; 141, subscript; 141, 142; 141, 143; 142, identifier:args; 143, string:'path'; 144, expression_statement; 144, 145; 145, augmented_assignment:+=; 145, 146; 145, 147; 146, identifier:data; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:parse; 150, identifier:urlencode; 151, argument_list; 151, 152; 152, identifier:args; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:res; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:_make_ocs_request; 160, argument_list; 160, 161; 160, 162; 160, 165; 161, string:'GET'; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:OCS_SERVICE_SHARE; 165, identifier:data; 166, if_statement; 166, 167; 166, 172; 167, comparison_operator:==; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:res; 170, identifier:status_code; 171, integer:200; 172, block; 172, 173; 172, 184; 172, 191; 172, 195; 172, 223; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:tree; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:ET; 179, identifier:fromstring; 180, argument_list; 180, 181; 181, attribute; 181, 182; 181, 183; 182, identifier:res; 183, identifier:content; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:_check_ocs_status; 189, argument_list; 189, 190; 190, identifier:tree; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:shares; 194, list:[]; 195, for_statement; 195, 196; 195, 197; 195, 208; 196, identifier:element; 197, call; 197, 198; 197, 206; 198, attribute; 198, 199; 198, 205; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:tree; 202, identifier:find; 203, argument_list; 203, 204; 204, string:'data'; 205, identifier:iter; 206, argument_list; 206, 207; 207, string:'element'; 208, block; 208, 209; 208, 211; 209, expression_statement; 209, 210; 210, string:'''share_attr = {}
for child in element:
key = child.tag
value = child.text
share_attr[key] = value
shares.append(share_attr)'''; 211, expression_statement; 211, 212; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:shares; 215, identifier:append; 216, argument_list; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:self; 220, identifier:_get_shareinfo; 221, argument_list; 221, 222; 222, identifier:element; 223, return_statement; 223, 224; 224, identifier:shares; 225, raise_statement; 225, 226; 226, call; 226, 227; 226, 228; 227, identifier:HTTPResponseError; 228, argument_list; 228, 229; 229, identifier:res | def get_shares(self, path='', **kwargs):
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, 20; 9, 32; 9, 68; 9, 86; 9, 95; 9, 123; 9, 139; 9, 158; 9, 213; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:remote_user; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:kwargs; 16, identifier:get; 17, argument_list; 17, 18; 17, 19; 18, string:'remote_user'; 19, False; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:perms; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:kwargs; 26, identifier:get; 27, argument_list; 27, 28; 27, 29; 28, string:'perms'; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:OCS_PERMISSION_READ; 32, if_statement; 32, 33; 32, 65; 33, parenthesized_expression; 33, 34; 34, boolean_operator:or; 34, 35; 34, 50; 35, parenthesized_expression; 35, 36; 36, boolean_operator:or; 36, 37; 36, 44; 37, parenthesized_expression; 37, 38; 38, not_operator; 38, 39; 39, call; 39, 40; 39, 41; 40, identifier:isinstance; 41, argument_list; 41, 42; 41, 43; 42, identifier:perms; 43, identifier:int; 44, parenthesized_expression; 44, 45; 45, comparison_operator:>; 45, 46; 45, 47; 46, identifier:perms; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:OCS_PERMISSION_ALL; 50, parenthesized_expression; 50, 51; 51, boolean_operator:or; 51, 52; 51, 61; 52, parenthesized_expression; 52, 53; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:user; 58, attribute; 58, 59; 58, 60; 59, identifier:six; 60, identifier:string_types; 61, parenthesized_expression; 61, 62; 62, comparison_operator:==; 62, 63; 62, 64; 63, identifier:user; 64, string:''; 65, block; 65, 66; 66, return_statement; 66, 67; 67, False; 68, if_statement; 68, 69; 68, 79; 69, boolean_operator:and; 69, 70; 69, 71; 70, identifier:remote_user; 71, parenthesized_expression; 71, 72; 72, not_operator; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:user; 76, identifier:endswith; 77, argument_list; 77, 78; 78, string:'/'; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:user; 83, binary_operator:+; 83, 84; 83, 85; 84, identifier:user; 85, string:'/'; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:path; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:_normalize_path; 93, argument_list; 93, 94; 94, identifier:path; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:post_data; 98, dictionary; 98, 99; 98, 109; 98, 112; 98, 120; 99, pair; 99, 100; 99, 101; 100, string:'shareType'; 101, conditional_expression:if; 101, 102; 101, 105; 101, 106; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:OCS_SHARE_TYPE_REMOTE; 105, identifier:remote_user; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:OCS_SHARE_TYPE_USER; 109, pair; 109, 110; 109, 111; 110, string:'shareWith'; 111, identifier:user; 112, pair; 112, 113; 112, 114; 113, string:'path'; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:_encode_string; 118, argument_list; 118, 119; 119, identifier:path; 120, pair; 120, 121; 120, 122; 121, string:'permissions'; 122, identifier:perms; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:res; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:_make_ocs_request; 130, argument_list; 130, 131; 130, 132; 130, 135; 130, 136; 131, string:'POST'; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:OCS_SERVICE_SHARE; 135, string:'shares'; 136, keyword_argument; 136, 137; 136, 138; 137, identifier:data; 138, identifier:post_data; 139, if_statement; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:_debug; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, call; 145, 146; 145, 147; 146, identifier:print; 147, argument_list; 147, 148; 148, binary_operator:%; 148, 149; 148, 152; 149, concatenated_string; 149, 150; 149, 151; 150, string:'OCS share_file request for file %s with permissions %i '; 151, string:'returned: %i'; 152, tuple; 152, 153; 152, 154; 152, 155; 153, identifier:path; 154, identifier:perms; 155, attribute; 155, 156; 155, 157; 156, identifier:res; 157, identifier:status_code; 158, if_statement; 158, 159; 158, 164; 159, comparison_operator:==; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:res; 162, identifier:status_code; 163, integer:200; 164, block; 164, 165; 164, 176; 164, 183; 164, 192; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:tree; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:ET; 171, identifier:fromstring; 172, argument_list; 172, 173; 173, attribute; 173, 174; 173, 175; 174, identifier:res; 175, identifier:content; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:_check_ocs_status; 181, argument_list; 181, 182; 182, identifier:tree; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:data_el; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:tree; 189, identifier:find; 190, argument_list; 190, 191; 191, string:'data'; 192, return_statement; 192, 193; 193, call; 193, 194; 193, 195; 194, identifier:ShareInfo; 195, argument_list; 195, 196; 196, dictionary; 196, 197; 196, 207; 196, 210; 197, pair; 197, 198; 197, 199; 198, string:'id'; 199, attribute; 199, 200; 199, 206; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:data_el; 203, identifier:find; 204, argument_list; 204, 205; 205, string:'id'; 206, identifier:text; 207, pair; 207, 208; 207, 209; 208, string:'path'; 209, identifier:path; 210, pair; 210, 211; 210, 212; 211, string:'permissions'; 212, identifier:perms; 213, raise_statement; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:HTTPResponseError; 216, argument_list; 216, 217; 217, identifier:res | def share_file_with_user(self, path, user, **kwargs):
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, 16; 11, 55; 11, 68; 11, 197; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:path; 15, string:'getattribute'; 16, if_statement; 16, 17; 16, 20; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:app; 19, None; 20, block; 20, 21; 20, 33; 21, expression_statement; 21, 22; 22, augmented_assignment:+=; 22, 23; 22, 24; 23, identifier:path; 24, binary_operator:+; 24, 25; 24, 26; 25, string:'/'; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:parse; 29, identifier:quote; 30, argument_list; 30, 31; 30, 32; 31, identifier:app; 32, string:''; 33, if_statement; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:key; 36, None; 37, block; 37, 38; 38, expression_statement; 38, 39; 39, augmented_assignment:+=; 39, 40; 39, 41; 40, identifier:path; 41, binary_operator:+; 41, 42; 41, 43; 42, string:'/'; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:parse; 46, identifier:quote; 47, argument_list; 47, 48; 47, 54; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_encode_string; 52, argument_list; 52, 53; 53, identifier:key; 54, string:''; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:res; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:_make_ocs_request; 62, argument_list; 62, 63; 62, 64; 62, 67; 63, string:'GET'; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:OCS_SERVICE_PRIVATEDATA; 67, identifier:path; 68, if_statement; 68, 69; 68, 74; 69, comparison_operator:==; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:res; 72, identifier:status_code; 73, integer:200; 74, block; 74, 75; 74, 86; 74, 93; 74, 97; 74, 181; 74, 195; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:tree; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:ET; 81, identifier:fromstring; 82, argument_list; 82, 83; 83, attribute; 83, 84; 83, 85; 84, identifier:res; 85, identifier:content; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:_check_ocs_status; 91, argument_list; 91, 92; 92, identifier:tree; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:values; 96, list:[]; 97, for_statement; 97, 98; 97, 99; 97, 110; 98, identifier:element; 99, call; 99, 100; 99, 108; 100, attribute; 100, 101; 100, 107; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:tree; 104, identifier:find; 105, argument_list; 105, 106; 106, string:'data'; 107, identifier:iter; 108, argument_list; 108, 109; 109, string:'element'; 110, block; 110, 111; 110, 122; 110, 133; 110, 146; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:app_text; 114, attribute; 114, 115; 114, 121; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:element; 118, identifier:find; 119, argument_list; 119, 120; 120, string:'app'; 121, identifier:text; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:key_text; 125, attribute; 125, 126; 125, 132; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:element; 129, identifier:find; 130, argument_list; 130, 131; 131, string:'key'; 132, identifier:text; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:value_text; 136, boolean_operator:or; 136, 137; 136, 145; 137, attribute; 137, 138; 137, 144; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:element; 141, identifier:find; 142, argument_list; 142, 143; 143, string:'value'; 144, identifier:text; 145, string:''; 146, if_statement; 146, 147; 146, 150; 146, 177; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:key; 149, None; 150, block; 150, 151; 151, if_statement; 151, 152; 151, 155; 151, 166; 152, comparison_operator:is; 152, 153; 152, 154; 153, identifier:app; 154, None; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:values; 160, identifier:append; 161, argument_list; 161, 162; 162, tuple; 162, 163; 162, 164; 162, 165; 163, identifier:app_text; 164, identifier:key_text; 165, identifier:value_text; 166, else_clause; 166, 167; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:values; 172, identifier:append; 173, argument_list; 173, 174; 174, tuple; 174, 175; 174, 176; 175, identifier:key_text; 176, identifier:value_text; 177, else_clause; 177, 178; 178, block; 178, 179; 179, return_statement; 179, 180; 180, identifier:value_text; 181, if_statement; 181, 182; 181, 192; 182, boolean_operator:and; 182, 183; 182, 189; 183, comparison_operator:==; 183, 184; 183, 188; 184, call; 184, 185; 184, 186; 185, identifier:len; 186, argument_list; 186, 187; 187, identifier:values; 188, integer:0; 189, comparison_operator:is; 189, 190; 189, 191; 190, identifier:key; 191, None; 192, block; 192, 193; 193, return_statement; 193, 194; 194, None; 195, return_statement; 195, 196; 196, identifier:values; 197, raise_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:HTTPResponseError; 200, argument_list; 200, 201; 201, identifier:res | def get_attribute(self, app=None, key=None):
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, 43; 9, 52; 9, 80; 9, 94; 9, 110; 9, 121; 10, if_statement; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:_debug; 14, block; 14, 15; 14, 24; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:print; 18, argument_list; 18, 19; 19, binary_operator:%; 19, 20; 19, 21; 20, string:'DAV request: %s %s'; 21, tuple; 21, 22; 21, 23; 22, identifier:method; 23, identifier:path; 24, if_statement; 24, 25; 24, 31; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:kwargs; 28, identifier:get; 29, argument_list; 29, 30; 30, string:'headers'; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:print; 35, argument_list; 35, 36; 35, 37; 36, string:'Headers: '; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:kwargs; 40, identifier:get; 41, argument_list; 41, 42; 42, string:'headers'; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:path; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_normalize_path; 50, argument_list; 50, 51; 51, identifier:path; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:res; 55, call; 55, 56; 55, 61; 56, attribute; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:_session; 60, identifier:request; 61, argument_list; 61, 62; 61, 63; 61, 78; 62, identifier:method; 63, binary_operator:+; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_webdav_url; 67, call; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:parse; 70, identifier:quote; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:_encode_string; 76, argument_list; 76, 77; 77, identifier:path; 78, dictionary_splat; 78, 79; 79, identifier:kwargs; 80, if_statement; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:_debug; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 88; 87, identifier:print; 88, argument_list; 88, 89; 89, binary_operator:%; 89, 90; 89, 91; 90, string:'DAV status: %i'; 91, attribute; 91, 92; 91, 93; 92, identifier:res; 93, identifier:status_code; 94, if_statement; 94, 95; 94, 102; 95, comparison_operator:in; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:res; 98, identifier:status_code; 99, list:[200, 207]; 99, 100; 99, 101; 100, integer:200; 101, integer:207; 102, block; 102, 103; 103, return_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_parse_dav_response; 108, argument_list; 108, 109; 109, identifier:res; 110, if_statement; 110, 111; 110, 118; 111, comparison_operator:in; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:res; 114, identifier:status_code; 115, list:[204, 201]; 115, 116; 115, 117; 116, integer:204; 117, integer:201; 118, block; 118, 119; 119, return_statement; 119, 120; 120, True; 121, raise_statement; 121, 122; 122, call; 122, 123; 122, 124; 123, identifier:HTTPResponseError; 124, argument_list; 124, 125; 125, identifier:res | def _make_dav_request(self, method, path, **kwargs):
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, 19; 9, 34; 9, 43; 9, 158; 10, expression_statement; 10, 11; 11, identifier:r; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:n_columns; 15, call; 15, 16; 15, 17; 16, identifier:len; 17, argument_list; 17, 18; 18, identifier:converters; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:columns; 22, call; 22, 23; 22, 24; 23, identifier:tuple; 24, generator_expression; 24, 25; 24, 28; 25, call; 25, 26; 25, 27; 26, identifier:list; 27, argument_list; 28, for_in_clause; 28, 29; 28, 30; 29, identifier:_; 30, call; 30, 31; 30, 32; 31, identifier:range; 32, argument_list; 32, 33; 33, identifier:n_columns; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:splitter; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:re; 40, identifier:compile; 41, argument_list; 41, 42; 42, identifier:delimiter; 43, with_statement; 43, 44; 43, 56; 44, with_clause; 44, 45; 45, with_item; 45, 46; 46, as_pattern; 46, 47; 46, 54; 47, call; 47, 48; 47, 49; 48, identifier:_open; 49, argument_list; 49, 50; 49, 51; 50, identifier:filename; 51, keyword_argument; 51, 52; 51, 53; 52, identifier:mode; 53, string:'r'; 54, as_pattern_target; 54, 55; 55, identifier:input_file; 56, block; 56, 57; 57, for_statement; 57, 58; 57, 61; 57, 66; 58, pattern_list; 58, 59; 58, 60; 59, identifier:row; 60, identifier:line; 61, call; 61, 62; 61, 63; 62, identifier:enumerate; 63, argument_list; 63, 64; 63, 65; 64, identifier:input_file; 65, integer:1; 66, block; 66, 67; 66, 83; 66, 110; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:data; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:splitter; 73, identifier:split; 74, argument_list; 74, 75; 74, 80; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:line; 78, identifier:strip; 79, argument_list; 80, binary_operator:-; 80, 81; 80, 82; 81, identifier:n_columns; 82, integer:1; 83, if_statement; 83, 84; 83, 90; 84, comparison_operator:!=; 84, 85; 84, 86; 85, identifier:n_columns; 86, call; 86, 87; 86, 88; 87, identifier:len; 88, argument_list; 88, 89; 89, identifier:data; 90, block; 90, 91; 91, raise_statement; 91, 92; 92, call; 92, 93; 92, 94; 93, identifier:ValueError; 94, argument_list; 94, 95; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, concatenated_string; 97, 98; 97, 99; 98, string:'Expected {} columns, got {} at '; 99, string:'{}:{:d}:\n\t{}'; 100, identifier:format; 101, argument_list; 101, 102; 101, 103; 101, 107; 101, 108; 101, 109; 102, identifier:n_columns; 103, call; 103, 104; 103, 105; 104, identifier:len; 105, argument_list; 105, 106; 106, identifier:data; 107, identifier:filename; 108, identifier:row; 109, identifier:line; 110, for_statement; 110, 111; 110, 115; 110, 121; 111, pattern_list; 111, 112; 111, 113; 111, 114; 112, identifier:value; 113, identifier:column; 114, identifier:converter; 115, call; 115, 116; 115, 117; 116, identifier:zip; 117, argument_list; 117, 118; 117, 119; 117, 120; 118, identifier:data; 119, identifier:columns; 120, identifier:converters; 121, block; 121, 122; 121, 151; 122, try_statement; 122, 123; 122, 131; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:converted_value; 127, call; 127, 128; 127, 129; 128, identifier:converter; 129, argument_list; 129, 130; 130, identifier:value; 131, except_clause; 131, 132; 132, block; 132, 133; 133, raise_statement; 133, 134; 134, call; 134, 135; 134, 136; 135, identifier:ValueError; 136, argument_list; 136, 137; 137, call; 137, 138; 137, 143; 138, attribute; 138, 139; 138, 142; 139, concatenated_string; 139, 140; 139, 141; 140, string:"Couldn't convert value {} using {} "; 141, string:"found at {}:{:d}:\n\t{}"; 142, identifier:format; 143, argument_list; 143, 144; 143, 145; 143, 148; 143, 149; 143, 150; 144, identifier:value; 145, attribute; 145, 146; 145, 147; 146, identifier:converter; 147, identifier:__name__; 148, identifier:filename; 149, identifier:row; 150, identifier:line; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:column; 155, identifier:append; 156, argument_list; 156, 157; 157, identifier:converted_value; 158, if_statement; 158, 159; 158, 162; 158, 167; 159, comparison_operator:==; 159, 160; 159, 161; 160, identifier:n_columns; 161, integer:1; 162, block; 162, 163; 163, return_statement; 163, 164; 164, subscript; 164, 165; 164, 166; 165, identifier:columns; 166, integer:0; 167, else_clause; 167, 168; 168, block; 168, 169; 169, return_statement; 169, 170; 170, identifier:columns | def load_delimited(filename, converters, delimiter=r'\s+'):
r
n_columns = len(converters)
columns = tuple(list() for _ in range(n_columns))
splitter = re.compile(delimiter)
with _open(filename, mode='r') as input_file:
for row, line in enumerate(input_file, 1):
data = splitter.split(line.strip(), n_columns - 1)
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:
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)
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, 22; 6, 37; 7, if_statement; 7, 8; 7, 14; 8, comparison_operator:==; 8, 9; 8, 13; 9, call; 9, 10; 9, 11; 10, identifier:_n_onset_midi; 11, argument_list; 11, 12; 12, identifier:reference_patterns; 13, integer:0; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:warnings; 19, identifier:warn; 20, argument_list; 20, 21; 21, string:'Reference patterns are empty.'; 22, if_statement; 22, 23; 22, 29; 23, comparison_operator:==; 23, 24; 23, 28; 24, call; 24, 25; 24, 26; 25, identifier:_n_onset_midi; 26, argument_list; 26, 27; 27, identifier:estimated_patterns; 28, integer:0; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:warnings; 34, identifier:warn; 35, argument_list; 35, 36; 36, string:'Estimated patterns are empty.'; 37, for_statement; 37, 38; 37, 39; 37, 42; 38, identifier:patterns; 39, list:[reference_patterns, estimated_patterns]; 39, 40; 39, 41; 40, identifier:reference_patterns; 41, identifier:estimated_patterns; 42, block; 42, 43; 43, for_statement; 43, 44; 43, 45; 43, 46; 44, identifier:pattern; 45, identifier:patterns; 46, block; 46, 47; 46, 62; 47, if_statement; 47, 48; 47, 54; 48, comparison_operator:<=; 48, 49; 48, 53; 49, call; 49, 50; 49, 51; 50, identifier:len; 51, argument_list; 51, 52; 52, identifier:pattern; 53, integer:0; 54, block; 54, 55; 55, raise_statement; 55, 56; 56, call; 56, 57; 56, 58; 57, identifier:ValueError; 58, argument_list; 58, 59; 59, concatenated_string; 59, 60; 59, 61; 60, string:"Each pattern must contain at least one "; 61, string:"occurrence."; 62, for_statement; 62, 63; 62, 64; 62, 65; 63, identifier:occurrence; 64, identifier:pattern; 65, block; 65, 66; 66, for_statement; 66, 67; 66, 68; 66, 69; 67, identifier:onset_midi; 68, identifier:occurrence; 69, block; 69, 70; 70, if_statement; 70, 71; 70, 77; 71, comparison_operator:!=; 71, 72; 71, 76; 72, call; 72, 73; 72, 74; 73, identifier:len; 74, argument_list; 74, 75; 75, identifier:onset_midi; 76, integer:2; 77, block; 77, 78; 78, raise_statement; 78, 79; 79, call; 79, 80; 79, 81; 80, identifier:ValueError; 81, argument_list; 81, 82; 82, concatenated_string; 82, 83; 82, 84; 83, string:"The (onset, midi) tuple must "; 84, string:"contain exactly 2 elements." | def validate(reference_patterns, estimated_patterns):
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, 13; 6, 58; 6, 110; 6, 221; 6, 242; 6, 253; 6, 270; 6, 287; 6, 297; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:validate; 10, argument_list; 10, 11; 10, 12; 11, identifier:reference_patterns; 12, identifier:estimated_patterns; 13, function_definition; 13, 14; 13, 15; 13, 18; 14, function_name:compute_first_layer_PR; 15, parameters; 15, 16; 15, 17; 16, identifier:ref_occs; 17, identifier:est_occs; 18, block; 18, 19; 18, 30; 18, 42; 18, 54; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:s; 22, call; 22, 23; 22, 24; 23, identifier:len; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 27; 26, identifier:_occurrence_intersection; 27, argument_list; 27, 28; 27, 29; 28, identifier:ref_occs; 29, identifier:est_occs; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:precision; 33, binary_operator:/; 33, 34; 33, 35; 34, identifier:s; 35, call; 35, 36; 35, 37; 36, identifier:float; 37, argument_list; 37, 38; 38, call; 38, 39; 38, 40; 39, identifier:len; 40, argument_list; 40, 41; 41, identifier:ref_occs; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:recall; 45, binary_operator:/; 45, 46; 45, 47; 46, identifier:s; 47, call; 47, 48; 47, 49; 48, identifier:float; 49, argument_list; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:est_occs; 54, return_statement; 54, 55; 55, expression_list; 55, 56; 55, 57; 56, identifier:precision; 57, identifier:recall; 58, function_definition; 58, 59; 58, 60; 58, 63; 59, function_name:compute_second_layer_PR; 60, parameters; 60, 61; 60, 62; 61, identifier:ref_pattern; 62, identifier:est_pattern; 63, block; 63, 64; 63, 72; 63, 89; 63, 106; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:F_1; 67, call; 67, 68; 67, 69; 68, identifier:compute_layer; 69, argument_list; 69, 70; 69, 71; 70, identifier:ref_pattern; 71, identifier:est_pattern; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:precision; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:np; 78, identifier:mean; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:np; 83, identifier:max; 84, argument_list; 84, 85; 84, 86; 85, identifier:F_1; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:axis; 88, integer:0; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:recall; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:np; 95, identifier:mean; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:np; 100, identifier:max; 101, argument_list; 101, 102; 101, 103; 102, identifier:F_1; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:axis; 105, integer:1; 106, return_statement; 106, 107; 107, expression_list; 107, 108; 107, 109; 108, identifier:precision; 109, identifier:recall; 110, function_definition; 110, 111; 110, 112; 110, 118; 111, function_name:compute_layer; 112, parameters; 112, 113; 112, 114; 112, 115; 113, identifier:ref_elements; 114, identifier:est_elements; 115, default_parameter; 115, 116; 115, 117; 116, identifier:layer; 117, integer:1; 118, block; 118, 119; 118, 135; 118, 142; 118, 149; 118, 160; 118, 219; 119, if_statement; 119, 120; 119, 127; 120, boolean_operator:and; 120, 121; 120, 124; 121, comparison_operator:!=; 121, 122; 121, 123; 122, identifier:layer; 123, integer:1; 124, comparison_operator:!=; 124, 125; 124, 126; 125, identifier:layer; 126, integer:2; 127, block; 127, 128; 128, raise_statement; 128, 129; 129, call; 129, 130; 129, 131; 130, identifier:ValueError; 131, argument_list; 131, 132; 132, binary_operator:%; 132, 133; 132, 134; 133, string:"Layer (%d) must be an integer between 1 and 2"; 134, identifier:layer; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:nP; 138, call; 138, 139; 138, 140; 139, identifier:len; 140, argument_list; 140, 141; 141, identifier:ref_elements; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:nQ; 145, call; 145, 146; 145, 147; 146, identifier:len; 147, argument_list; 147, 148; 148, identifier:est_elements; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:F; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:np; 155, identifier:zeros; 156, argument_list; 156, 157; 157, tuple; 157, 158; 157, 159; 158, identifier:nP; 159, identifier:nQ; 160, for_statement; 160, 161; 160, 162; 160, 166; 161, identifier:iP; 162, call; 162, 163; 162, 164; 163, identifier:range; 164, argument_list; 164, 165; 165, identifier:nP; 166, block; 166, 167; 167, for_statement; 167, 168; 167, 169; 167, 173; 168, identifier:iQ; 169, call; 169, 170; 169, 171; 170, identifier:range; 171, argument_list; 171, 172; 172, identifier:nQ; 173, block; 173, 174; 173, 192; 173, 206; 174, if_statement; 174, 175; 174, 178; 174, 183; 175, comparison_operator:==; 175, 176; 175, 177; 176, identifier:layer; 177, integer:1; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:func; 182, identifier:compute_first_layer_PR; 183, elif_clause; 183, 184; 183, 187; 184, comparison_operator:==; 184, 185; 184, 186; 185, identifier:layer; 186, integer:2; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:func; 191, identifier:compute_second_layer_PR; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 197; 194, pattern_list; 194, 195; 194, 196; 195, identifier:precision; 196, identifier:recall; 197, call; 197, 198; 197, 199; 198, identifier:func; 199, argument_list; 199, 200; 199, 203; 200, subscript; 200, 201; 200, 202; 201, identifier:ref_elements; 202, identifier:iP; 203, subscript; 203, 204; 203, 205; 204, identifier:est_elements; 205, identifier:iQ; 206, expression_statement; 206, 207; 207, assignment; 207, 208; 207, 212; 208, subscript; 208, 209; 208, 210; 208, 211; 209, identifier:F; 210, identifier:iP; 211, identifier:iQ; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:util; 215, identifier:f_measure; 216, argument_list; 216, 217; 216, 218; 217, identifier:precision; 218, identifier:recall; 219, return_statement; 219, 220; 220, identifier:F; 221, if_statement; 221, 222; 221, 236; 222, boolean_operator:or; 222, 223; 222, 229; 222, 230; 223, comparison_operator:==; 223, 224; 223, 228; 224, call; 224, 225; 224, 226; 225, identifier:_n_onset_midi; 226, argument_list; 226, 227; 227, identifier:reference_patterns; 228, integer:0; 229, line_continuation:\; 230, comparison_operator:==; 230, 231; 230, 235; 231, call; 231, 232; 231, 233; 232, identifier:_n_onset_midi; 233, argument_list; 233, 234; 234, identifier:estimated_patterns; 235, integer:0; 236, block; 236, 237; 237, return_statement; 237, 238; 238, expression_list; 238, 239; 238, 240; 238, 241; 239, float:0.; 240, float:0.; 241, float:0.; 242, expression_statement; 242, 243; 243, assignment; 243, 244; 243, 245; 244, identifier:F_2; 245, call; 245, 246; 245, 247; 246, identifier:compute_layer; 247, argument_list; 247, 248; 247, 249; 247, 250; 248, identifier:reference_patterns; 249, identifier:estimated_patterns; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:layer; 252, integer:2; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:precision_3; 256, call; 256, 257; 256, 260; 257, attribute; 257, 258; 257, 259; 258, identifier:np; 259, identifier:mean; 260, argument_list; 260, 261; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:np; 264, identifier:max; 265, argument_list; 265, 266; 265, 267; 266, identifier:F_2; 267, keyword_argument; 267, 268; 267, 269; 268, identifier:axis; 269, integer:0; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:recall_3; 273, call; 273, 274; 273, 277; 274, attribute; 274, 275; 274, 276; 275, identifier:np; 276, identifier:mean; 277, argument_list; 277, 278; 278, call; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:np; 281, identifier:max; 282, argument_list; 282, 283; 282, 284; 283, identifier:F_2; 284, keyword_argument; 284, 285; 284, 286; 285, identifier:axis; 286, integer:1; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 290; 289, identifier:f_measure_3; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:util; 293, identifier:f_measure; 294, argument_list; 294, 295; 294, 296; 295, identifier:precision_3; 296, identifier:recall_3; 297, return_statement; 297, 298; 298, expression_list; 298, 299; 298, 300; 298, 301; 299, identifier:f_measure_3; 300, identifier:precision_3; 301, identifier:recall_3 | def three_layer_FPR(reference_patterns, estimated_patterns):
validate(reference_patterns, estimated_patterns)
def compute_first_layer_PR(ref_occs, est_occs):
s = len(_occurrence_intersection(ref_occs, est_occs))
precision = s / float(len(ref_occs))
recall = s / float(len(est_occs))
return precision, recall
def compute_second_layer_PR(ref_pattern, est_pattern):
F_1 = compute_layer(ref_pattern, est_pattern)
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):
if layer != 1 and layer != 2:
raise ValueError("Layer (%d) must be an integer between 1 and 2"
% layer)
nP = len(ref_elements)
nQ = len(est_elements)
F = np.zeros((nP, nQ))
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
precision, recall = func(ref_elements[iP], est_elements[iQ])
F[iP, iQ] = util.f_measure(precision, recall)
return F
if _n_onset_midi(reference_patterns) == 0 or \
_n_onset_midi(estimated_patterns) == 0:
return 0., 0., 0.
F_2 = compute_layer(reference_patterns, estimated_patterns, layer=2)
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, 46; 28, 64; 28, 74; 28, 86; 28, 95; 28, 104; 28, 114; 28, 124; 28, 157; 28, 165; 28, 176; 28, 183; 28, 189; 28, 200; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:matching; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:transcription; 35, identifier:match_notes; 36, argument_list; 36, 37; 36, 38; 36, 39; 36, 40; 36, 41; 36, 42; 36, 43; 36, 44; 36, 45; 37, identifier:ref_intervals; 38, identifier:ref_pitches; 39, identifier:est_intervals; 40, identifier:est_pitches; 41, identifier:onset_tolerance; 42, identifier:pitch_tolerance; 43, identifier:offset_ratio; 44, identifier:offset_min_tolerance; 45, identifier:strict; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 51; 48, pattern_list; 48, 49; 48, 50; 49, identifier:min_velocity; 50, identifier:max_velocity; 51, expression_list; 51, 52; 51, 58; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:np; 55, identifier:min; 56, argument_list; 56, 57; 57, identifier:ref_velocities; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:np; 61, identifier:max; 62, argument_list; 62, 63; 63, identifier:ref_velocities; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:velocity_range; 67, call; 67, 68; 67, 69; 68, identifier:max; 69, argument_list; 69, 70; 69, 71; 70, integer:1; 71, binary_operator:-; 71, 72; 71, 73; 72, identifier:max_velocity; 73, identifier:min_velocity; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:ref_velocities; 77, binary_operator:/; 77, 78; 77, 82; 78, parenthesized_expression; 78, 79; 79, binary_operator:-; 79, 80; 79, 81; 80, identifier:ref_velocities; 81, identifier:min_velocity; 82, call; 82, 83; 82, 84; 83, identifier:float; 84, argument_list; 84, 85; 85, identifier:velocity_range; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:matching; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:np; 92, identifier:array; 93, argument_list; 93, 94; 94, identifier:matching; 95, if_statement; 95, 96; 95, 101; 96, comparison_operator:==; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:matching; 99, identifier:size; 100, integer:0; 101, block; 101, 102; 102, return_statement; 102, 103; 103, list:[]; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:ref_matched_velocities; 107, subscript; 107, 108; 107, 109; 108, identifier:ref_velocities; 109, subscript; 109, 110; 109, 111; 109, 113; 110, identifier:matching; 111, slice; 111, 112; 112, colon; 113, integer:0; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:est_matched_velocities; 117, subscript; 117, 118; 117, 119; 118, identifier:est_velocities; 119, subscript; 119, 120; 119, 121; 119, 123; 120, identifier:matching; 121, slice; 121, 122; 122, colon; 123, integer:1; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 129; 126, pattern_list; 126, 127; 126, 128; 127, identifier:slope; 128, identifier:intercept; 129, subscript; 129, 130; 129, 156; 130, call; 130, 131; 130, 136; 131, attribute; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:np; 134, identifier:linalg; 135, identifier:lstsq; 136, argument_list; 136, 137; 136, 155; 137, attribute; 137, 138; 137, 154; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:np; 141, identifier:vstack; 142, argument_list; 142, 143; 143, list:[est_matched_velocities,
np.ones(len(est_matched_velocities))]; 143, 144; 143, 145; 144, identifier:est_matched_velocities; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:np; 148, identifier:ones; 149, argument_list; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:len; 152, argument_list; 152, 153; 153, identifier:est_matched_velocities; 154, identifier:T; 155, identifier:ref_matched_velocities; 156, integer:0; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:est_matched_velocities; 160, binary_operator:+; 160, 161; 160, 164; 161, binary_operator:*; 161, 162; 161, 163; 162, identifier:slope; 163, identifier:est_matched_velocities; 164, identifier:intercept; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:velocity_diff; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:np; 171, identifier:abs; 172, argument_list; 172, 173; 173, binary_operator:-; 173, 174; 173, 175; 174, identifier:est_matched_velocities; 175, identifier:ref_matched_velocities; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:velocity_within_tolerance; 179, parenthesized_expression; 179, 180; 180, comparison_operator:<; 180, 181; 180, 182; 181, identifier:velocity_diff; 182, identifier:velocity_tolerance; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:matching; 186, subscript; 186, 187; 186, 188; 187, identifier:matching; 188, identifier:velocity_within_tolerance; 189, expression_statement; 189, 190; 190, assignment; 190, 191; 190, 192; 191, identifier:matching; 192, list_comprehension; 192, 193; 192, 197; 193, call; 193, 194; 193, 195; 194, identifier:tuple; 195, argument_list; 195, 196; 196, identifier:_; 197, for_in_clause; 197, 198; 197, 199; 198, identifier:_; 199, identifier:matching; 200, return_statement; 200, 201; 201, 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):
matching = transcription.match_notes(
ref_intervals, ref_pitches, est_intervals, est_pitches,
onset_tolerance, pitch_tolerance, offset_ratio, offset_min_tolerance,
strict)
min_velocity, max_velocity = np.min(ref_velocities), np.max(ref_velocities)
velocity_range = max(1, max_velocity - min_velocity)
ref_velocities = (ref_velocities - min_velocity)/float(velocity_range)
matching = np.array(matching)
if matching.size == 0:
return []
ref_matched_velocities = ref_velocities[matching[:, 0]]
est_matched_velocities = est_velocities[matching[:, 1]]
slope, intercept = np.linalg.lstsq(
np.vstack([est_matched_velocities,
np.ones(len(est_matched_velocities))]).T,
ref_matched_velocities)[0]
est_matched_velocities = slope*est_matched_velocities + intercept
velocity_diff = np.abs(est_matched_velocities - ref_matched_velocities)
velocity_within_tolerance = (velocity_diff < velocity_tolerance)
matching = matching[velocity_within_tolerance]
matching = [tuple(_) for _ in matching]
return matching |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.