Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] Monitoring swith-y
Forum PHP.pl > Forum > Przedszkole
redelek
Witam,

Mam w firmie swith-e CISCO, poprzez www można oglądać statystyki każdego gniazdka ile danych wysłał ile odebrał.
Niestety dane te są czystym tekstem w prostym HTML-u. I tu moje pytanie
czy wiecie jak i czy wogóle można pobrać wartości z takiej sieczki

FastEthernet0/5 is up, line protocol is up
Hardware is Fast Ethernet, address is 0004.27dc.0345 (bia 0004.27dc.0345)
Description: GM3/22
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive not set
Auto-duplex (Full), Auto Speed (100), 100BaseTX/FX
ARP type: ARPA, ARP Timeout 04:00:00
Last input 00:00:26, output 00:00:26, output hang never
Last clearing of "show interface" counters never
Queueing strategy: fifo
Output queue 0/40, 0 drops; input queue 0/75, 0 drops
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 1000 bits/sec, 1 packets/sec
2481810 packets input, 1426225855 bytes
Received 82915 broadcasts, 0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
0 watchdog, 21650 multicast
0 input packets with dribble condition detected
4037360 packets output, 1553305833 bytes, 0 underruns
0 output errors, 0 collisions, 1 interface resets
0 babbles, 0 late collision, 0 deferred
0 lost carrier, 0 no carrier
0 output buffer failures, 0 output buffers swapped out

Przykładowe wartości które by mnie interesowały pogróbiłem. Czy można to jakoś pobrać czy raczej nierealne to jest ?

Dzięki za info i wskazówki

Redelek
anonim1133
file() odpowiednie linijki explode na "," - przecinek biggrin.gif albo wyrażenia regularne ?
redelek
Cytat(anonim1133 @ 6.02.2008, 17:50:46 ) *
file() odpowiednie linijki explode na "," - przecinek biggrin.gif albo wyrażenia regularne ?


Ale to nie jest zapisane w pliku tylko przez www to pobieram i muszę się logować żeby to zobaczyć.
Jak by było w pliku zapisane to bym sobie poradził, ale ja nato wchodzę tak
http://192.168.1.2/sw2/statistic

i tu mi się wyświetlają dane

Pozdrawiam
Redelek
webdice
Skorzystaj z cURL, a następnie z wyrażeń regularnych.
redelek
Cytat(webdicepl @ 6.02.2008, 19:25:04 ) *
Skorzystaj z cURL, a następnie z wyrażeń regularnych.


A jakiś przykład hmm troszkę utknąłem zrobiłem tak
  1. <?php
  2. $link = curl_init('http://192.168.1.198/exec/show/interfaces/CR');
  3. curl_setopt($link, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  4. curl_setopt($link, CURLOPT_USERPWD, 'cadmin:tajne haslo');
  5.  
  6. $wynik=curl_exec($link);
  7. curl_close($link);
  8. if (ereg('FastEthernet0/1', $wynik)) {
  9. echo "ZNALEZIONO: wyraz FastEthernet0/1 wystąpił w napisie '$wynik'";
  10. } else {
  11. echo "NIE ZNALEZIONO: wyraz FastEthernet0/1 nie wystąpił w napisie '$wynik'";
  12. }
  13.  
  14. ?>


I zwraca mi że nie znaleziono , a w $wynik ma wartosc 1

Pozdrawiam
Redelek
nowotny
Musisz sobie dodać ustawienie:
  1. <?php
  2. curl_setopt($link, CURLOPT_RETURNTRANSFER,1);
  3. ?>
redelek
Cytat(nowotny @ 7.02.2008, 11:47:34 ) *
Musisz sobie dodać ustawienie:
  1. <?php
  2. curl_setopt($link, CURLOPT_RETURNTRANSFER,1);
  3. ?>


Nie śmiejcie się ale walczę dalej.
Doszedłem do tego że pokazuje w którym wierszu jest to co mnie interesuje

  1. <?php
  2.  
  3. $i=1;
  4. while ($i < 25){
  5.  
  6.  
  7. if(($id = strpos($wynik, 'FastEthernet0/'.$i.'')) !== false) 
  8. {
  9. echo $id.'<br>';
  10. }
  11.  
  12. $i++;
  13. }
  14. ?>


wynik jest taki
1
1194
2388
3585
Jak teraz znając ten numerek pobrać ten tekst FastEthernet0/1 ?

Dzięki za pomoc i wyrozumiałość

Redelek
nowotny
Pokaż pełny kod źródłowy, czyli zawartość zmiennej $wynik bo to w pierwszyp poście nie wygląda jak źródło strony...
redelek
Cytat(nowotny @ 7.02.2008, 14:37:00 ) *
Pokaż pełny kod źródłowy, czyli zawartość zmiennej $wynik bo to w pierwszyp poście nie wygląda jak źródło strony...


Mam za długi i niemieście się

  1. <form method="post" action="/exec/show/interfaces/CR">
  2. VLAN1 is up, line protocol is up
  3. Hardware is CPU Interface, address is 0004.27dc.2b40 (bia 0004.27dc.2b40)
  4. Internet address is 192.168.1.198/24
  5. MTU 1500 bytes, BW 10000 Kbit, DLY 1000 usec,
  6. reliability 255/255, txload 1/255, rxload 1/255
  7. Encapsulation ARPA, loopback not set
  8. ARP type: ARPA, ARP Timeout 04:00:00
  9. Last input 00:00:00, output 00:00:00, output hang never
  10. Last clearing of "show interface" counters never
  11. Queueing strategy: fifo
  12. Output queue 0/40, 0 drops; input queue 0/75, 0 drops
  13. 5 minute input rate 0 bits/sec, 0 packets/sec
  14. 5 minute output rate 0 bits/sec, 0 packets/sec
  15. 1360671 packets input, 112528539 bytes, 0 no buffer
  16. Received 1360211 broadcasts, 0 runts, 0 giants, 0 throttles
  17. 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
  18. 0 input packets with dribble condition detected
  19. 455 packets output, 117985 bytes, 0 underruns
  20. 0 output errors, 0 collisions, 0 interface resets
  21. 0 babbles, 0 late collision, 0 deferred
  22. 0 lost carrier, 0 no carrier
  23. 0 output buffer failures, 0 output buffers swapped out
  24. FastEthernet0/1 is up, line protocol is up
  25. Hardware is Fast Ethernet, address is 0004.27dc.2b41 (bia 0004.27dc.2b41)
  26. Description: GM1/02
  27. MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
  28. reliability 255/255, txload 1/255, rxload 1/255
  29. Encapsulation ARPA, loopback not set
  30. Keepalive not set
  31. Auto-duplex (Full), Auto Speed (100), 100BaseTX/FX
  32. ARP type: ARPA, ARP Timeout 04:00:00
  33. Last input never, output 00:00:53, output hang never
  34. Last clearing of "show interface" counters never
  35. Queueing strategy: fifo
  36. Output queue 0/40, 0 drops; input queue 0/75, 0 drops
  37. 5 minute input rate 2000 bits/sec, 1 packets/sec
  38. 5 minute output rate 3000 bits/sec, 3 packets/sec
  39. 11297196 packets input, 3874223968 bytes
  40. Received 48457 broadcasts, 0 runts, 0 giants, 0 throttles
  41. 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
  42. 0 watchdog, 24835 multicast
  43. 0 input packets with dribble condition detected
  44. 10828076 packets output, 3619569789 bytes, 0 underruns
  45. 0 output errors, 0 collisions, 1 interface resets
  46. 0 babbles, 0 late collision, 0 deferred
  47. 0 lost carrier, 0 no carrier
  48. 0 output buffer failures, 0 output buffers swapped out
  49. FastEthernet0/2 is up, line protocol is up
  50. Hardware is Fast Ethernet, address is 0004.27dc.2b42 (bia 0004.27dc.2b42)
  51. Description: GM3/12
  52. MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
  53. reliability 255/255, txload 1/255, rxload 1/255
  54. Encapsulation ARPA, loopback not set
  55. Keepalive not set
  56. Auto-duplex (Full), Auto Speed (100), 100BaseTX/FX
  57. ARP type: ARPA, ARP Timeout 04:00:00
  58. Last input 00:00:41, output 00:00:53, output hang never
  59. Last clearing of "show interface" counters never
  60. Queueing strategy: fifo
  61. Output queue 0/40, 0 drops; input queue 0/75, 0 drops
  62. 5 minute input rate 1000 bits/sec, 2 packets/sec
  63. 5 minute output rate 2000 bits/sec, 2 packets/sec
  64. 4474099 packets input, 1081558187 bytes
  65. Received 77789 broadcasts, 0 runts, 0 giants, 0 throttles
  66. 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
  67. 0 watchdog, 34105 multicast
  68. 0 input packets with dribble condition detected
  69. 7196714 packets output, 1130345050 bytes, 0 underruns
  70. 0 output errors, 0 collisions, 1 interface resets
  71. 0 babbles, 0 late collision, 0 deferred
  72. 0 lost carrier, 0 no carrier
  73. 0 output buffer failures, 0 output buffers swapped out
  74. FastEthernet0/3 is up, line protocol is up
  75. Hardware is Fast Ethernet, address is 0004.27dc.2b43 (bia 0004.27dc.2b43)
  76. Description: GM3/24
  77. MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
  78. reliability 255/255, txload 1/255, rxload 1/255
  79. Encapsulation ARPA, loopback not set
  80. Keepalive not set
  81. Auto-duplex (Full), Auto Speed (100), 100BaseTX/FX
  82. ARP type: ARPA, ARP Timeout 04:00:00
  83. Last input 00:00:58, output 00:00:53, output hang never
  84. Last clearing of "show interface" counters never
  85. Queueing strategy: fifo
  86. Output queue 0/40, 0 drops; input queue 0/75, 0 drops
  87. 5 minute input rate 4000 bits/sec, 8 packets/sec
  88. 5 minute output rate 147000 bits/sec, 14 packets/sec
  89. 3447754 packets input, 1067112477 bytes
  90. Received 33713 broadcasts, 0 runts, 0 giants, 0 throttles
  91. 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
  92. 0 watchdog, 22610 multicast
  93. 0 input packets with dribble condition detected
  94. 6201582 packets output, 1361692681 bytes, 0 underruns
  95. 0 output errors, 0 collisions, 1 interface resets
  96. 0 babbles, 0 late collision, 0 deferred
  97. 0 lost carrier, 0 no carrier
  98. 0 output buffer failures, 0 output buffers swapped out
  99. FastEthernet0/4 is up, line protocol is up
  100. Hardware is Fast Ethernet, address is 0004.27dc.2b44 (bia 0004.27dc.2b44)
  101. Description: GM3/40
  102. MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
  103. reliability 255/255, txload 1/255, rxload 1/255
  104. Encapsulation ARPA, loopback not set
  105. Keepalive not set
  106. Auto-duplex (Full), Auto Speed (100), 100BaseTX/FX
  107. ARP type: ARPA, ARP Timeout 04:00:00
  108. Last input never, output 00:00:53, output hang never
  109. Last clearing of "show interface" counters never
  110. Queueing strategy: fifo
  111. Output queue 0/40, 0 drops; input queue 0/75, 0 drops
  112. 5 minute input rate 0 bits/sec, 0 packets/sec
  113. 5 minute output rate 1000 bits/sec, 2 packets/sec
  114. 1238664 packets input, 403439143 bytes
  115. Received 123806 broadcasts, 0 runts, 0 giants, 0 throttles
  116. 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
  117. 0 watchdog, 64238 multicast
  118. 0 input packets with dribble condition detected
  119. 2895623 packets output, 1598856061 bytes, 0 underruns
  120. 0 output errors, 0 collisions, 1 interface resets
  121. 0 babbles, 0 late collision, 0 deferred
  122. 0 lost carrier, 0 no carrier
  123. 0 output buffer failures, 0 output buffers swapped out
  124.  
  125.  
  126. </form></html>
nowotny
Ok... widze że jednak taka kompletna sieczka...
Widze że tu masz kilka interfejsów (FastEthernet0/1, FastEthernet0/2, ...) interesuje cię jeden konkretny czy wszystkie po kolei...?
redelek
Cytat(nowotny @ 7.02.2008, 15:21:58 ) *
Ok... widze że jednak taka kompletna sieczka...
Widze że tu masz kilka interfejsów (FastEthernet0/1, FastEthernet0/2, ...) interesuje cię jeden konkretny czy wszystkie po kolei...?

wszystkie po kolei FastEthernet0/x i dane wysłane i odebrane w pierwszym poście zaznaczyłem które dokładnie.
nowotny
  1. <?php
  2. preg_match_all('#(?:^|\n[^s])(.+)buffers swapped out#Us',$string,$w);//najpierw wydzielamy sobie poszczegolne interfejsy...
  3. foreach ($w[0] as $key=>$interf){//potem w kazdym z tych wydzielonych kawalkow szukamy co nam potrzebne...
  4. preg_match('#^(.+) is#U',trim($interf),$m);
  5. $out[$key]['name']=$m[1];
  6.  
  7. preg_match('#s+[0-9]+ packets input, ([0-9]+) bytes#U',trim($interf),$m);
  8. $out[$key]['bytes_in']=$m[1];
  9.  
  10. preg_match('#s+[0-9]+ packets output, ([0-9]+) bytes#U',trim($interf),$m);
  11. $out[$key]['bytes_out']=$m[1];
  12.  
  13. }
  14. print_r($out);
  15. ?>
redelek
Cytat(nowotny @ 7.02.2008, 16:03:30 ) *
  1. <?php
  2. preg_match_all('#(?:^|\n[^s])(.+)buffers swapped out#Us',$string,$w);//najpierw wydzielamy sobie poszczegolne interfejsy...
  3. foreach ($w[0] as $key=>$interf){//potem w kazdym z tych wydzielonych kawalkow szukamy co nam potrzebne...
  4. preg_match('#^(.+) is#U',trim($interf),$m);
  5. $out[$key]['name']=$m[1];
  6.  
  7. preg_match('#s+[0-9]+ packets input, ([0-9]+) bytes#U',trim($interf),$m);
  8. $out[$key]['bytes_in']=$m[1];
  9.  
  10. preg_match('#s+[0-9]+ packets output, ([0-9]+) bytes#U',trim($interf),$m);
  11. $out[$key]['bytes_out']=$m[1];
  12.  
  13. }
  14. print_r($out);
  15. ?>


dobra a jakieś małe objaśnienie bo skrypt zaczyna mi się od cURL

$link = curl_init('http://192.168.1.198/exec/show/interfaces/CR');
curl_setopt($link, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($link, CURLOPT_USERPWD, 'cadmin:tajne');
curl_setopt($link, CURLOPT_RETURNTRANSFER,1);
curl_exec($link);
curl_close($link);
nowotny
Zamiast "$string" wpisz "$wynik" i gra... :/
redelek
Cytat(nowotny @ 7.02.2008, 16:20:57 ) *
Zamiast "$string" wpisz "$wynik" i gra... :/


No tak, ale u mnie wynik wygląda tak

Array ( [name] => FastEthernet0/1 [bytes_in] => [bytes_out] => ) [2]

a jak pobrać cyferki z bytes_in ?
nowotny
Hmm... coś namieszałeś... pokaż jeszcze raz CAŁY kod skryptu jaki masz teraz...
redelek
Cytat(nowotny @ 7.02.2008, 16:34:19 ) *
Hmm... coś namieszałeś... pokaż jeszcze raz CAŁY kod jaki tam masz teraz...


  1. <?php
  2. $link = curl_init('http://192.168.1.198/exec/show/interfaces/CR');
  3. curl_setopt($link, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  4. curl_setopt($link, CURLOPT_USERPWD, 'cadmin:tajnehaslo);
  5. curl_setopt($link, CURLOPT_RETURNTRANSFER,1);
  6. $string = curl_exec($link);
  7. curl_close($link);
  8.  
  9. preg_match_all('#(?:^|\n[^s])(.+)buffers swapped out#Us',$string,$w);//najpierw wydzielamy sobie poszczegolne interfejsy...
  10. foreach ($w[0] as $key=>$interf){//potem w kazdym z tych wydzielonych kawalkow szukamy co nam potrzebne...
  11. preg_match('#^(.+) is#U',trim($interf),$m);
  12. $out[$key]['name']=$m[1];
  13.  
  14. preg_match('#s+[0-9]+ packets input, ([0-9]+) bytes#U',trim($interf),$m);
  15. $out[$key]['bytes_in']=$m[1];
  16.  
  17. preg_match('#s+[0-9]+ packets output, ([0-9]+) bytes#U',trim($interf),$m);
  18. $out[$key]['bytes_out']=$m[1];
  19.  
  20. }
  21. print_r($out);
  22.  
  23. ?>
nowotny
No i dobrze... powinno działać... co ci wyświetla...?
redelek
Cytat(nowotny @ 7.02.2008, 16:38:19 ) *
No i dobrze... powinno działać... co ci wyświetla...?


Takie coś

Array ( [0] => Array ( [name] => [bytes_in] => [bytes_out] => ) [1] => Array ( [name] => FastEthernet0/1 [bytes_in] => [bytes_out] => ) [2] => Array ( [name] => FastEthernet0/2 [bytes_in] => [bytes_out] => ) [3] => Array ( [name] => FastEthernet0/3 [bytes_in] => [bytes_out] => ) [4] => Array ( [name] => FastEthernet0/4 [bytes_in] => [bytes_out] => ) [5] => Array ( [name] => FastEthernet0/5 [bytes_in] => [bytes_out] => ) [6] => Array ( [name] => FastEthernet0/6 [bytes_in] => [bytes_out] => ) [7] => Array ( [name] => FastEthernet0/7 [bytes_in] => [bytes_out] => ) [8] => Array ( [name] => FastEthernet0/8 [bytes_in] => [bytes_out] => ) [9] => Array ( [name] => FastEthernet0/9 [bytes_in] => [bytes_out] => ) [10] => Array ( [name] => FastEthernet0/10 [bytes_in] => [bytes_out] => ) [11] => Array ( [name] => FastEthernet0/11 [bytes_in] => [bytes_out] => ) [12] => Array ( [name] => FastEthernet0/12 [bytes_in] => [bytes_out] => ) [13] => Array ( [name] => FastEthernet0/13 [bytes_in] => [bytes_out] => ) [14] => Array ( [name] => FastEthernet0/14 [bytes_in] => [bytes_out] => ) [15] => Array ( [name] => FastEthernet0/15 [bytes_in] => [bytes_out] => ) [16] => Array ( [name] => FastEthernet0/16 [bytes_in] => [bytes_out] => ) [17] => Array ( [name] => FastEthernet0/17 [bytes_in] => [bytes_out] => ) [18] => Array ( [name] => FastEthernet0/18 [bytes_in] => [bytes_out] => ) [19] => Array ( [name] => FastEthernet0/19 [bytes_in] => [bytes_out] => ) [20] => Array ( [name] => FastEthernet0/20 [bytes_in] => [bytes_out] => ) [21] => Array ( [name] => FastEthernet0/21 [bytes_in] => [bytes_out] => ) [22] => Array ( [name] => FastEthernet0/22 [bytes_in] => [bytes_out] => ) [23] => Array ( [name] => FastEthernet0/23 [bytes_in] => [bytes_out] => ) [24] => Array ( [name] => FastEthernet0/24 [bytes_in] => [bytes_out] => ) [25] => Array ( [name] => GigabitEthernet0/1 [bytes_in] => [bytes_out] => ) [26] => Array ( [name] => GigabitEthernet0/2 [bytes_in] => [bytes_out] => ) )
nowotny
Dodaj
  1. <?php
  2. file_put_contents('zrzut.txt',$string);
  3. ?>

potem spakuj plik zrzut.txt i wystaw mi gdzieś do ściągnięcia...
redelek
Cytat(nowotny @ 7.02.2008, 16:49:11 ) *
Dodaj
  1. <?php
  2. file_put_contents('zrzut.txt',$string);
  3. ?>

potem spakuj plik zrzut.txt i wystaw mi gdzieś do ściągnięcia...



Tu czeka http://redelek.net/screen/zrzut.txt
nowotny
Teraz powinno działać:
  1. <?php
  2. preg_match_all('#\n[^s](.+)buffers swapped out#Us',strip_tags ($string),$w);//najpierw wydzielamy sobie poszczegolne interfejsy...
  3. foreach ($w[0] as $key=>$interf){//potem w kazdym z tych wydzielonych kawalkow szukamy co nam potrzebne...
  4. preg_match('#(?:\n|^)(.+) is (?:up|down),#U',trim($interf),$m);
  5. $out[$key]['name']=$m[1];
  6.  
  7. preg_match('#s+[0-9]+ packets input, ([0-9]+) bytes#U',trim($interf),$m);
  8. $out[$key]['bytes_in']=$m[1];
  9.  
  10. preg_match('#s+[0-9]+ packets output, ([0-9]+) bytes#U',trim($interf),$m);
  11. $out[$key]['bytes_out']=$m[1];
  12.  
  13. }
  14. print_r($out);
  15. ?>
redelek
Cytat(nowotny @ 7.02.2008, 20:15:36 ) *
Teraz powinno działać:


Oki już pokazuje wartości ale nadal wygląda tak jak poprzednio
czym teraz to ładnie obrobić żeby był tylko

FastEthernet0/1 Bytes in 2121212 bytes out 3213131

a nie tak:

Array ( [0] => Array ( [name] => VLAN1 [bytes_in] => 121720615 [bytes_out] => 3972455 ) [1] => Array ( [name] => FastEthernet0/1 [bytes_in] => 315851646 [bytes_out] => 4087010159 ) [2] => Array ( [name] => FastEthernet0/2 [bytes_in] => 1162457518 [bytes_out] => 1440706852 ) [3] => Array ( [name] => FastEthernet0/3 [bytes_in] => 1103272818 [bytes_out] => 1836174204 ) [4] => Array ( [name] => FastEthernet0/4 [bytes_in] => 424214476 [bytes_out] => 1664666314 )
nowotny
Przeleć się po tablicy $out i wyświetl sobie jak tam chcesz... to już jest proste...
redelek
Cytat(nowotny @ 8.02.2008, 10:48:20 ) *
Przeleć się po tablicy $out i wyświetl sobie jak tam chcesz... to już jest proste...


hmm nio tak,

ale jak robię echo $out['name'];

Proszę jeszcze jeden przykład i wysyłam Ci piwo, albo całą kratkę, albo miejsce na www Ci zrobię smile.gif

Redelek
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.