1. Список говнокодов пользователя munin

    Всего: 55

  2. Python / Говнокод #22361

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    #!/usr/bin/env python
    # litecoind_ Munin plugin for Litecoin Server Variables
    #
    # by Mike Koss
    # Feb 14, 2012, MIT License
    #
    
    
    import os
    import sys
    import time
    import re
    import urllib2
    import json
    
    
    DEBUG = False
    
    
    def main():
        # getinfo variable is read from command name - probably the sym-link name.
        request_var = sys.argv[0].split('_', 1)[1] or 'balance'
        command = sys.argv[1] if len(sys.argv) > 1 else None
        request_labels = {'balance': ('Wallet Balance', 'BTC'),
                          'connections': ('Peer Connections', 'Connections'),
                          'fees': ("Tip Offered", "BTC"),
                          'transactions': ("Transactions", "Transactions",
                                           ('confirmed', 'waiting')),
                          'block_age': ("Last Block Age", "Seconds"),
                          'difficulty': ("Difficulty", ""),
                          }
        labels = request_labels[request_var]
        if len(labels) < 3:
            line_labels = [request_var]
        else:
            line_labels = labels[2]
    
        if command == 'suggest':
            for var_name in request_labels.keys():
                print var_name
            return
    
        if command == 'config':
            print 'graph_category litecoin'
            print 'graph_title Litecoin %s' % labels[0]
            print 'graph_vlabel %s' % labels[1]
            for label in line_labels:
                print '%s.label %s' % (label, label)
            return
    
        # Munin should send connection options via environment vars
        litecoin_options = get_env_options('rpcconnect', 'rpcport', 'rpcuser', 'rpcpassword')
        litecoin_options.rpcconnect = litecoin_options.get('rpcconnect', '127.0.0.1')
        litecoin_options.rpcport = litecoin_options.get('rpcport', '8332')
    
        if litecoin_options.get('rpcuser') is None:
            conf_file = os.path.join(os.path.expanduser('~/.litecoin'), 'litecoin.conf')
            litecoin_options = parse_conf(conf_file)
    
        litecoin_options.require('rpcuser', 'rpcpassword')
    
        litecoin = ServiceProxy('http://%s:%s' % (litecoin_options.rpcconnect,
                                                 litecoin_options.rpcport),
                               username=litecoin_options.rpcuser,
                               password=litecoin_options.rpcpassword)
    
        (info, error) = litecoin.getinfo()
    
        if error:
            if command == 'autoconf':
                print 'no'

    munin, 18 Февраля 2017

    Комментарии (0)
  3. Python / Говнокод #22360

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    #!/usr/bin/env python
    # bitcoind_ Munin plugin for Bitcoin Server Variables
    #
    # by Mike Koss
    # Feb 14, 2012, MIT License
    
    
    import os
    import sys
    import time
    import re
    import urllib2
    import json
    
    
    DEBUG = False
    
    
    def main():
        # getinfo variable is read from command name - probably the sym-link name.
        request_var = sys.argv[0].split('_', 1)[1] or 'balance'
        command = sys.argv[1] if len(sys.argv) > 1 else None
        request_labels = {'balance': ('Wallet Balance', 'BTC'),
                          'connections': ('Peer Connections', 'Connections'),
                          'fees': ("Tip Offered", "BTC"),
                          'transactions': ("Transactions", "Transactions",
                                           ('confirmed', 'waiting')),
                          'block_age': ("Last Block Age", "Seconds"),
                          'difficulty': ("Difficulty", ""),
                          }
        labels = request_labels[request_var]
        if len(labels) < 3:
            line_labels = [request_var]
        else:
            line_labels = labels[2]
    
        if command == 'suggest':
            for var_name in request_labels.keys():
                print var_name
            return
    
        if command == 'config':
            print 'graph_category bitcoin'
            print 'graph_title Bitcoin %s' % labels[0]
            print 'graph_vlabel %s' % labels[1]
            for label in line_labels:
                print '%s.label %s' % (label, label)
            return
    
        # Munin should send connection options via environment vars
        bitcoin_options = get_env_options('rpcconnect', 'rpcport', 'rpcuser', 'rpcpassword')
        bitcoin_options.rpcconnect = bitcoin_options.get('rpcconnect', '127.0.0.1')
        bitcoin_options.rpcport = bitcoin_options.get('rpcport', '8332')
    
        if bitcoin_options.get('rpcuser') is None:
            conf_file = os.path.join(os.path.expanduser('~/.bitcoin'), 'bitcoin.conf')
            bitcoin_options = parse_conf(conf_file)
    
        bitcoin_options.require('rpcuser', 'rpcpassword')
    
        bitcoin = ServiceProxy('http://%s:%s' % (bitcoin_options.rpcconnect,
                                                 bitcoin_options.rpcport),
                               username=bitcoin_options.rpcuser,
                               password=bitcoin_options.rpcpassword)
    
        (info, error) = bitcoin.getinfo()
    
        if error:
            if command == 'autoconf':
                print 'no'

    munin, 18 Февраля 2017

    Комментарии (0)
  4. bash / Говнокод #22359

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    #!/bin/bash
    #
    # munin plugin to monitor bans on Fail2ban jails
    #
    # Origional Author: Thomas Leveil
    # Contributors: none
    # Version: 1.1
    #
    ###############################################
    # You have to specify a different user in the munin-node config file as follow:
    #
    # [fail2ban_all_jails]
    # user root
    ###############################################
    #
    # HISTORY
    # v1.1 : better autoconf
    #
    #%# family=contrib
    #%# capabilities=autoconf
    
    
    case $1 in
    	autoconf)
    		if [ -z $(which fail2ban-client) ]; then
    			echo no
    			exit 1
    		fi
    		if [ $(whoami) != "root" ]; then
    			echo "no (fail2ban-client found but must run as root)"
    			exit 1
    		fi
    		if [ -x $(which fail2ban-client) ]; then
    			echo yes
    			exit 0
    		else
    			echo "no (fail2ban-client found but not executable)"
    			exit 1
    		fi
    		;;
    	config)
    		echo "graph_title Fail2ban"
    		echo 'graph_vlabel active bans'
    		echo 'graph_category Network'
    		echo 'graph_info number of jailled ip'
    		echo 'graph_info This graph shows the amount of bans caught by Fail2ban'
    		$(which fail2ban-client) status | awk '/Jail list:/ { for (i=4; i<=NF; i++) { sub(/,$/,"",$i); jail=$i; sub(/-/,"_",$i); print "fail2ban_"$i".label "jail } }'
    		exit 0
    		;;
    esac
    
     $(which fail2ban-client) status | awk '/Jail list:/ { for (i=4; i<=NF; i++) { sub(/,$/,"",$i); print $i } }' | \
      while read JAIL; do 
        echo -n "fail2ban_${JAIL//-/_}.value "
        $(which fail2ban-client) status $JAIL | awk '/Currently banned:/ { print $NF }'
      done

    munin, 18 Февраля 2017

    Комментарии (0)
  5. Perl / Говнокод #22317

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    #!/usr/bin/perl
    #
    # Plugin to monitor CPU frequency scaling via time_in_state
    #
    # Origional Author: Kamen Naydenov @pau4o
    # Contributors:
    #
    #
    #
    use strict;
    use warnings;
    
    
    my $data_file = '/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state';
    
    if ($ARGV[0] and $ARGV[0] eq "autoconf") {
      if (-r "$data_file") {
        print "yes\n";
        exit 0;
      } else {
        print $data_file, " not found\n";
        exit 1;
      }
    }
    
    my (%cpufreq_stats, $cpufreq, $freq, $total_time, $graphOrder, $firstOne);
    &fetch_info;
    
    if ($ARGV[0] and $ARGV[0] eq "config") {
      print 'graph_args --base 1000 -l 0 -u 100', "\n";
      print 'graph_vlabel %', "\n";
      print 'graph_scale no', "\n";
      print 'graph_title CPU scaling statistics', "\n";
      print 'graph_category system', "\n";
      print 'graph_info This graph shows how much time CPU spend in each supported frequency.', "\n";
    
      foreach $freq (sort { $b <=> $a } keys %cpufreq_stats) {
        $graphOrder .= 'cpu_at_' . $freq . ' ';
        print 'cpu_at_', $freq, '.label ', $freq, "\n";
        print 'cpu_at_', $freq, '.info Time spend using frequency of ', $freq, " Hz \n";
        print 'cpu_at_', $freq, '.min 0', "\n";
        print 'cpu_at_', $freq, '.max 100', "\n";
    #     if ($firstOne) {
    #       print $freq, ".draw STACK\n";
    #     } else {
    #       print $freq, ".draw AREA\n";
    #     }
    #     $firstOne++;
      }
      print 'graph_order ', $graphOrder, "\n";
      exit 0;
    }
    
    foreach $cpufreq (sort { $b <=> $a } keys %cpufreq_stats ) {
      my $time_in_percent = $cpufreq_stats{"$cpufreq"} * 100 / $total_time;
      print 'cpu_at_', $cpufreq, '.value ', $time_in_percent, "\n";
    }
    
    
    sub fetch_info {
      open (IN, '<', "$data_file")
        or die "Could not open $data_file for reading: $!";
      while (<IN>) {
        if (/^(\d+)\s+(\d+)\s+/) {
          $cpufreq_stats{"$1"} = $2;
          $total_time += $2;
        }
      }
      close (IN) or die "$!";
    }

    munin, 12 Февраля 2017

    Комментарии (24)
  6. Perl / Говнокод #22316

    −98

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    #!/usr/bin/perl
    #
    # Plugin to monitor thermal sensors inside ThinkPad
    #
    # Origional Author: Kamen Naydenov @pau4o
    # Contributors:
    #
    #
    
    use warnings;
    use strict;
    
    if ($ARGV[0] and $ARGV[0] eq "autoconf")
      {
        if (-r "/proc/acpi/ibm/thermal")
          {
    	print "yes\n";
    	exit 0;
          }
        else
          {
    	print "/proc/acpi/ibm/thermal not found\n You must load ibm_acpi kernel module\n";
    	exit 1;
          }
      }
    
    my ($i, $val, @sensors, @values);
    
    @sensors=qw/CPU MiniPCI HDD GPU Bat0 Na0 Bat1 Na1/;
    $val=qx|cat /proc/acpi/ibm/thermal|;
    
    if ($ARGV[0] and $ARGV[0] eq "config")
      {
        print "graph_args --base 1000 -l 0 --vertical-label Temp\n";
        print "graph_title Some temperatures in ThinkPad\n";
        print "graph_category sensors\n";
        print "graph_info There is some themperatures detected by ibm_acpi kernel module. The location of sensors may vary on other models (these are for R51)\n";
        print "graph_order @sensors\n";
        print "graph_scale off\n";
        for (@sensors) {
          print "$_.label $_\n";
          print "$_.info Temperature near $_\n";
          print "$_.max 100\n";
        }
        exit 0;
      }
    
    @values=split(/:|\s+/,$val);
    shift @values;
    shift @values;
    
    for ($i=0; $i <= 7; $i++) {
      if ($values[$i]=~/^-(\d*)$/) {
        print "$sensors[$i].value $1\n";
      } else {
        print "$sensors[$i].value $values[$i]\n";
      }
    }

    munin, 12 Февраля 2017

    Комментарии (0)