From 8081a5520a441b43a8a7a73f3a90c7aacfaa8e10 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sun, 24 Feb 2019 21:05:27 +0100 Subject: Move everything one level up --- tasks/snmp_agent_uptime/howtos/en/index.html | 319 +++++++++++++++++++++++++++ tasks/snmp_agent_uptime/howtos/images/01.png | Bin 0 -> 67779 bytes tasks/snmp_agent_uptime/howtos/si/index.html | 308 ++++++++++++++++++++++++++ tasks/snmp_agent_uptime/task.py | 224 +++++++++++++++++++ 4 files changed, 851 insertions(+) create mode 100644 tasks/snmp_agent_uptime/howtos/en/index.html create mode 100644 tasks/snmp_agent_uptime/howtos/images/01.png create mode 100644 tasks/snmp_agent_uptime/howtos/si/index.html create mode 100644 tasks/snmp_agent_uptime/task.py (limited to 'tasks/snmp_agent_uptime') diff --git a/tasks/snmp_agent_uptime/howtos/en/index.html b/tasks/snmp_agent_uptime/howtos/en/index.html new file mode 100644 index 0000000..bef6792 --- /dev/null +++ b/tasks/snmp_agent_uptime/howtos/en/index.html @@ -0,0 +1,319 @@ + + + + snmp_agent_uptime + + +

snmp_agent_uptime

+

Quick instructions

+

+ Set up three virtual computers, SimpleArbiter with the disk image + simpleArbiterDhcp, SNMPServer and SNMPClient. Write a program + called upminutes. This program should output the uptime of the + computer in minutes. Set it up on SNMPClient in the home directory + of the user test with the password test. +

+

+ Make sure that the SNMP server reports it's uptime in seconds + over SNMP under NET-SNMP-EXTEND-MIB::nsExtendOutput2Table. +

+

+ Write a script called beri.sh that reads the value from the + OID 1.3.6.1.4.1.8072.1.3.2.4.1.2 on SNMPServer. Set it up on + SNMPClient in the home directory of the user test. +

+

Instructions

+

Set up of VM VirtualBox

+
    +
  1. + Download the following virtual images (*.vid) from the directory + with images of virtual computers: +
      +
    1. + simpleArbiterDhcp.vdi +
    2. +
    3. + some-bash-console.vdi – twice, one for SNMPServer + and second for SNMPClient +
    4. +
    +
  2. +
  3. + VM VirtualBox WARNING! If you want to use one same virtual image + (some-bash-console.vdi) for two virtual computers + (SNMPServer and SNMPClient), you must change UUID + of one image. +
      +
    1. + Use this command + vboxmanage internalcommands sethduuid name-of-disk.vdi + to change UUID (hint). +
    2. +
    +
  4. +
  5. + Final view of sets VM VirtualBox machines.
    + VM VirtualBox machines +
  6. +
+ +

Set up of SNMPServer machine

+
    +
  1. + setup network as “Bridged Adapter” -> Machine-> Settings ->Network + + Install snmpd and snmp packages and tools for inspecting the + data available over SNMP. +
      +
    1. + command apt-get install snmpd snmp snmp-mibs-downloader +
    2. +
    +
  2. + RECOMMENDATION! Before doing any changes to your /etc/snmp/snmpd.conf + file take a copy of original file. +
      +
    1. + command cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig +
    2. +
    +
  3. +
  4. + Set up the snmp server to allow all other computers to access it = edit + snmpd.conf file. +
      +
    1. + command nano /etc/snmp/snmpd.conf + (you can use different editor) +
    2. +
    3. + Check this 4 rows and make sure they look like this:
      + # Listen for connections from the local system only
      + # agentAddress udp:127.0.0.1:161
      + # Listen for connections on all interfaces (both IPv4 *and* IPv6)
      + agentAddress udp:161,udp6:[::1]:161
      +
    4. +
    +
  5. +
  6. + Add a group (community) of computers we deem to be worthy of + accessing all data. This group will be called students = again edit + snmpd.conf file. +
      +
    1. + rocommunity students 0.0.0.0/0 +
    2. +
    3. + change 0.0.0.0./0 into correct address ifconfig -a +
    4. +
    +
  7. +
  8. + OPTIONAL CONFIGURATION. Lower in the same file you can set the + location of the computer snmpd is running on and the name + of the administrator. +
      +
    1. + find under # SYSTEM INFORMATION +
    2. +
    +
  9. +
  10. + Make sure that the SNMP server reports it's uptime in seconds + over SNMP under NET-SNMP-EXTEND-MIB::nsExtendOutput2Table. +
      +
    1. + create script upseconds containing this and save it where + you want:
      + #!/bin/bash
      + uptime=$(</proc/uptime)
      + seconds=${uptime%%.*}
      + echo "Uptime in seconds:" $seconds
      + exit 0
      +
    2. +
    3. + don't forget to make the script runnable:
      + command chmod +x /your_path_to_script/upseconds +
    4. +
    5. + Then edit file snmpd.conf and under # EXTENDING THE AGENT + comment all three tests and add your line of your code + with upsecond script. It will look like this:
      + # extend test1 /bin/echo Hello, world!
      + # extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35
      + # extend-sh test3 /bin/sh /tmp/shtest
      + extend-sh "your_name" "your_path_to_script_upseconds" +
      +
    6. +
    +
  11. +
  12. + You need to restart the snmp services. +
      +
    1. + command /etc/init.d/snmpd restart +
    2. +
    +
  13. +
  14. + You can test your configuration through localhost. +
      +
    1. + command snmpwalk localhost -c public -v1 +
    2. +
    +
  15. +
  16. + Also test the correct return of server's uptime in seconds SNMP under + NET-SNMP-EXTEND-MIB::nsExtendOutput2Table. +
      +
    1. + command snmpwalk -c students -v1 IPaddressOfServer + 1.3.6.1.4.1.8072.1.3.2.4.1.2 +
    2. +
    3. + you should get string: "Uptime in seconds: xyz" +
    4. +
    +
  17. +
+ +

Set up of SNMPClient machine

+
    +
  1. + Install snmpd and snmp packages. +
      +
    1. + command apt-get install snmpd snmp +
    2. +
    +
  2. + RECOMMENDATION! Before doing any changes to your /etc/snmp/snmpd.conf + file take a copy of original file. +
      +
    1. + command cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig +
    2. +
    +
  3. +
  4. + Set up the snmp client to allow all other computers to access it = edit + snmpd.conf file. +
      +
    1. + command nano /etc/snmp/snmpd.conf + (you can use different editor) +
    2. +
    3. + (un)comment these four lines as below:
      + # Listen for connections from the local system only
      + # agentAddress udp:127.0.0.1:161
      + # Listen for connections on all interfaces (both IPv4 *and* IPv6)
      + agentAddress udp:161,udp6:[::1]:161
      +
    4. +
    +
  5. +
  6. + Add a group (community) of computers we deem to be worthy of + accessing all data. This group will be called students = again edit + snmpd.conf file. +
      +
    1. + rocommunity students 0.0.0.0/0 +
    2. +
    3. + write correct network address = command ifconfig -a +
    4. +
    +
  7. +
  8. + OPTIONAL CONFIGURATION. Lower in the same file you can set the + location of the computer snmpd is running on and the name + of the administrator. +
      +
    1. + find under # SYSTEM INFORMATION +
    2. +
    +
  9. + +
  10. + You need to restart the snmp services. +
      +
    1. + command /etc/init.d/snmpd restart +
    2. +
    +
  11. +
  12. + You can test your configuration through localhost. +
      +
    1. + command snmpwalk localhost -c public -v1 +
    2. +
    +
  13. +
  14. Create the user test with password test +
      +
    1. + command adduser test +
    2. +
    +
  15. +
  16. Login as user test and create program upminutes + in the home directory. This program should output the uptime of the + computer in minutes. +
      +
    1. + command nano upminutes (you can use different editor) +
    2. +
    3. + add the source code:
      + #!/bin/bash
      + uptime=$(</proc/uptime)
      + uptime=${uptime%%.*}
      + minutes=$(( uptime / 60 ))
      + echo $minutes
      + exit 0
      +
    4. +
    5. + don't forget to make the program runnable:
      + command chmod +x /home/test/upminutes +
    6. +
    7. + test the program (it should output the uptime of the + computer in minutes)
      + command /home/test/upminutes +
    8. +
    +
  17. +
  18. As user test and create next script called + beri.sh that reads the value from the OID + 1.3.6.1.4.1.8072.1.3.2.4.1.2. on SNMPServer. Set it up on SNMPClient + in the home directory of the user test. +
      +
    1. + command nano beri.sh (you can use different editor) +
    2. +
    3. + add the source code:
      + #!/bin/bash
      + snmpwalk -c students -v1 IPServerAddress 1.3.6.1.4.1.8072.1.3.2.4.1.2
      + exit 0
      +
    4. +
    5. + don't forget to make the program runnable:
      + command chmod +x /home/test/upminutes + you can test it with ./beri.sh +
    6. +
    +
  19. +
+ +

Setting SimpleArbiter

+ User: tester + Password: test + + apt-get install libsnmp-python + + diff --git a/tasks/snmp_agent_uptime/howtos/images/01.png b/tasks/snmp_agent_uptime/howtos/images/01.png new file mode 100644 index 0000000..1bd01aa Binary files /dev/null and b/tasks/snmp_agent_uptime/howtos/images/01.png differ diff --git a/tasks/snmp_agent_uptime/howtos/si/index.html b/tasks/snmp_agent_uptime/howtos/si/index.html new file mode 100644 index 0000000..f490f6c --- /dev/null +++ b/tasks/snmp_agent_uptime/howtos/si/index.html @@ -0,0 +1,308 @@ + + + + snmp_agent_uptime + + +

snmp_agent_uptime

+

Namen naloge

+

+ +

+

Hitra navodila

+

+ Naloga: Postavi tri navidezne racunalnike SimpleArbiter s sliko diska simpleArbiterDhcp,SNMPServer in + SNMPClient. + Napiši program upminutes, ki bo izpisal v minutah koliko casa je racunalnik vklopljen. + Postavi ga na SNMPClient v domaÄŤi imenik uporabnika test z geslom test. +

+

+ Poskrbi, da bo SNMP strežnik prek SNMP pod NET-SNMP-EXTEND-MIB::nsExtendOutput2Table sporočal, koliko časa je vklopljen v sekundah. +

+

+ Napisi skripto, poimenovano beri.sh, ki prek SNMP prebere vrednost s streĹľnika + SNMPServer na OID 1.3.6.1.4.1.8072.1.3.2.4.1.4. + Postavi jo na SNMP klienta, v domači imenik uporabnika test z geslom test. +

+

Navodila

+

Nastavitev VM VirtualBox-a

+
    +
  1. + Prenesi sledeče slike virtualk (*.vid) iz datoteke + z slikami virtualk računalnikov: +
      +
    1. + simpleArbiterDhcp.vdi +
    2. +
    3. + neko-bash-konzolo.vdi (dvakrat), enkrat za SNMPServer + in drugič SNMPClient. +
    4. +
    +
  2. +
  3. + VM VirtualBox OPOZORILO! Ce hoces uporabljati isto sliko virtualke + (neko-bash-konzolo.vdi) za dva navidezna racunalnika + (SNMPServer in SNMPClient), moras spremeniti UUID + ene od slik. +
      +
    1. + Uporabi ta ukaz + vboxmanage internalcommands sethduuid ime-diska.vdi + za spreminjanje UUID (namig). +
    2. +
    +
  4. +
  5. + Primer VM VirtualBox-a po nastavitvi.
    + +
  6. +
+ +

Nastavitev SNMPServer virtualke

+
    +
  1. + Nasnemi snmpd and snmp orodja za pregledovanje + podatkov, ki so no voljo preko SNMP. +
      +
    1. + ukaz apt-get install snmpd snmp snmp-mibs-downloader +
    2. +
    +
  2. + PRIPOROCILO! Preden spreminjate vaso datoteko /etc/snmp/snmpd.conf, + naredite kopijo originalne datoteke. +
      +
    1. + ukaz cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig +
    2. +
    +
  3. +
  4. + Nastavi snmp streznik tako, da se bodo lahko nanj povezali drugi racunalniki + (popravi datoteko snmpd.conf). +
      +
    1. + ukaz nano /etc/snmp/snmpd.conf + (lahko uporabis drug urejevalnik besedila) +
    2. +
    3. + odkomentiraj sledece stiri vrstice:
      + # Listen for connections from the local system only
      + # agentAddress udp:127.0.0.1:161
      + # Listen for connections on all interfaces (both IPv4 *and* IPv6)
      + agentAddress udp:161,udp6:[::1]:161
      +
    4. +
    +
  5. +
  6. + Dodaj skupino (community) racunalnikov, ki lahko dostopajo do vseh podatkov. + To skupino bomo poimenovali students (spet potrebno spremeniti datoteko) + snmpd.conf file. +
      +
    1. + rocommunity students 0.0.0.0/0 +
    2. +
    3. + napisi pravilni naslov omrezja = ukaz ifconfig -a +
    4. +
    +
  7. +
  8. + DODATNA (NEOBVEZNA) KONFIGURACIJA. Nizje v isti datoteki lahko nastavis + lokacijo racunalnika, na katerem deluje snmp, ter ime administratorja. +
      +
    1. + poisci pod # SYSTEM INFORMATION +
    2. +
    +
  9. +
  10. + Poskrbi, da bo SNMP streznik prek SNMP pod NET-SNMP-EXTEND-MIB::nsExtendOutpucd + k t2Table sporocal, koliko casa je vklopljen v sekundah. +
      +
    1. + ustvari skripto upseconds, v kateri je zapisano sledece:
      + #!/bin/bash
      + uptime=$(</proc/uptime)
      + seconds=${uptime%%.*}
      + echo "Uptime in seconds:" $seconds
      + exit 0

      + skripto nato shrani kjerkoli hoces +
    2. +
    3. + ne pozabi skripti dodelti pravic, da jo lahko zaganjamo:
      + ukaz chmod +x /pot_do_skripte/upseconds +
    4. +
    5. + Nato uredi datoteko snmpd.conf in pod # EXTENDING THE AGENT + zakomentiraj vse tri teste ter dodaj svojo skripto upseconds. + Zgledati bi moralo nekako tako:
      + # extend test1 /bin/echo Hello, world!
      + # extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35
      + # extend-sh test3 /bin/sh /tmp/shtest
      + extend-sh "ime_testa" "pot_to_skripte_upseconds" +
      +
    6. +
    +
  11. +
  12. + Potrebno je ponovno zagnati snmp storitev. +
      +
    1. + ukaz /etc/init.d/snmpd restart +
    2. +
    +
  13. +
  14. + Lahko testiras svoje nastavitve preko localhost-a. +
      +
    1. + ukaz snmpwalk localhost -c public -v1 +
    2. +
    +
  15. +
  16. + Stestiraj tudi, ali SNMP vrne pravilni cas delovanja (uptime) v sekundah + pod NET-SNMP-EXTEND-MIB::nsExtendOutput2Table. +
      +
    1. + ukaz snmpwalk -c students -v1 IPnaslovStreznika + 1.3.6.1.4.1.8072.1.3.2.4.1.2 +
    2. +
    3. + moral bi vrniti taksen string: "Uptime in seconds: xyz" +
    4. +
    +
  17. +
+ +

Nastavitev SNMPClient virtualke

+
    +
  1. + Nasnemi snmpd and snmp paketa. +
      +
    1. + ukaz apt-get install snmpd snmp +
    2. +
    +
  2. + PRIPOROCILO! Preden spreminjate vaso datoteko /etc/snmp/snmpd.conf, + naredite kopijo originalne datoteke. +
      +
    1. + ukaz cp /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig +
    2. +
    +
  3. +
  4. + Nastavi snmp streznik tako, da se bodo lahko nanj povezali drugi racunalniki + (popravi datoteko snmpd.conf). +
      +
    1. + ukaz nano /etc/snmp/snmpd.conf + (lahko uporabis drug urejevalnik besedila) +
    2. +
    3. + odkomentiraj sledece stiri vrstice:
      + # Listen for connections from the local system only
      + # agentAddress udp:127.0.0.1:161
      + # Listen for connections on all interfaces (both IPv4 *and* IPv6)
      + agentAddress udp:161,udp6:[::1]:161
      +
    4. +
    +
  5. +
  6. + Dodaj skupino (community) racunalnikov, ki lahko dostopajo do vseh podatkov. + To skupino bomo poimenovali students (spet potrebno spremeniti datoteko) + snmpd.conf file. +
      +
    1. + rocommunity students 0.0.0.0/0 +
    2. +
    3. + napisi pravilni naslov omrezja = ukaz ifconfig -a +
    4. +
    +
  7. +
  8. + DODATNA (NEOBVEZNA) KONFIGURACIJA. Nizje v isti datoteki lahko nastavis + lokacijo racunalnika, na katerem deluje snmp, ter ime administratorja. +
      +
    1. + poisci pod # SYSTEM INFORMATION +
    2. +
    +
  9. + +
  10. + Potrebno je ponovno zagnati snmp storitev. +
      +
    1. + ukaz /etc/init.d/snmpd restart +
    2. +
    +
  11. +
  12. + Lahko testiras svoje nastavitve preko localhost-a. +
      +
    1. + ukaz snmpwalk localhost -c public -v1 +
    2. +
    +
  13. +
  14. Ustvari uporabnika test z geslom test +
      +
    1. + ukaz adduser test +
    2. +
    +
  15. +
  16. Prijavi se kot uporabnik test ter naredi skripto upminutes + v domacem direktoriju. Ta skripta naj izpisuje cas delovanja racunalnika (uptime) v minutah. +
      +
    1. + ukaz nano upminutes (lahko uporabis drug urejevalnik besedila) +
    2. +
    3. + dodaj sledeco kodo:
      + #!/bin/bash
      + uptime=$(</proc/uptime)
      + uptime=${uptime%%.*}
      + minutes=$(( uptime / 60 ))
      + echo $minutes
      + exit 0
      +
    4. +
    5. + ne pozabi skripti dodelti pravic, da jo lahko zaganjamo:
      + ukaz chmod +x /pot_do_skripte/upminutes +
    6. +
    7. + stestiraj skripto (izpisovati bi morala cas delovanja racunalnika (uptime) v minutah)
      + ukaz /home/test/upminutes +
    8. +
    +
  17. +
  18. Kot uporabnik test naredi se eno skripto beri.shm ki bere + vrednosti od OID 1.3.6.1.4.1.8072.1.3.2.4.1.2. + na SNMPServer. Shrani jo na SNMPClient v domac direktorij uporabnika test. +
      +
    1. + ukaz nano beri.sh (lahko uporabis drug urejevalnik besedila) +
    2. +
    3. + dodaj kodo:
      + #!/bin/bash
      + snmpwalk -c students -v1 IPnaslovStreznika 1.3.6.1.4.1.8072.1.3.2.4.1.2
      + exit 0
      +
    4. +
    5. + ne pozabi skripti dodelti pravic, da jo lahko zaganjamo:
      + ukaz chmod +x /pot_do_skripte/upminutes +
    6. +
    +
  19. +
+ + + diff --git a/tasks/snmp_agent_uptime/task.py b/tasks/snmp_agent_uptime/task.py new file mode 100644 index 0000000..919fcb4 --- /dev/null +++ b/tasks/snmp_agent_uptime/task.py @@ -0,0 +1,224 @@ +# kpov_util should be imported by add_assignment.py + +# TODO: finish this. +instructions = { + 'si': '''\ +

+Postavi tri navidezne računalnike: SimpleArbiter, SNMPServer in SNMPClient. + +

+Napiši program upminutes, ki bo izpisal v minutah, koliko časa je racunalnik vklopljen. Postavi ga na SNMPClient v domači imenik uporabnika test z geslom test. + +

+Poskrbi, da bo strežnik SNMP pod OID + +

{{SNMP_UPTIME_OID}}
+ +

+sporočal, koliko časa je vklopljen v sekundah. + +

+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 SNMPClient, v domači imenik uporabnika test. Poskrbi, da bodo podatki na SNMPServer dostopni za skupino (angl. community) studentje. +''', + 'en': '''\ +

+Set up three virtual computers: SimpleArbiter, SNMPServer and SNMPClient. + +

+Write a program called upminutes. This program should output the uptime of the computer in minutes. Set it up on SNMPClient in the home directory of the user test with the password test. + +

+Make sure that the SNMP server reports its 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 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 community studentje. +''', +} + +computers = { + 'SNMPClient': { + 'disks': [ + { 'name': 'student-SNMPClient', + + }, + ], + 'network_interfaces': [{'network': 'net1'}], + 'flavor': 'm1.tiny', + 'config_drive': False + }, + 'SNMPServer': { + 'disks': [ + { 'name': 'student-SNMPServer', + }, + ], + 'network_interfaces': [{'network': 'net1'}], + 'flavor': 'm1.tiny', + 'config_drive': False + + }, + + 'SimpleArbiter': { + 'disks': [ + { 'name': 'simpleArbiterDhcpGWSNMP', + }, + ], + 'network_interfaces': [{'network': 'net1'}, {'network': 'test-net'}], + 'flavor': 'm1.tiny', + 'config_drive': False + } +} + +networks = { 'net1': {'public': False}, 'test-net': {'public': True} } + +params_meta = { + 'SNMP_VALUE': {'descriptions': {'si': 'Vrednost, dostopna prek SNMP', 'en': 'The value available over SNMP'}, 'w': False, 'public':False, 'type': 'short', 'generated': True}, + 'SNMP_UPTIME_OID': {'descriptions': {'si': 'SNMP_UPTIME_OID (za uptime)', 'en': 'SNMP_UPTIME_OID (for the uptime)'}, 'w': False, 'public':True, 'type': 'str', 'generated': True}, + 'SNMP_CLIENT_OID': {'descriptions': {'si': 'SNMP_CLIENT_OID, ki naj ga klient bere', 'en':'The OID that the client should read'}, 'w': False, 'public':True, 'type': 'OID', 'generated': True}, + 'SERVER_IP': {'descriptions': {'si': 'IP SNMP strežnika', 'en':'IP of the SNMP server'}, 'w': True, 'public':True, 'type': 'IP', 'generated': False}, + 'CLIENT_IP': {'descriptions': {'si': 'IP SNMP klienta', 'en': 'IP of the SNMP client'}, 'w': True, 'public':True, 'type': 'IP', 'generated': False}, + +} + +def task(SERVER_IP, CLIENT_IP, SNMP_UPTIME_OID, SNMP_CLIENT_OID): + #<== Aleksander Fujs 6310020 ==> + # TODO popravi IPje + import netsnmp + import paramiko + from paramiko import SSHClient + return_results = {} + + client = SSHClient() + client.load_system_host_keys() + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + client.connect(SERVER_IP, username='student', password='vaje') + stdin, stdout, stderr = client.exec_command('uptime=$( + + +def gen_params(user_id, params_meta): + import random + params = dict() + r = random.Random(user_id) + # You can also create an OID creation function in kpov_util. + # this should probably return params_meta + + #<== Aleksander Fujs 6310020 ==> + params['SNMP_VALUE'] = kpov_util.alnum_gen(r, 64) + params['SNMP_UPTIME_OID'] = 'NET-SNMP-EXTEND-MIB::nsExtendOutLine."{}".1'.format( + kpov_util.hostname_gen(r)) + params['SNMP_CLIENT_OID'] = '1.3.6.1.4.1.8072.2.9999.9999.{}'.format( + r.randint(0, 255)) + #<== Aleksander Fujs 6310020 ==> + + return params + +def task_check(results, params): + #TODO improve regex + import re + score = 0 + hints = [] + client_script_uptime = int(results['client_script'].strip()) + client_uptime = int(results['client_uptime'].strip()) + d = client_uptime - client_script_uptime*60 + if d >= 0 and d < 62: + score += 3 + else: + hints += ["client uptime script output wrong."] + server_uptime = int(results['server_uptime'].strip()) + lines = results['server_OID'].split('\n') + unique_part_start = params['SNMP_UPTIME_OID'].find('"') + unique_part_end = params['SNMP_UPTIME_OID'].find('"', unique_part_start+1) + unique_part = params['SNMP_UPTIME_OID'][unique_part_start+1:unique_part_end] + server_oid = 'iso.3.6.1.4.1.8072.1.3.2.4.1.2.{}.'.format(len(unique_part)) + server_oid += '.'.join([str(ord(i)) for i in unique_part]) + '.1.' + found_uptime = False + for line in lines: + try: + oid, uptime_s = line.split(':') + d = server_uptime - int(uptime_s.strip()) + if oid.strip() == server_oid and d >= -2 and d <= 5: + found_uptime = True + break + except Exception as e: + pass + if len(lines) <= 50 and found_uptime: + score += 3 + else: + hints += ["Uptime not found in server's MDB"] + if results['client_script2'].find(params['SNMP_VALUE']) >= 0: + score += 4 + else: + hints += ["beri.sh not working properly"] + return score, hints + +def prepare_disks(templates, task_params, global_params): +# d = templates['simpleArbiterDhcp'] + prog = """#!/usr/bin/python +import sys +action = sys.argv[1] +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['simpleArbiterDhcpGWSNMP'].write('/usr/local/bin/snmpext.py', prog) + templates['simpleArbiterDhcpGWSNMP'].chmod(0o755, '/usr/local/bin/snmpext.py') + write_default_config(templates['simpleArbiterDhcpGWSNMP'], global_params) -- cgit v1.2.1