18 Ekim 2012 Perşembe

Cacti (CLI) Toplu Device,Graphs....vs Ekleme

Cacti (CLI) Toplu Device,Graphs....vs Ekleme

Merhaba arkadaşlar,

Yeni Cacti kurulumu yapınca eklemem gereken cihazlar çok olunca üşendim. Konuyla ilgili araştırmalar sunucu Cactiye komut satırı üzerinden Device,Graphs,...vs birçok şey eklenebiliyormuş.
Sizlere bu konu hakkında bahsetmek istiyorum. Aşağıda komutlar tek tek eklemeye yöneliktir. excellde komutları çoğaltarak topluca girebilirsiniz.

1. Toplu Device Ekleme (add_device.php):

Run = > Cmd
Komut satırına
cd C:\inetpub\wwwroot\cacti\cli
Yazarak (tabi size uygun olan cacti\cli klasörüne ulaşın) cli klasörüne ulaşıyoruz.
php -q add_device.php --help
Yazdığımızda yardım alarak neler yapabileceğimizi görelim.

C:\inetpub\wwwroot\cacti\cli>php -q add_device.php --help
Add Device Script 1.0, Copyright 2004-2012 - The Cacti Group

A simple command line utility to add a device in Cacti

usage: add_device.php --description=[description] --ip=[IP] --template=[ID] [--notes="[]"] [--disable]    [--avail=[ping]] --ping_method=[icmp] --ping_port=[N/A, 1-65534] --ping_retries=[2]
    [--version=[1|2|3]] [--community=] [--port=161] [--timeout=500]
    [--username= --password=] [--authproto=] [--privpass= --privproto=] [--context=]
    [--quiet]

Required:
    --description  the name that will be displayed by Cacti in the graphs
    --ip           self explanatory (can also be a FQDN)
Optional:
    --template     0, is a number (read below to get a list of templates)    --notes        '', General information about this host.  Must be enclosed using double quotes.
    --disable      0, 1 to add this host but to disable checks and 0 to enable it
    --avail        pingsnmp, [ping][none, snmp, pingsnmp]
    --ping_method  tcp, icmp|tcp|udp
    --ping_port    '', 1-65534
    --ping_retries 2, the number of time to attempt to communicate with a host
    --version      1, 1|2|3, snmp version
    --community    '', snmp community string for snmpv1 and snmpv2.  Leave blank
 for no community
    --port         161
    --timeout      500
    --username     '', snmp username for snmpv3
    --password     '', snmp password for snmpv3
    --authproto    '', snmp authentication protocol for snmpv3
    --privpass     '', snmp privacy passphrase for snmpv3
    --privproto    '', snmp privacy protocol for snmpv3
    --context      '', snmp context for snmpv3
    --max_oids     10, 1-60, the number of OID's that can be obtained in a single SNMP Get request

List Options:
    --list-host-templates
    --list-communities
    --quiet - batch mode value return
Siz yukarıdaki listeyi inceleyerek size uygun olan formatı bulabilir siniz. Ama ben kendi kullandığım bir örneği vereceğim ihtiyacınız olan herşey içinde mevcut olacağını düşünüyorum.

php -q add_device.php --description="Cihaz adı" --ip="192.168.1.31" --template=7 --community="public"
Komutla ilgi biraz açıklamak yapmak gerekirse: 
--description="Cihaz adı"
--ip="192.168.1.31"
--community="public"
--template=7  ===> burası Host template IDsi nerden öğreneceğiz peki??

Cacti Sitesine Consol=>Host Templates tıkladığımızda örneğin Windows 2000/XP Host adresi

http://172.24.82.29/cacti/host_templates.php?action=edit&id=7







Sondaki ID bize Host Template ID verecektir.

2. Toplu Grafik Ekleme (add_graphs.php):

2 türlü grafik ekleme vardır.
1. Sorgusuz grafik ekleme:

2. Sorgu çekerek grafik ekleme:

1. Sorgusuz grafik ekleme:

Uptime süresi gibi grafikleri eklemek için kullanırız.Cihazda ne var ne yok bakmadan grafik ekleriz.


php -q add_graphs.php --host-id=51 --graph-type=cg --graph-template-id=44

Komutla ilgi biraz açıklamak yapmak gerekirse:
  • --host-id=51  ===> burası Host  IDsi nerden öğreneceğiz peki??
          Cacti Sitesine Consol=>Device tıkladığımızda örneğin  Localhost  cihazının adresi
          http://172.24.82.29/cacti/host.php?action=edit&id=2
    Sondaki ID bize Host ID verecektir.
  • --graph-type=cg ===> burası Sorgusuz grafik ekleyeceğimiz söylüyoruz.
  • --graph-template-id=44===>burası Graphs Templates  IDsi nerden öğreneceğiz peki??
     Cacti Sitesine Consol=>Graphs Templates tıkladığımızda örneğin  SNMPv2-MIB - sysUpTime  Templatenin  adresi
    http://172.24.82.29/cacti/graph_templates.php?action=template_edit&id=44
    Sondaki ID bize Graphs Templates ID verecektir.

2. Sorgu çekerek grafik ekleme:

Burası biraz karışıyor. Ben temel olarak bir tane örnek vereyim onun üzerinden konuşalım.

php -q add_graphs.php --host-id=70 --graph-type=ds --graph-template-id=26 --snmp-query-id=8 --snmp-query-type-id=18 --snmp-field=hrStorageAllocationUnits --snmp-value="4096 Bytes"


Komutla ilgi biraz açıklamak yapmak gerekirse:
  • --host-id=70  ===> burası Host  ID si nerden öğreneceğiz demiyorum artık öğrentik :))
  •  --graph-type=ds ===> burası Sorgulu grafik ekleyeceğimiz söylüyoruz.
  •   --snmp-field=hrStorageAllocationUnits ===> burası şart sunduğumuz yer. Peki host üzerinde hangi şartlar var nasıl görebiliriz derseniz aşağıdaki komutu giriyoruz.
php -q add_graphs.php --host-id=69 --list-snmp-fields
Known SNMP Fields for host-id 69: (name)
hrProcessorFrwID
hrStorageAllocationUnits
hrStorageDescr
hrStorageIndex
ifDescr
ifHwAddr
ifIndex
ifIP
ifOperStatus
ifSpeed
ifType
 
Yukarıdakilerinin hepsi şart. 
  1. İf ile başlayanlar network için
  2.  hrStorage disk
  3.  hrProcessor Cpu

  •  --snmp-value="4096 Bytes" ===> burası  sunduğumuz şartın değeri. Peki host üzerinde sunduğumuz şartların değerleri neler nasıl görebiliriz derseniz aşağıdaki komutu giriyoruz.

php -q add_graphs.php --host-id=70 --snmp-field=hrStorageAllocationUnits --list-snmp-values
Known values for hrStorageAllocationUnits for host 70: (name)
0 Bytes
4096 Bytes
65536 Bytes

 Yani disk biçimlendirmesi 4096 Bytes olan diskleri seçiyoruz.

  •  --snmp-query-id=8 ===> burası Data Query ID si
Disk için ucd 10 fs yani 8
Network için ucd 00 Lan Yani 1   Gibi 

  • --snmp-query-type-id=18  ===> burası Data Query Type ID si.Bazılarında tek dir bazılarında çoktur.Nerden öğreniyoruz peki? 

php -q add_graphs.php --snmp-query-id=8 --list-query-types
 Known SNMP Query Types: (id, name)
18      Available Disk Space

  •  --graph-template-id=26 ===>burası Graphs Templates  IDsi daha önce bahsetmiştik.

Örnek-2

 Disk için bir tane oluşturduk.Örnek olmas içinde bir tane network tarafı için oluşturalım.
Network bacaklarınan hangilerini izleceğimize karar vermemiz lazım.Up olanlar olabilir ama ben hızı 100000000 olan bacakları izlemek istiyorum.

  • Hangi snmp-fields yi kullanacağız?
php -q add_graphs.php --host-id=69 --list-snmp-fields
Known SNMP Fields for host-id 69: (name)
hrProcessorFrwID
hrStorageAllocationUnits
hrStorageDescr
hrStorageIndex
ifDescr
ifHwAddr
ifIndex
ifIP
ifOperStatus
ifSpeed
ifType

Networkun hızını istediğimiz için     --snmp-field=ifSpeed
  • Hangi Value yi kullanacağız? Şartımızın sonuçlarını görelim.

 php -q add_graphs.php --host-id=70 --snmp-field=ifSpeed --list-snmp-values
 Known values for ifSpeed for host 70: (name)
10000000
1000000000

şartımızı ve sonucumuz belli oldu. --snmp-value="1000000000"

  • Hangi Data Query ID yi kullanacağız?

 ucd 00 Lan Yani 1
  --snmp-query-id=1

  •  Hangi Data Query Type ID yi kullanacağız?
 php -q add_graphs.php --snmp-query-id=1 --list-query-types
Known SNMP Query Types: (id, name)
2       In/Out Errors/Discarded Packets
3       In/Out Non-Unicast Packets
4       In/Out Unicast Packets
9       In/Out Bytes (64-bit Counters)
13      In/Out Bits
14      In/Out Bits (64-bit Counters)
16      In/Out Bytes
20      In/Out Bits with 95th Percentile
21      In/Out Bits with Total Bandwidth
22      In/Out Bytes with Total Bandwidth

 Tercih size kalmış ben burda 16 kullanıyorum.

  •  Hangi Graph Template ID yi kullanacağız?
 Interface - Traffic (bytes/sec) yani 25
 --graph-template-id=25

  •   Hangi Graph türünü kullanacağız ?
 Sorgu çekerek grafik oluşturacağımız için   
--graph-type=ds


  • Hangi Device için kullanacağız ?
 --host-id=79

  •  Sonuç:
 php -q add_graphs.php --host-id=79 --graph-type=ds --graph-template-id=25 --snmp-query-id=1 --snmp-query-type-id=16 --snmp-field=ifSpeed --snmp-value="1000000000"



 Help



İsterseniz bide help diyelim.Bakalım komutlarımız neler...

C:\inetpub\wwwroot\cacti\cli>php -q add_graphs.php --help
Add Graphs Script 1.2, Copyright 2008 - The Cacti Group

A simple command line utility to add graphs in Cacti

usage: add_graphs.php --graph-type=[cg|ds] --graph-template-id=[ID]
    --host-id=[ID] [--graph-title=title] [graph options] [--force] [--quiet]

For cg graphs:
    [--input-fields="[data-template-id:]field-name=value ..."] [--force]

    --input-fields  If your data template allows for custom input data, you may
specify that
                    here.  The data template id is optional and applies where tw
o input fields
                    have the same name.
    --force         If you set this flag, then new cg graphs will be created, ev
en though they
                    may already exist

For ds graphs:
    --snmp-query-id=[ID] --snmp-query-type-id=[ID] --snmp-field=[SNMP Field] --s
nmp-value=[SNMP Value]

    [--graph-title=]       Defaults to what ever is in the graph template/data-s
ource template.

    [--reindex-method=]    the reindex method to be used for that data query
                           if data query already exists, the reindex method will
 not be changed
                    0|None   = no reindexing
                    1|Uptime = Uptime goes Backwards (Default)
                    2|Index  = Index Count Changed
                    3|Fields = Verify all Fields
List Options:
    --list-hosts
    --list-graph-templates [--host-template-id=[ID]]
    --list-input-fields --graph-template-id=[ID]
    --list-snmp-queries
    --list-query-types  --snmp-query-id [ID]
    --list-snmp-fields  --host-id=[ID] [--snmp-query-id=[ID]]
    --list-snmp-values  --host-id=[ID] [--snmp-query-id=[ID]] --snmp-field=[Fiel
d]

'cg' graphs are for things like CPU temp/fan speed, while
'ds' graphs are for data-source based graphs (interface stats etc.)






Windows üzerinde otomatik Cacti kulumunda Zaman sorunu

Windows üzerinde otomatik Cacti kulumunda Zaman sorunu

Merhaba arkadaşlar,
Geçenlerde yeni bir cacti ihtiyacım olmuştu.Windows üzerine package Cacti kurulumu yaptığımda Cactinin saatinin windowsunkinden farklı olduğunu gördüm. Hatta ilk başlar grafik oluşmadığı için cactinin çalışmadığını bile düşündüm. Cactinin saati bizim saate gelince grafikler oluşmaya başlayınca timezone sorunu olduğunu anladım tabi bu bana çok zaman kaybettirdi :))

Sorunun Çözümü:

C:\PHP\php.ini  dosyasını düzenliyoruz.
dosya icerisinde "timezone" ifadesini aratıyoruz.
[Date]
date.timezone="Europe/Istanbul"
Olacak şekilde düzenliyoruz.
run => cmd
Komut satırına iisreset attığımızda sorun düzelmiş olacaktır.

Notlar:

Biz burda PHP için kendimize uygun olan timezone seçtik.Tabi siz farklı bir timezone kullanıyor olabilirsiniz. Aşağıdaki linkden kendinize uygun olan timezone seçebilirsiniz.

Sürüm Bilgisi:

 Cacti=Version 0.8.8a
 OS=Windows Server 2008 R2 Sp1