diff options
-rw-r--r-- | kpov_judge/tasks/snmp_agent_uptime/task.py | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/kpov_judge/tasks/snmp_agent_uptime/task.py b/kpov_judge/tasks/snmp_agent_uptime/task.py index f007eec..0c24235 100644 --- a/kpov_judge/tasks/snmp_agent_uptime/task.py +++ b/kpov_judge/tasks/snmp_agent_uptime/task.py @@ -18,8 +18,9 @@ Poskrbi, da bo SNMP strežnik prek SNMP pod OID {SNMP_UPTIME_OID} sporočal, koliko casa je vklopljen v sekundah. -Napiši skripto, poimenovano beri.sh, ki prek SNMP prebere vrednost s strežnika - SNMPServer na OID {SNMP_CLIENT_OID} +Napiši skripto, poimenovano beri.sh, ki prek SNMP prebere vrednost s +simpleArbiterDhcpGWSNMP na OID {SNMP_CLIENT_OID} kot član skupnosti +"testers". Postavi jo na SNMP klienta, v domaci imenik uporabnika test z geslom test. @@ -34,8 +35,10 @@ of the user test with the password test. Make sure that the SNMP server reports it's uptime in seconds over SNMP under OID {SNMP_UPTIME_OID}. -Write a script called beri.sh that reads the value from the OID {SNMP_CLIENT_OID} -on SNMPServer. Set it up on SNMPClient in the home directory of the user test. +Write a script called beri.sh that reads the value from the OID +{SNMP_CLIENT_OID} on simpleArbiterDhcpGWSNMP as a member of the +community "testers". +Set it up on SNMPClient in the home directory of the user test. Make all the data available over SNMP readable by the "studentje" community. """ @@ -75,7 +78,7 @@ computers = { 'SimpleArbiter': { 'disks': [ - { 'name': 'simpleArbiterDhcpGW', + { 'name': 'simpleArbiterDhcpGWSNMP', # attempt automount }, #{ 'name': 'CDROM', @@ -112,7 +115,7 @@ def task(SERVER_IP, CLIENT_IP, SNMP_UPTIME_OID, SNMP_CLIENT_OID): client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - client.connect(SERVER_IP, username='root', password='kaboom') + client.connect(SERVER_IP, username='student', password='vaje') stdin, stdout, stderr = client.exec_command('uptime=$(</proc/uptime); uptime=${uptime%%.*}; echo $uptime') return_results['server_uptime'] = stdout.read() @@ -131,8 +134,7 @@ def task(SERVER_IP, CLIENT_IP, SNMP_UPTIME_OID, SNMP_CLIENT_OID): print ('ERROR: Occurred during SNMPget for OID %s from %s: ' '(%s)') % (SNMP_UPTIME_OID, CLIENT_IP, exception_error) sys.exit(2) - - + client.connect(CLIENT_IP, username='test', password='test') stdin, stdout, stderr = client.exec_command('uptime=$(</proc/uptime); uptime=${uptime%%.*}; echo $(( uptime ))') return_results['client_uptime'] = stdout.read() @@ -204,17 +206,27 @@ def prepare_disks(templates, task_params, global_params): # d = templates['simpleArbiterDhcp'] prog = """#!/usr/bin/python import sys -oid = sys.argv[2] action = sys.argv[1] -if action == '-g' and oid == ".{oid}": - print ".{oid}" - print "string" - print "{val}" -elif action == '-n' and oid < ".{oid}": - print ".{oid}" +oid = sys.argv[2] + +foo_oid = ".{oid}" +foo_oid_start = foo_oid[:foo_oid.rfind('.')] +foo_oid_end = foo_oid[len(foo_oid_start)+1:] +oid_end = oid[len(foo_oid_start)+1:] +oid_start = oid[:len(foo_oid_start)] + +if action == '-n' and ( + (oid_start == foo_oid_start) and ( + (len(oid_end) == 0) or (int(oid_end) < int(foo_oid_end)) + ) + ): + oid = foo_oid + +if action != '-s' and oid == foo_oid: + print foo_oid print "string" print "{val}" """.format(oid = task_params['SNMP_CLIENT_OID'], val = task_params['SNMP_VALUE']) - templates['student-SNMPServer'].write('/usr/local/bin/snmpext.py', prog) - templates['student-SNMPServer'].chmod(0755, '/usr/local/bin/snmpext.py') - write_default_config(templates['simpleArbiterDhcpGW'], global_params) + templates['simpleArbiterDhcpGWSNMP'].write('/usr/local/bin/snmpext.py', prog) + templates['simpleArbiterDhcpGWSNMP'].chmod(0755, '/usr/local/bin/snmpext.py') + write_default_config(templates['simpleArbiterDhcpGWSNMP'], global_params) |