Guest User

Untitled

a guest
Apr 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. !/bin/bash
  2. #- Pieter Steyn '08
  3.  
  4. poll_device() {
  5. #Colour Printer
  6.  
  7. colour_black=`snmpget 192.168.229.12:161 -v 1 -c public 1.3.6.1.2.1.43.11.1.1.9.1.1 -Ovq` #Black
  8. colour_cyan=`snmpget 192.168.229.12:161 -v 1 -c public 1.3.6.1.2.1.43.11.1.1.9.1.2 -Ovq` #Cyan
  9. colour_magenta=`snmpget 192.168.229.12:161 -v 1 -c public 1.3.6.1.2.1.43.11.1.1.9.1.3 -Ovq` #Magenta
  10. colour_yellow=`snmpget 192.168.229.12:161 -v 1 -c public 1.3.6.1.2.1.43.11.1.1.9.1.4 -Ovq` #Yellow
  11. colour_tonerdrum=`snmpget 192.168.229.12:161 -v 1 -c public 1.3.6.1.2.1.43.11.1.1.9.1.5 -Ovq` #Toner Drum
  12.  
  13. }
  14.  
  15. create() {
  16. #Create the RRD file if they don't already exist.
  17.  
  18. if ! [ -e $NAME.rrd ]; then
  19. rrdtool create $NAME.rrd \
  20. DS:black:GAUGE:300:0:10000000 \
  21. DS:cyan:GAUGE:300:0:10000000 \
  22. DS:magenta:GAUGE:300:0:10000000 \
  23. DS:yellow:GAUGE:300:0:10000000 \
  24. DS:toner_drum:GAUGE:300:0:10000000 \
  25. RRA:LAST:0.5:1:9600 \
  26. RRA:LAST:0.5:4:9600 \
  27. RRA:LAST:0.5:24:6000;
  28. fi
  29.  
  30. }
  31.  
  32. update() {
  33. #Update the RRD files.
  34.  
  35. poll_device
  36. echo "$colour_black $colour_cyan $colour_magenta $colour_yellow $colour_tonerdrum"
  37. rrdtool update $NAME.rrd -t black N:$colour_black
  38. rrdtool update $NAME.rrd -t cyan N:$colour_cyan
  39. rrdtool update $NAME.rrd -t magenta N:$colour_magenta
  40. rrdtool update $NAME.rrd -t yellow N:$colour_yellow
  41. rrdtool update $NAME.rrd -t toner_drum N:$colour_tonerdrum
  42.  
  43. }
  44.  
  45. # --start=-6400 \
  46. graph() {
  47. #Graph the RRD files.
  48.  
  49. rrdtool graph $NAME.png \
  50. --imgformat=PNG \
  51. --start="now -1h" \
  52. --title="HP Color Laserjet 2550" \
  53. --base=1000 \
  54. --height=120 \
  55. --width=500 \
  56. --alt-autoscale-max \
  57. --lower-limit=0 \
  58. --vertical-label="" \
  59. DEF:blacklast=$NAME.rrd:black:LAST \
  60. LINE1:blacklast#736F6E:"Current Black Level" \
  61. GPRINT:blacklast:LAST:"mg remaining\:%6.2lf" \
  62. DEF:cyanlast=$NAME.rrd:cyan:LAST \
  63. LINE1:cyanlast#50EBEC:"Current Cyan Level" \
  64. GPRINT:cyanlast:LAST:"mg remaining\:%6.2lf" \
  65. GPRINT:cyanlast:LAST:"mg remaining\:%6.2lf" \
  66. DEF:magentalast=$NAME.rrd:magenta:LAST \
  67. LINE1:magentalast#E238EC:"Current Magenta Level" \
  68. GPRINT:magentalast:LAST:"mg remaining\:%6.2lf" \
  69. DEF:yellowlast=$NAME.rrd:yellow:LAST \
  70. LINE1:yellowlast#FFFC17:"Current Yellow Level" \
  71. GPRINT:yellowlast:LAST:"mg remaining\:%6.2lf"
  72.  
  73. }
  74.  
  75. update_loop() {
  76. #Update the RRD every 15 mins.
  77.  
  78. while true; do
  79. update
  80. sleep 5m;
  81. done
  82.  
  83. }
  84.  
  85. NAME="colour_printer"
  86.  
  87. create
  88. update
  89. update_loop
  90.  
  91. #DONE
  92.  
  93. #RESULTS:
  94.  
  95. 892 360 330 188 0 #5mins passed
  96. 892 360 330 188 0 #5mins passed
  97. 892 360 330 188 0 #5mins passed
  98. 892 360 330 188 0 #5mins passed
  99. 892 360 330 188 0 #5mins passed
  100.  
  101. #OK, now I graph:
  102.  
  103. 581x227
  104.  
  105. But the graph has only NAN's WHY?
Add Comment
Please, Sign In to add comment