Quick and dirty script to add devices to cacti

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
sangayya.alagundimath
Posts: 20
Joined: Thu Aug 20, 2009 7:41 am

Post by sangayya.alagundimath »

on cacti console all the webpages are working fine. i had taken this bulk upload script and extracted into cacti folder.

when am running add_device php script am getting the above mentioned error, wil this script work for Version 0.8.7e ?
--SanG
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

sangayya.alagundimath wrote: i had taken this bulk upload script and extracted into cacti folder.
Oh, sorry. You're using the old script from this thread? Bad!
Cacti as of 087 has its own cli directory with supported bulk commands. Please use the commands from cli directory only
R.
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

anotherscript to add/export devices to cacti

Post by pepj »

Hello

I put again a sand grain in the desert.

Again a import/export script .... user field friendly ... (but using the cacti API, CLI)
Why? I think it is useful to be able to export/import/merge cacti databases, ... For that reason we cannot work only with 'id' for host, template, ... . This simple script allow to export host with user friendly fields like 'name' instead 'id' and import with 'name','id', .... as you want.

ex:
myswitch,10.0.0.1,"Cisco Switches", "","","AVAIL_SNMP_AND_PING","PING_ICMP","23","600","3","3","","161","600","snmpuserv3","snmppasswordv3","MD5","","[None]","15","",1
Additionnally the exported file could be modify with for example Excel.

Code: Select all

php hosts-add-script.php  --cacti=/usr/share/cacti/site --separator=';' --all-device-infos
@gandalf my script will no more be needed if you add the possibility in CLI to work with 'name' and 'user friendly fields' (tempalename, enabled,...) and have a export of the host data.

Code: Select all

ex: to export
         php hosts-add-script.php  --cacti=/usr/share/cacti/site --all-device-infos
         php hosts-add-script.php  --cacti=/usr/share/cacti/site --separator=';' --all-device-infos
     to import php hosts-add-script.php  --cacti=/usr/share/cacti --f=hosts-files-to-add.txt
PS:
hosts-add-script.php [--host-templates] [--all-device-infos] [--separator='character'] [--help] [--cacti=cactipath] [--f=filename]
--all-device-infos show all devices with all information (in format 'hosts file FORMAT')
--all-device-infos-with-id show all devices with all information with id
--separator (default ',') for example ',' or ';'
--host-templates returns the valid host templates
--cacti=cactipath give the cacti path. If empty you must start from cacti folder
--f=filename to create several cacti devices (see hosts file FORMAT)
--file=filename to create several cacti devices (see hosts file FORMAT)
Attachments
hosts-add-script.php.zip
(6.54 KiB) Downloaded 724 times
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
pegmonkey
Posts: 1
Joined: Mon Aug 24, 2009 12:35 pm

Re: Quick and dirty script to add devices to cacti

Post by pegmonkey »

Excellent script. Thanks! I think this should become an integral part of cacti. Very handy for generating reports for the bean counters around inventory time.
doraemon0214
Posts: 5
Joined: Sun Jul 17, 2005 11:03 pm

Re: Quick and dirty script to add devices to cacti

Post by doraemon0214 »

Hello. I have downloaded the script and exported the devices to a file successfully. But I got an error as below when import.


PHP Fatal error: Call to undefined function mb_strtolower() in /var/www/html/cli/hosts-add-script.php on line 357


Server config:
Cacti Version - 0.8.7c
Plugin Architecture - 2.2
Poller Type - Cactid v
Server Info - Linux 2.6.9-78.0.13.ELsmp
Web Server - Apache/2.0.63 (CentOS)
PHP - 5.1.6
PHP Extensions - libxml, xml, wddx, tokenizer, sysvshm, sysvsem, sysvmsg, standard, SimpleXML, sockets, SPL, shmop, session, Reflection, pspell, posix, mime_magic, iconv, hash, gmp, gettext, ftp, exif, date, curl, ctype, calendar, bz2, zlib, pcre, openssl, apache2handler, gd, ldap, mysql, mysqli, PDO, pdo_mysql, pdo_sqlite, snmp, eAccelerator
MySQL - 5.0.82sp1
RRDTool - 1.2.23
SNMP - 5.1.2
Plugins
  • Global Plugin Settings (settings - v0.5)
    Large Site Performane Booster for Cacti (boost - v2.2)
    Device Monitoring (monitor - v0.8.2)
    Network Discovery (discovery - v0.8.5)
    Network Tools (tools - v0.3)
    Syslog Monitoring (syslog - v0.5.2)
    Device Tracking (mactrack - v1.1)
    Login Page Mod (loginmod - v1.0)
    Update Checker (update - v0.4)
    FlowView (flowview - v0.6)
    Host Info (hostinfo - v0.2)
    Error Images (errorimage - v0.1)
    PHP Network Weathermap (weathermap - v0.96a)
    docs
    Cacti-ReportIt (reportit - v0.6.1)
    Router Configs (routerconfigs - v0.1)
    WMI Query (wmi - v0.1)
    Realtime Graph Viewer (realtime - v0.43)
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

Re: Quick and dirty script to add devices to cacti

Post by pepj »

doraemon0214 wrote:Hello. I have downloaded the script and exported the devices to a file successfully. But I got an error as below when import.
PHP Fatal error: Call to undefined function mb_strtolower() in /var/www/html/cli/hosts-add-script.php on line 357
PHP - 5.1.6
You can replace all "mb_strtolower" with "strtolower" if you are working with only US or UK characters.

But i do not understand why your PHP does not have mb_strtolower (PHP 4 >= 4.3.0, PHP 5). Anyway replace with strtolower should do the same when you do not work with "international character sets".
(Perhaps make sure that PHP has been compiled with --enable-mbstring)
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
gsaray101
Cacti User
Posts: 233
Joined: Thu May 17, 2007 9:18 am

Re: Quick and dirty script to add devices to cacti

Post by gsaray101 »

what is this script host_add_script.php do? I am looking for a script to automate adding devices and creating graphs?

thanks,
pepj
Cacti User
Posts: 324
Joined: Thu Sep 29, 2005 5:03 am
Location: switzerland

Re: Quick and dirty script to add devices to cacti

Post by pepj »

gsaray101 wrote:what is this script host_add_script.php do? I am looking for a script to automate adding devices and creating graphs?

thanks,
Hi,

to automate adding devices use plugin "autom8".

(host_add_script.php is more for simplifying export/import with names (ex name of template) or from/to *.cvs,
or particularly needed to import/export between cacti(s) systems or backups/restore because sql index conflicts)
Jean-Michel
cacti 0.8.7e | cmd & cactid (cactid 0.8.x) | Linux | MySQL Ver 14.7 Distrib 4.1.12, for Win32 | PHP v5.2.6 | Apache v2.x | Thold | Plugin Architecture | plugin "configuration manager" http://cactiusers.org/forums/topic257.html | plugin "IP subnet calculator IPv4 / IPV6" http://forums.cacti.net/viewtopic.php?t=15428 | plugin banner http://docs.cacti.net/userplugin:banner | Net-SNMP 5.5.2 | cygwin 1.5.18 of 02.07.2005
jenkjenk
Posts: 1
Joined: Thu Oct 07, 2010 1:43 am

Re: Quick and dirty script to add devices to cacti

Post by jenkjenk »

pepj wrote:
doraemon0214 wrote:Hello. I have downloaded the script and exported the devices to a file successfully. But I got an error as below when import.
PHP Fatal error: Call to undefined function mb_strtolower() in /var/www/html/cli/hosts-add-script.php on line 357
PHP - 5.1.6
You can replace all "mb_strtolower" with "strtolower" if you are working with only US or UK characters.

But i do not understand why your PHP does not have mb_strtolower (PHP 4 >= 4.3.0, PHP 5). Anyway replace with strtolower should do the same when you do not work with "international character sets".
(Perhaps make sure that PHP has been compiled with --enable-mbstring)
It's work! Thank you :)
vimvim
Posts: 6
Joined: Wed Sep 21, 2011 12:39 pm

Re: Quick and dirty script to add devices to cacti

Post by vimvim »

I have a issue when I use the script.
I open the file and add manually my device with the param I need.
The adding new device working well but when I tried to graph port on those device is still blank.
I used cacti 0.8.7g on ubuntu 11.04 server
Attachments
cacti_blank
cacti_blank
blank_cacti.JPG (26.79 KiB) Viewed 12508 times
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Quick and dirty script to add devices to cacti

Post by gandalf »

Then please use 2nd link of my sig to know what's causing the failure
R..
vimvim
Posts: 6
Joined: Wed Sep 21, 2011 12:39 pm

Re: Quick and dirty script to add devices to cacti

Post by vimvim »

thx for your help is appreciated but I already tried these and is not fix my issue. When I imported my file with new divices I insert myself but is not graph the new devices.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Quick and dirty script to add devices to cacti

Post by gandalf »

Then please tell us about the results of the debugging steps to help
R.
vimvim
Posts: 6
Joined: Wed Sep 21, 2011 12:39 pm

Re: Quick and dirty script to add devices to cacti

Post by vimvim »

Check Cacti Log File (this is the host have trouble, but all the rest is perfect)
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9053] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9053] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9052] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9052] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9050] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9050] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9049] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9049] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9047] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9047] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9046] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9041] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9040] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9040] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9046] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9044] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9044] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9043] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:04 AM - CMDPHP: Poller[0] Host[46] DS[9043] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:05 AM - CMDPHP: Poller[0] Host[14] DS[2876] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:05 AM - CMDPHP: Poller[0] Host[14] DS[2876] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:20:05 AM - CMDPHP: Poller[0] Host[46] DS[9041] WARNING: Result from SNMP not valid. Partial Result: U

Check Basic Data Gathering
root@CACTI:/var/www/cacti/scripts# snmpwalk -c Che2ranUN5 -v 2c 172.*.*.* .1.3.6.1.2.1.4
iso.3.6.1.2.1.4.1.0 = INTEGER: 2
iso.3.6.1.2.1.4.2.0 = INTEGER: 255
iso.3.6.1.2.1.4.3.0 = Counter32: 569857940
iso.3.6.1.2.1.4.4.0 = Counter32: 0
iso.3.6.1.2.1.4.5.0 = Counter32: 555625673
iso.3.6.1.2.1.4.6.0 = Counter32: 0
iso.3.6.1.2.1.4.7.0 = Counter32: 0
iso.3.6.1.2.1.4.8.0 = Counter32: 0
iso.3.6.1.2.1.4.9.0 = Counter32: 14232274
iso.3.6.1.2.1.4.10.0 = Counter32: 14264627
iso.3.6.1.2.1.4.11.0 = Counter32: 91
iso.3.6.1.2.1.4.12.0 = Counter32: 0
iso.3.6.1.2.1.4.13.0 = INTEGER: 30
iso.3.6.1.2.1.4.14.0 = Counter32: 0
iso.3.6.1.2.1.4.15.0 = Counter32: 0
iso.3.6.1.2.1.4.16.0 = Counter32: 0
iso.3.6.1.2.1.4.17.0 = Counter32: 0
iso.3.6.1.2.1.4.18.0 = Counter32: 0
iso.3.6.1.2.1.4.19.0 = Counter32: 0
iso.3.6.1.2.1.4.20.1.1.172.*.*.* = IpAddress: 172.*.*.*
iso.3.6.1.2.1.4.20.1.2.172.*.*.* = INTEGER: 999
iso.3.6.1.2.1.4.20.1.3.172.*.*.* = IpAddress: 0.0.0.0
iso.3.6.1.2.1.4.20.1.4.172.*.*.* = INTEGER: 1
iso.3.6.1.2.1.4.20.1.5.172.*.*.* = INTEGER: 18024
iso.3.6.1.2.1.4.22.1.1.999.172.*.*.* = INTEGER: 999
iso.3.6.1.2.1.4.22.1.1.999.172.*.*.* = INTEGER: 999
iso.3.6.1.2.1.4.22.1.1.999.172.*.*.* = INTEGER: 999
iso.3.6.1.2.1.4.22.1.2.999.172.*.*.* = Hex-STRING: 00 00 0C 9F F3 E7
iso.3.6.1.2.1.4.22.1.2.999.172.*.*.* = Hex-STRING: 00 08 E3 FF FC 50
iso.3.6.1.2.1.4.22.1.2.999.172.*.*.* = Hex-STRING: 00 24 97 B0 E9 41
iso.3.6.1.2.1.4.22.1.3.999.172.*.*.* = IpAddress: 172.*.*.*
iso.3.6.1.2.1.4.22.1.3.999.172.*.*.* = IpAddress: 172.*.*.*
iso.3.6.1.2.1.4.22.1.3.999.172.*.*.* = IpAddress: 172.*.*.*
iso.3.6.1.2.1.4.22.1.4.999.172.*.*.* = INTEGER: 3
iso.3.6.1.2.1.4.22.1.4.999.172.*.*.* = INTEGER: 3
iso.3.6.1.2.1.4.22.1.4.999.172.*.*.* = INTEGER: 4
iso.3.6.1.2.1.4.23.0 = Counter32: 0

Check Cacti's Poller
id=46
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9053] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9053] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9052] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9052] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9050] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9050] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9049] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9049] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9047] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9047] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9046] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9041] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9040] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9040] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9046] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9044] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9044] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9043] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9043] WARNING: Result from SNMP not valid. Partial Result: U
09/26/2011 09:44:05 AM - CMDPHP: Poller[0] Host[46] DS[9041] WARNING: Result from SNMP not valid. Partial Result: U

Check RRD File Update
rrdtool update 1235775600:0

Check RRD File Ownership (my file is not there)
root@CACTI:/var/www/cacti/rra/46# ls -la
-rw-r--r-- 1 cacti www-data 56228 2011-09-26 10:20 9035.rrd
-rw-r--r-- 1 cacti www-data 56228 2011-09-26 10:20 9036.rrd
-rw-r--r-- 1 cacti www-data 56228 2011-09-26 10:20 9037.rrd

Check RRD File Numbers

root@CACTI:/var/www/cacti/rra/46# rrdtool fetch 9085.rrd AVERAGE
ERROR: opening '9085.rrd': No such file or directory

root@CACTI:/var/www/cacti/rra/46# rrdtool tune 9085.rrd --maximum 0:600
ERROR: opening '9085.rrd': No such file or directory

The issue appears when I edit the export file and adding new device after I import the file with the new device wrote and Cacti cannot graph because rrd file not exist.

THX
vimvim
Posts: 6
Joined: Wed Sep 21, 2011 12:39 pm

Re: Quick and dirty script to add devices to cacti

Post by vimvim »

I found the issue. Is related about the crontab file. Just do
"sudo /etc/init.d/cron restart or stop and start"
THX
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests