Skip to content

Commit 9bffe94

Browse files
Update app.py
1 parent 59b7ba8 commit 9bffe94

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

jobs/account-port-scan/app.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@
3535
"""
3636
authenticator = IAMAuthenticator(apikey=ibmcloud_api_key)
3737

38+
39+
def setup_logging(default_path='logging.json', default_level=logging.info, env_key='LOG_CFG'):
40+
"""
41+
Set up logging configuration and use logging.json to format logs
42+
"""
43+
path = default_path
44+
value = os.getenv(env_key, None)
45+
if value:
46+
path = value
47+
if os.path.exists(path):
48+
with open(path, 'rt') as f:
49+
config = json.load(f)
50+
logging.config.dictConfig(config)
51+
else:
52+
logging.basicConfig(level=default_level)
53+
54+
3855
def sl_iam_client():
3956
"""
4057
Create a SoftLayer client object using the IBM Cloud API key
@@ -47,6 +64,7 @@ def sl_iam_client():
4764
)
4865
return client
4966

67+
5068
def get_regions():
5169
"""
5270
Retrieve a list of IBM Cloud VPC regions
@@ -62,6 +80,7 @@ def get_regions():
6280
logging.error("Unable to retrieve regions: {0}".format(e))
6381
sys.exit()
6482

83+
6584
def get_floating_ips():
6685
"""
6786
Retrieve a list of IBM Cloud VPC floating IPs across all regions
@@ -77,6 +96,7 @@ def get_floating_ips():
7796
floating_ips.append(ip_address)
7897
return floating_ips
7998

99+
80100
def get_classic_infrastructure_instances():
81101
"""
82102
Retrieve of public IPs associated with classic
@@ -91,6 +111,7 @@ def get_classic_infrastructure_instances():
91111
classic_host_ips.append(vm['primaryIpAddress'])
92112
return classic_host_ips
93113

114+
94115
def get_classic_infrastructure_hardware():
95116
"""
96117
Retrieve of public IPs associated with classic
@@ -126,6 +147,7 @@ def scan_top_ports(target):
126147
pass
127148
return open_ports
128149

150+
129151
def main():
130152
"""
131153
Main function to scan IBM Cloud VPC and classic infrastructure
@@ -154,5 +176,6 @@ def main():
154176
logging.info(f"Open ports on {target}: {open_ports}")
155177
print("Classic Bare Metals Scan complete.")
156178

179+
157180
if __name__ == "__main__":
158181
main()

0 commit comments

Comments
 (0)