Skip to content

Commit fa0617e

Browse files
committed
cleanup
1 parent affd9c9 commit fa0617e

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed

check-hostname.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
import sys
77

88

9-
def get_hostname():
10-
"""Get the system's hostname."""
11-
return socket.gethostname()
12-
13-
14-
def get_fqdn():
15-
"""Get the system's fully qualified domain name."""
16-
return socket.getfqdn()
17-
18-
199
def get_ips_for_hostname(hostname):
2010
"""Get all IP addresses associated with the hostname."""
2111
try:
@@ -55,20 +45,9 @@ def ping_target(target):
5545
return False
5646

5747

58-
# Maintain backwards compatibility with original function names
59-
def ping_hostname(hostname):
60-
"""Ping a hostname directly and return whether it was successful."""
61-
return ping_target(hostname)
62-
63-
64-
def ping_ip(ip):
65-
"""Ping an IP address and return whether it was successful."""
66-
return ping_target(ip)
67-
68-
6948
def run_checks_for_target(target_name, target_value):
7049
"""Run all checks for a given target (hostname or FQDN).
71-
50+
7251
Returns:
7352
bool: True if all checks passed, False if any failed
7453
"""
@@ -97,37 +76,37 @@ def run_checks_for_target(target_name, target_value):
9776
# Ping each IP
9877
print(f"\nPinging IP addresses for {target_value}:")
9978
for ip in ips:
100-
success = ping_ip(ip)
79+
success = ping_target(ip)
10180
status = "successful" if success else "failed"
10281
print(f" Ping to {ip}: {status}")
10382
if not success:
10483
has_failures = True
105-
84+
10685
return not has_failures
10786

10887

10988
def main():
11089
# Get hostname and FQDN
111-
hostname = get_hostname()
112-
fqdn = get_fqdn()
113-
90+
hostname = socket.gethostname()
91+
fqdn = socket.getfqdn()
92+
11493
all_passed = True
11594

11695
# Run checks for hostname
11796
hostname_passed = run_checks_for_target("Hostname", hostname)
11897
if not hostname_passed:
11998
all_passed = False
120-
121-
print("\n" + "="*50 + "\n")
122-
99+
100+
print("\n" + "=" * 50 + "\n")
101+
123102
# Run checks for FQDN (only if different from hostname)
124103
if fqdn != hostname:
125104
fqdn_passed = run_checks_for_target("FQDN", fqdn)
126105
if not fqdn_passed:
127106
all_passed = False
128107
else:
129108
print(f"FQDN is the same as hostname: {fqdn}")
130-
109+
131110
# Exit with appropriate status code
132111
if not all_passed:
133112
print("\nSome checks failed. Exiting with status code 1.")

0 commit comments

Comments
 (0)