UPD: various clean up

This commit is contained in:
xpk 2024-03-06 09:51:53 +08:00
parent 7481d96740
commit a474f5f5ef
Signed by: xpk
GPG Key ID: CD4FF6793F09AB86
7 changed files with 66 additions and 2 deletions

5
py/dates-test.py Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/python3
from datetime import datetime
# print (str(datetime.now().year) + "-" + str(datetime.now().month-1))
print (datetime.now().replace(month=datetime.now().month-1).strftime('%Y-%m'))

33
py/ldap-monitor.py Normal file
View File

@ -0,0 +1,33 @@
import json
import socket
import boto3
def lambda_handler(event, context):
hosts=['10.129.72.63', '10.135.72.66', '10.129.72.64', '10.135.72.67']
port=636
timeout_seconds=1
test_results = 0
for host in hosts:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout_seconds)
result = sock.connect_ex((host,int(port)))
if result == 0:
print("Host {}:{} - Up".format(host, port))
test_results += 1
else:
print("Host {}:{} - Down".format(host, port))
sock.close()
if test_results == 4:
return {
'message' : 'Successfully connected to all LDAP servers'
}
else:
raise Exception('Not all LDAP servers can be connected!')
return {
'statusCode': 200,
'body': json.dumps("Finished")
}

13
py/ldaps.py Normal file
View File

@ -0,0 +1,13 @@
import ldap
LDAP_SERVER = 'ldap://192.168.86.87'
BASE_DN = 'dc=acme,dc=local' # base dn to search in
LDAP_LOGIN = 'Administrator'
LDAP_PASSWORD = 'qwerty-asdf-1234'
OBJECT_TO_SEARCH = 'userPrincipalName=Administrator@acme.local'
ATTRIBUTES_TO_SEARCH = ['memberOf']
connect = ldap.initialize(LDAP_SERVER)
connect.set_option(ldap.OPT_REFERRALS, 0) # to search the object and all its descendants
connect.simple_bind_s(LDAP_LOGIN, LDAP_PASSWORD)
result = connect.search_s(BASE_DN, ldap.SCOPE_SUBTREE, OBJECT_TO_SEARCH, ATTRIBUTES_TO_SEARCH)

15
py/port-test.py Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/python3
import socket
hosts=['192.168.86.51', '192.168.86.53']
port=22
timeout_seconds=1
for host in hosts:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout_seconds)
result = sock.connect_ex((host,int(port)))
if result == 0:
print("Host {}:{} - Up".format(host, port))
else:
print("Host {}:{} - Down".format(host, port))
sock.close()

View File

@ -1,2 +0,0 @@
1
2