Skip to content

Instantly share code, notes, and snippets.

@yamamomo
yamamomo / graph.rb
Created April 23, 2017 07:43
zabbix のグラフ画像を取得して保存する
#!/usr/bin/ruby
#
require "zabbixapi"
require 'net/http'
require 'uri'
zbx = ZabbixApi.connect(
:url => 'http://localhost/zabbix/api_jsonrpc.php',
:user => 'Admin',
:password => 'zabbix'
@yamamomo
yamamomo / junos-config.hilight
Created January 17, 2016 13:18
秀丸強調表示 junos-config
99,description
99,inactive:
371,unit \d+
// ipv4
475,(\d{1,3}\.){3}\d{1,3}
475,(\d{1,3}\.){3}\d{1,3}\/\d+
// ipv6
475,(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}(?:\/\d{1,3})?
475,(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}(?:\/\d{1,3})?\/\d+
// ipv6 compressed
@yamamomo
yamamomo / junos-tree.hilight
Created January 17, 2016 13:11
秀丸アウトライン解析 junos-config
/<TreeWord>
/0000,0002,0000,00000000,00010115,"^system {",""
/0000,0002,0000,00000000,00012115,"^chassis {",""
/0000,0002,0000,00000000,00012013,"^interfaces {",""
/0000,0002,0000,00000000,00012115,"^logical-systems {",""
/0000,0002,0000,00000000,00012113,"^forwarding-options {",""
/0000,0002,0000,00000000,00012115,"^class-of-service {",""
/0000,0002,0000,00000000,00012115,"^protocols {",""
/0000,0002,0000,00000000,00012115,"^routing-options {",""
/0000,0002,0000,00000000,00012115,"^policy-options {",""
@yamamomo
yamamomo / rrd_tool.rb
Last active January 17, 2016 13:12
rrdtool fetch をruby でラップしたクラスライブラリ
################################################
#
# rrd_tool.rb
#
# rrdtool fetch をruby でラップしたクラスライブラリ
#
# 2013/6
# yamamoto
#
################################################
@yamamomo
yamamomo / d3_mrtg.html
Last active January 17, 2016 13:13
d3 でMRTG風グラフを描く
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
@yamamomo
yamamomo / rrdtool_graph.rb
Last active January 17, 2016 13:13
rrdtool graph を ruby でラップした
#!/usr/local/bin/ruby
require 'pathname'
require 'open3'
rrd_path = Pathname.new('/data/mrtg/rrd')
rrdfile = "localhost_em0.rrd"
rrd = rrd_path + rrdfile
command = '/usr/local/bin/rrdtool graph'
outfile = "test.png"
#!/usr/local/bin/ruby
require 'pty'
require 'expect'
require 'logger'
require 'ostruct'
conf = OpenStruct.new
conf.pattern = /(user@freebsd:.*%)/
conf.username = "username"
#
#
#
#
class BgpEntry
@@snmpwalk = "/usr/local/bin/snmpwalk -v 2c -c"
@@bgp_status_mib = "1.3.6.1.2.1.15.3.1.2"
@@bgp_admin_mib = "1.3.6.1.2.1.15.3.1.3"
@@bgp_as_mib = "1.3.6.1.2.1.15.3.1.9"
@yamamomo
yamamomo / sec2dhms.rb
Created May 6, 2013 07:20
秒数を日数、時間、分、秒に変換したい
def sec2dhms(secs)
time = secs.round
sec = time % 60
time /= 60
mins = time % 60
time /= 60
hrs = time % 24
time /= 24
days = time
[days, hrs, mins, sec]
@yamamomo
yamamomo / mrtg-run.rb
Created May 5, 2013 19:54
/data/mrtg/cfg 以下の cfgファイルを mrtgコマンドで実行するrubyスクリプト
#!/usr/local/bin/ruby
cfgdir = '/data/mrtg/cfg'
command = '/usr/local/bin/mrtg'
Dir.glob("#{cfgdir}/*.cfg").each do |file|
system("#{command} #{file}")
end