diff --git a/pandora_console/extras/demodata/agents/0-demo-agent.prd b/pandora_console/extras/demodata/agents/0-demo-agent.prd new file mode 100644 index 0000000000..1a45fb939c --- /dev/null +++ b/pandora_console/extras/demodata/agents/0-demo-agent.prd @@ -0,0 +1,30 @@ +[agent_data] + +agents_number="1" + +agent_name="demo-global-agent" +agent_alias="demo-global-agent" + +group="Demo servers" + +address_network="192.168.0.0/24" + +os_name="Linux" + +os_versions[]="Rocky Linux 9.2 (Blue Onyx)" +os_versions[]="CentOS Linux 7 (Core)" +os_versions[]="CentOS Linux 6 (Core)" +os_versions[]="RHEL 8.2" +os_versions[]="RHEL 8.1" +os_versions[]="Alma Linux 9.1" + +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + +[modules] + +name[1]="Host Alive" +type[1]="generic_proc" +values[1]="PROC;5" +group[1]="Network" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/1-linux.prd b/pandora_console/extras/demodata/agents/1-linux.prd new file mode 100644 index 0000000000..aaec5cd6ad --- /dev/null +++ b/pandora_console/extras/demodata/agents/1-linux.prd @@ -0,0 +1,211 @@ +[agent_data] + +agents_number="4" + +agent_name="linux" +agent_alias="linux" + +group="Demo servers" + +address_network="192.168.1.0/24" + +os_name="Linux" + +os_versions[]="Rocky Linux 9.2 (Blue Onyx)" +os_versions[]="CentOS Linux 7 (Core)" +os_versions[]="CentOS Linux 6 (Core)" +os_versions[]="RHEL 8.2" +os_versions[]="RHEL 8.1" +os_versions[]="Alma Linux 9.1" + +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + +[modules] + +name[1]="Network Usage" +type[1]="generic_data_inc" +description[1]="Network usage in the system" +values[1]="RANDOM;0;10000" +unit[1]="bytes/sec" +group[1]="Network" + +name[2]="Network latency" +type[2]="generic_data" +description[2]="Network latency to router" +values[2]="RANDOM;0;20" +unit[2]="msec" +group[2]="Network" + +name[3]="CPU Load" +type[3]="generic_data" +description[3]="CPU Usage" +values[3]="RANDOM;20;90" +unit[3]="%" +group[3]="System" + +name[4]="Disk Usage" +type[4]="generic_data" +description[4]="% used space" +values[4]="RANDOM;50;60" +unit[4]="%" +group[4]="System" + +name[5]="Memory Usage" +type[5]="generic_data" +description[5]="% Used memory" +values[5]="RANDOM;0;20" +unit[5]="%" +group[5]="System" + +name[6]="Antivirus Updated" +type[6]="generic_proc" +description[6]="Detect if A/V is enabled and updated" +values[6]="PROC;5" +group[6]="Security" + +name[7]="Insecure passwords status" +type[7]="generic_proc" +description[7]="No insecure passwords found" +values[7]="PROC;0" +group[7]="Security" + +name[8]="Files check status" +type[8]="generic_proc" +description[8]="No changed files found" +values[8]="PROC;0" +group[8]="Security" + +name[9]="Authorized ports status" +type[9]="generic_proc" +description[9]="No unauthorized ports found" +values[9]="PROC;0" +group[9]="Security" + +name[10]="Service httpd" +type[10]="generic_proc" +values[10]="PROC;5" +group[10]="Applications" + +name[11]="Service mysqld" +type[11]="generic_proc" +values[11]="PROC;5" +group[11]="Applications" + +name[12]="Service sshd" +type[12]="generic_proc" +values[12]="PROC;5" +group[12]="Applications" + +[inventory] + +name[1]="Software" +format[1]="Name;Version;Description" +values[1]="name;version;description" + +name[2]="Users" +format[2]="Username" +values[2]="username" + +name[3]="File System" +format[3]="Device;Free size;Total size;Mount point" +values[3]="device;free_size;total_size;mount_point" + +[inventory_values] + +name[1]="aajohan-comfortaa-fonts" +name[2]="aardvark-dns" +name[3]="abattis-cantarell-fonts" +name[4]="abrt" + +version[1]="3.101" +version[2]="1.0.3" +version[3]="0.301" +version[4]="2.14.6" + +description[1]="Modern style true type font" +description[2]="Authoritative DNS server for A/AAAA container records" +description[3]="Humanist sans serif font" +description[4]="Automatic bug detection and reporting tool" + +username[1]="root" +username[2]="pandora" + +device[1]="/dev/sda1" +device[2]="/dev/sda2" +device[3]="/dev/sdb1" + +free_size[1]="96G" +free_size[2]="136G" +free_size[3]="97M" + +total_size[1]="180G" +total_size[2]="1.6T" +total_size[3]="819M" + +mount_point[1]="/home" +mount_point[2]="/" +mount_point[3]="/tmp" + +[log_modules] + +source[1]="httpd" +data[1]='127.0.0.1 - "GET /index.html HTTP/1.1" 200 3456 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[2]="httpd" +data[2]='192.168.1.1 - "POST /submit.php HTTP/1.1" 302 0 "https://example.com/form" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[3]="httpd" +data[3]='10.0.0.2 - "GET /images/logo.png HTTP/1.1" 304 0 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Mobile/15E148 Safari/604.1"' + +source[4]="httpd" +data[4]='172.16.0.1 - "GET /page/about-us HTTP/1.1" 404 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[5]="httpd" +data[5]='192.168.0.10 - "GET /css/style.css HTTP/1.1" 200 768 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[6]="httpd" +data[6]='203.0.113.45 - "GET /blog/post-123 HTTP/1.1" 200 5432 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[7]="httpd" +data[7]='54.78.90.12 - "GET /category/api-reference HTTP/1.1" 200 6543 "-" "Mozilla/5.0 (Linux; Android 10; SM-G960U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Mobile Safari/537.36"' + +source[8]="httpd" +data[8]='88.77.66.55 - "GET /contact-us HTTP/1.1" 301 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[9]="httpd" +data[9]='198.51.100.23 - "GET /images/photo.jpg HTTP/1.1" 200 4567 "https://example.com/gallery" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[10]="httpd" +data[10]='128.0.0.1 - "GET /downloads/file.zip HTTP/1.1" 200 12345 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[11]="mysqld" +data[11]="[Warning] Aborted connection 123 to db: 'your_database' user: 'your_user' host: '192.168.1.100' (Got an error reading communication packets)" + +source[12]="mysqld" +data[12]="[ERROR] Table 'your_database.your_table' doesn't exist" + +source[13]="mysqld" +data[13]="[Note] Starting crash recovery..." + +source[14]="mysqld" +data[14]="[Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a LIMIT clause. Use a different log bin event type." + +source[15]="mysqld" +data[15]="[ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use 'ulimit' to allow mysqld to use more memory or you can add more swap space" + +source[16]="mysqld" +data[16]="[Note] Aborted connection 456 to db: 'another_database' user: 'another_user' host: 'localhost' (Got timeout reading communication packets)" + +source[17]="mysqld" +data[17]="[ERROR] Can't create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug" + +source[18]="mysqld" +data[18]="[Warning] 'user' entry 'your_user@localhost' ignored in --skip-name-resolve mode." + +source[19]="mysqld" +data[19]="[Note] InnoDB: Starting rollback of uncommitted transactions" + +source[20]="mysqld" +data[20]="[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed." \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/2-windows.prd b/pandora_console/extras/demodata/agents/2-windows.prd new file mode 100644 index 0000000000..921abeb7dc --- /dev/null +++ b/pandora_console/extras/demodata/agents/2-windows.prd @@ -0,0 +1,118 @@ +[agent_data] + +agents_number="2" + +agent_name="windows" +agent_alias="windows" + +group="Demo servers" + +address_network="192.168.2.0/24" + +os_name="Windows" + +os_versions[]="Microsoft Windows 11 Pro" +os_versions[]="Microsoft Windows 11" +os_versions[]="Home Microsoft Windows 10 Pro" +os_versions[]="Microsoft Windows 10 Home" +os_versions[]="Microsoft Windows 2018" + +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + +[modules] + +name[1]="Network Usage" +type[1]="generic_data_inc" +description[1]="Network usage in the system" +values[1]="RANDOM;0;10000" +unit[1]="bytes/sec" +group[1]="Network" + +name[2]="Network latency" +type[2]="generic_data" +description[2]="Network latency to router" +values[2]="RANDOM;0;20" +unit[2]="msec" +group[2]="Network" + +name[3]="CPU Load" +type[3]="generic_data" +description[3]="CPU Usage" +values[3]="RANDOM;20;90" +unit[3]="%" +group[3]="System" + +name[4]="Disk Usage" +type[4]="generic_data" +description[4]="% used space" +values[4]="RANDOM;50;60" +unit[4]="%" +group[4]="System" + +name[5]="Memory Usage" +type[5]="generic_data" +description[5]="% Used memory" +values[5]="RANDOM;0;20" +unit[5]="%" +group[5]="System" + +name[6]="Service WMI" +type[6]="generic_proc" +values[6]="PROC;5" +group[6]="Applications" + +[inventory] + +name[1]="Software" +format[1]="Name;Version" +values[1]="name;version" + +name[2]="Users" +format[2]="Domain;User" +values[2]="domain;user" + +name[3]="File System" +format[3]="Device;Total size;Free size;Mount point" +values[3]="device;total_size;free_size;mount_point" + +name[4]="Windows Serial Number" +format[4]="Serial number" +values[4]="serial_number" + +[inventory_values] + +name[1]="Microsoft Update Health Tools" +name[2]="Java(TM) SE Development Kit 17.0.6 (64-bit)" +name[3]="DisplayLink Graphics" +name[4]="Microsoft Visual C++ 2019 X64 Additional Runtime - 14.28.29325" + +version[1]="5.71.0.0" +version[2]="17.0.6.0" +version[3]="10.2.7042.0" +version[4]="14.28.29325" + +domain[1]="DEMO" +domain[2]="DEMO" + +user[1]="Administrator" +user[2]="pandora" + +device[1]="C:" +device[2]="D:" +device[3]="T:" + +total_size[1]="1.6T" +total_size[2]="180G" +total_size[3]="819M" + +free_size[1]="136G" +free_size[2]="96G" +free_size[3]="97M" + +mount_point[1]="OS" +mount_point[2]="Data" +mount_point[3]="Temp" + +serial_number[1]="Demo-56 4d 7d 43 24 e4 c6 ac-67 57 52 60 e9 10 26 78" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/3-macosx.prd b/pandora_console/extras/demodata/agents/3-macosx.prd new file mode 100644 index 0000000000..0bbf20edbb --- /dev/null +++ b/pandora_console/extras/demodata/agents/3-macosx.prd @@ -0,0 +1,74 @@ +[agent_data] + +agents_number="1" + +agent_name="macos" +agent_alias="macos" + +group="Demo servers" + +address_network="192.168.3.0/24" + +os_name="MacOS" + +os_versions[]="12.1" +os_versions[]="13.1" +os_versions[]="11.2" +os_versions[]="11.3" +os_versions[]="10.3" + +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + +[modules] + +name[1]="Network Usage" +type[1]="generic_data_inc" +description[1]="Network usage in the system" +values[1]="RANDOM;0;10000" +unit[1]="bytes/sec" +group[1]="Network" + +name[2]="Network latency" +type[2]="generic_data" +description[2]="Network latency to router" +values[2]="RANDOM;0;20" +unit[2]="msec" +group[2]="Network" + +name[3]="CPU Load" +type[3]="generic_data" +description[3]="CPU Usage" +values[3]="RANDOM;20;90" +unit[3]="%" +group[3]="System" + +name[4]="Disk Usage" +type[4]="generic_data" +description[4]="% used space" +values[4]="RANDOM;50;60" +unit[4]="%" +group[4]="System" + +name[5]="Memory Usage" +type[5]="generic_data" +description[5]="% Used memory" +values[5]="RANDOM;0;20" +unit[5]="%" +group[5]="System" + +name[6]="Service httpd" +type[6]="generic_proc" +values[6]="PROC;5" +group[6]="Applications" + +name[7]="Service mysqld" +type[7]="generic_proc" +values[7]="PROC;5" +group[7]="Applications" + +name[8]="Service sshd" +type[8]="generic_proc" +values[8]="PROC;5" +group[8]="Applications" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/4-freebsd.prd b/pandora_console/extras/demodata/agents/4-freebsd.prd new file mode 100644 index 0000000000..c3d9d3eba2 --- /dev/null +++ b/pandora_console/extras/demodata/agents/4-freebsd.prd @@ -0,0 +1,73 @@ +[agent_data] + +agents_number="1" + +agent_name="freebsd" +agent_alias="freebsd" + +group="Demo servers" + +address_network="192.168.4.0/24" + +os_name="BSD" + +os_versions[]="14.0" +os_versions[]="13.1" +os_versions[]="13.2" +os_versions[]="13.3" + +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + +[modules] + +name[1]="Network Usage" +type[1]="generic_data_inc" +description[1]="Network usage in the system" +values[1]="RANDOM;0;10000" +unit[1]="bytes/sec" +group[1]="Network" + +name[2]="Network latency" +type[2]="generic_data" +description[2]="Network latency to router" +values[2]="RANDOM;0;20" +unit[2]="msec" +group[2]="Network" + +name[3]="CPU Load" +type[3]="generic_data" +description[3]="CPU Usage" +values[3]="RANDOM;20;90" +unit[3]="%" +group[3]="System" + +name[4]="Disk Usage" +type[4]="generic_data" +description[4]="% used space" +values[4]="RANDOM;50;60" +unit[4]="%" +group[4]="System" + +name[5]="Memory Usage" +type[5]="generic_data" +description[5]="% Used memory" +values[5]="RANDOM;0;20" +unit[5]="%" +group[5]="System" + +name[6]="Service httpd" +type[6]="generic_proc" +values[6]="PROC;5" +group[6]="Applications" + +name[7]="Service mysqld" +type[7]="generic_proc" +values[7]="PROC;5" +group[7]="Applications" + +name[8]="Service sshd" +type[8]="generic_proc" +values[8]="PROC;5" +group[8]="Applications" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/5-cisco.prd b/pandora_console/extras/demodata/agents/5-cisco.prd new file mode 100644 index 0000000000..a385f535dc --- /dev/null +++ b/pandora_console/extras/demodata/agents/5-cisco.prd @@ -0,0 +1,297 @@ +[agent_data] + +agents_number="1" + +agent_name="cisco" +agent_alias="cisco" + +group="Demo network" + +address_network="192.168.5.0/24" +mac="__randomMAC__" + +os_name="Cisco" + +os_versions[]="C9200L" +os_versions[]="C9300LM" +os_versions[]="C9600" + +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + +[modules] + +name[1]="CPU Usage (5 min avg)" +type[1]="generic_data" +description[1]="CPU Usage" +values[1]="RANDOM;20;90" +unit[1]="%" +group[1]="General" + +name[2]="Big Buffer Misses" +type[2]="generic_data" +description[2]="Buffer misses" +values[2]="RANDOM;20;90" +unit[2]="%" +group[2]="General" + +name[3]="Temperature" +type[3]="generic_data" +description[3]="System temp" +values[3]="RANDOM;20;30" +unit[3]="ÂșC" +group[3]="General" + +name[4]="Host alive" +type[4]="generic_proc" +values[4]="PROC;5" +group[4]="Networking" + +name[5]="Gi0/0_ifOperStatus" +type[5]="generic_proc" +description[5]="(MAC: _mac_ - Gi0/0_ifOperStatus)" +values[5]="PROC;5" +group[5]="Networking" + +name[6]="Gi0/0_ifInOctets" +type[6]="generic_data_inc" +description[6]="(MAC: _mac_ - Gi0/0_ifInOctets)" +values[6]="RANDOM;0;1000" +unit[6]="bytes/s" +group[6]="Networking" + +name[7]="Gi0/0_ifOutOctets" +type[7]="generic_data_inc" +description[7]="(MAC: _mac_ - Gi0/0_ifOutOctets)" +values[7]="RANDOM;0;1000" +unit[7]="bytes/s" +group[7]="Networking" + +name[8]="Gi0/1_ifOperStatus" +type[8]="generic_proc" +description[8]="(MAC: _mac_ - Gi0/1_ifOperStatus)" +values[8]="PROC;5" +group[8]="Networking" + +name[9]="Gi0/1_ifInOctets" +type[9]="generic_data_inc" +description[9]="(MAC: _mac_ - Gi0/1_ifInOctets)" +values[9]="RANDOM;0;1000" +unit[9]="bytes/s" +group[9]="Networking" + +name[10]="Gi0/1_ifOutOctets" +type[10]="generic_data_inc" +description[10]="(MAC: _mac_ - Gi0/1_ifOutOctets)" +values[10]="RANDOM;0;1000" +unit[10]="bytes/s" +group[10]="Networking" + +name[11]="Gi0/2_ifOperStatus" +type[11]="generic_proc" +description[11]="(MAC: _mac_ - Gi0/2_ifOperStatus)" +values[11]="PROC;5" +group[11]="Networking" + +name[12]="Gi0/2_ifInOctets" +type[12]="generic_data_inc" +description[12]="(MAC: _mac_ - Gi0/2_ifInOctets)" +values[12]="RANDOM;0;1000" +unit[12]="bytes/s" +group[12]="Networking" + +name[13]="Gi0/2_ifOutOctets" +type[13]="generic_data_inc" +description[13]="(MAC: _mac_ - Gi0/2_ifOutOctets)" +values[13]="RANDOM;0;1000" +unit[13]="bytes/s" +group[13]="Networking" + +name[14]="Gi0/3_ifOperStatus" +type[14]="generic_proc" +description[14]="(MAC: _mac_ - Gi0/3_ifOperStatus)" +values[14]="PROC;5" +group[14]="Networking" + +name[15]="Gi0/3_ifInOctets" +type[15]="generic_data_inc" +description[15]="(MAC: _mac_ - Gi0/3_ifInOctets)" +values[15]="RANDOM;0;1000" +unit[15]="bytes/s" +group[15]="Networking" + +name[16]="Gi0/3_ifOutOctets" +type[16]="generic_data_inc" +description[16]="(MAC: _mac_ - Gi0/3_ifOutOctets)" +values[16]="RANDOM;0;1000" +unit[16]="bytes/s" +group[16]="Networking" + +name[17]="Gi0/4_ifOperStatus" +type[17]="generic_proc" +description[17]="(MAC: _mac_ - Gi0/4_ifOperStatus)" +values[17]="PROC;5" +group[17]="Networking" + +name[18]="Gi0/4_ifInOctets" +type[18]="generic_data_inc" +description[18]="(MAC: _mac_ - Gi0/4_ifInOctets)" +values[18]="RANDOM;0;1000" +unit[18]="bytes/s" +group[18]="Networking" + +name[19]="Gi0/4_ifOutOctets" +type[19]="generic_data_inc" +description[19]="(MAC: _mac_ - Gi0/4_ifOutOctets)" +values[19]="RANDOM;0;1000" +unit[19]="bytes/s" +group[19]="Networking" + +name[20]="Gi0/5_ifOperStatus" +type[20]="generic_proc" +description[20]="(MAC: _mac_ - Gi0/5_ifOperStatus)" +values[20]="PROC;5" +group[20]="Networking" + +name[21]="Gi0/5_ifInOctets" +type[21]="generic_data_inc" +description[21]="(MAC: _mac_ - Gi0/5_ifInOctets)" +values[21]="RANDOM;0;1000" +unit[21]="bytes/s" +group[21]="Networking" + +name[22]="Gi0/5_ifOutOctets" +type[22]="generic_data_inc" +description[22]="(MAC: _mac_ - Gi0/5_ifOutOctets)" +values[22]="RANDOM;0;1000" +unit[22]="bytes/s" +group[22]="Networking" + +name[23]="Gi0/6_ifOperStatus" +type[23]="generic_proc" +description[23]="(MAC: _mac_ - Gi0/6_ifOperStatus)" +values[23]="PROC;5" +group[23]="Networking" + +name[24]="Gi0/6_ifInOctets" +type[24]="generic_data_inc" +description[24]="(MAC: _mac_ - Gi0/6_ifInOctets)" +values[24]="RANDOM;0;1000" +unit[24]="bytes/s" +group[24]="Networking" + +name[25]="Gi0/6_ifOutOctets" +type[25]="generic_data_inc" +description[25]="(MAC: _mac_ - Gi0/6_ifOutOctets)" +values[25]="RANDOM;0;1000" +unit[25]="bytes/s" +group[25]="Networking" + +name[26]="Gi0/7_ifOperStatus" +type[26]="generic_proc" +description[26]="(MAC: _mac_ - Gi0/7_ifOperStatus)" +values[26]="PROC;5" +group[26]="Networking" + +name[27]="Gi0/7_ifInOctets" +type[27]="generic_data_inc" +description[27]="(MAC: _mac_ - Gi0/7_ifInOctets)" +values[27]="RANDOM;0;1000" +unit[27]="bytes/s" +group[27]="Networking" + +name[28]="Gi0/7_ifOutOctets" +type[28]="generic_data_inc" +description[28]="(MAC: _mac_ - Gi0/7_ifOutOctets)" +values[28]="RANDOM;0;1000" +unit[28]="bytes/s" +group[28]="Networking" + +name[29]="Gi0/8_ifOperStatus" +type[29]="generic_proc" +description[29]="(MAC: _mac_ - Gi0/8_ifOperStatus)" +values[29]="PROC;5" +group[29]="Networking" + +name[30]="Gi0/8_ifInOctets" +type[30]="generic_data_inc" +description[30]="(MAC: _mac_ - Gi0/8_ifInOctets)" +values[30]="RANDOM;0;1000" +unit[30]="bytes/s" +group[30]="Networking" + +name[31]="Gi0/8_ifOutOctets" +type[31]="generic_data_inc" +description[31]="(MAC: _mac_ - Gi0/8_ifOutOctets)" +values[31]="RANDOM;0;1000" +unit[31]="bytes/s" +group[31]="Networking" + +name[32]="Gi0/9_ifOperStatus" +type[32]="generic_proc" +description[32]="(MAC: _mac_ - Gi0/9_ifOperStatus)" +values[32]="PROC;5" +group[32]="Networking" + +name[33]="Gi0/9_ifInOctets" +type[33]="generic_data_inc" +description[33]="(MAC: _mac_ - Gi0/9_ifInOctets)" +values[33]="RANDOM;0;1000" +unit[33]="bytes/s" +group[33]="Networking" + +name[34]="Gi0/9_ifOutOctets" +type[34]="generic_data_inc" +description[34]="(MAC: _mac_ - Gi0/9_ifOutOctets)" +values[34]="RANDOM;0;1000" +unit[34]="bytes/s" +group[34]="Networking" + +name[35]="ipInReceives" +type[35]="generic_data" +description[35]="The total number of input datagrams received from interfaces" +values[35]="RANDOM;0;1000" +unit[35]="datagrams" +group[35]="Networking" + +name[36]="ipOutRequests" +type[36]="generic_data" +description[36]="The total number of output datagrams requested from interfaces" +values[36]="RANDOM;0;1000" +unit[36]="datagrams" +group[36]="Networking" + +name[37]="Latency" +type[37]="generic_data" +description[37]="Network latency" +values[37]="RANDOM;0;100" +unit[37]="msec" +group[37]="Networking" + +[traps] + +oid[1]=".1.3.6.1.4.1.9.9.41.1.2.3.1.2.0" +value[1]="RANDOM;0;100" +snmp_type[1]="6" +chance_percent[1]="20" + +oid[2]=".1.3.6.1.4.1.9.9.41.1.2.3.1.3.0" +value[2]="RANDOM;0;100" +snmp_type[2]="6" +chance_percent[2]="20" + +oid[3]=".1.3.6.1.4.1.9.9.41.1.2.3.1.4.0" +value[3]="RANDOM;0;100" +snmp_type[3]="6" +chance_percent[3]="20" + +oid[4]=".1.3.6.1.4.1.9.9.41.1.2.3.1.5.0" +value[4]="RANDOM;0;100" +snmp_type[4]="6" +chance_percent[4]="20" + +oid[5]=".1.3.6.1.4.1.9.9.41.1.2.3.1.6.0" +value[5]="RANDOM;0;100" +snmp_type[5]="6" +chance_percent[5]="20" \ No newline at end of file diff --git a/pandora_console/extras/demodata/dashboards/1-dashboard.prd b/pandora_console/extras/demodata/dashboards/1-dashboard.prd new file mode 100644 index 0000000000..f4a66d3692 --- /dev/null +++ b/pandora_console/extras/demodata/dashboards/1-dashboard.prd @@ -0,0 +1,65 @@ +[dashboard_data] + +name="Demo dashboard" +group="Demo dashboard" + +[dashboard_items] + +title[1]="Groups status" +type[1]="system_group_status" +x[1]="0" +y[1]="0" +width[1]="5" +height[1]="4" + +title[2]="Network map" +type[2]="network_map" +x[2]="5" +y[2]="0" +width[2]="7" +height[2]="6" +map_name[2]="Demo sunburst network map" + +title[3]="Module histogram" +type[3]="graph_module_histogram" +x[3]="0" +y[3]="4" +width[3]="5" +height[3]="2" +agent_name[3]="demo-global-agent-1" +module[3]="Host Alive" +interval[3]="86400" + +title[4]="List of latest events" +type[4]="events_list" +x[4]="0" +y[4]="6" +width[4]="12" +height[4]="5" + +title[5]="Top N events by agent" +type[5]="top_n_events_by_group" +x[5]="6" +y[5]="11" +width[5]="6" +height[5]="8" + +title[6]="Top N of agent modules" +type[6]="top_n" +x[6]="0" +y[6]="11" +width[6]="6" +height[6]="4" +agent_name[6]="cisco-.*" +module[6]=".*ifOutOctets" +interval[6]="86400" + +title[7]="Top N of agent modules" +type[7]="top_n" +x[7]="0" +y[7]="15" +width[7]="6" +height[7]="4" +agent_name[7]="cisco-.*" +module[7]=".*ifInOctets" +interval[7]="86400" \ No newline at end of file diff --git a/pandora_console/extras/demodata/gis_maps/1-gismap.prd b/pandora_console/extras/demodata/gis_maps/1-gismap.prd new file mode 100644 index 0000000000..84016c5279 --- /dev/null +++ b/pandora_console/extras/demodata/gis_maps/1-gismap.prd @@ -0,0 +1,16 @@ +[gis_data] + +name="Demo GIS map" +group="Demo servers" +zoom_level="6" +initial_latitude="40" +initial_longitude="-3" +initial_altitude="0" +default_latitude="40" +default_longitude="-3" +default_altitude="0" + +[gis_layers] + +name[1]="Demo servers" +group[1]="Demo servers" \ No newline at end of file diff --git a/pandora_console/extras/demodata/graphs/1-cpu-graph.prd b/pandora_console/extras/demodata/graphs/1-cpu-graph.prd new file mode 100644 index 0000000000..61b7ab456c --- /dev/null +++ b/pandora_console/extras/demodata/graphs/1-cpu-graph.prd @@ -0,0 +1,21 @@ +[graph_data] + +name="Linux CPU Load" +group="Demo servers" +description="This is a demo custom graph for linux agents CPU Load" +type="s_area" +periodicity="86400" + +[graph_items] + +agent_name[1]="linux-1" +module[1]="CPU Load" + +agent_name[2]="linux-2" +module[2]="CPU Load" + +agent_name[3]="linux-3" +module[3]="CPU Load" + +agent_name[4]="linux-4" +module[4]="CPU Load" \ No newline at end of file diff --git a/pandora_console/extras/demodata/graphs/2-disks-graph.prd b/pandora_console/extras/demodata/graphs/2-disks-graph.prd new file mode 100644 index 0000000000..cf3032c5f0 --- /dev/null +++ b/pandora_console/extras/demodata/graphs/2-disks-graph.prd @@ -0,0 +1,21 @@ +[graph_data] + +name="Linux Disk Usage" +group="Demo servers" +description="This is a demo custom graph for linux agents Disk Usage" +type="line" +periodicity="86400" + +[graph_items] + +agent_name[1]="linux-1" +module[1]="Disk Usage" + +agent_name[2]="linux-2" +module[2]="Disk Usage" + +agent_name[3]="linux-3" +module[3]="Disk Usage" + +agent_name[4]="linux-4" +module[4]="Disk Usage" \ No newline at end of file diff --git a/pandora_console/extras/demodata/graphs/3-network-usage-graph.prd b/pandora_console/extras/demodata/graphs/3-network-usage-graph.prd new file mode 100644 index 0000000000..3108b4cb7f --- /dev/null +++ b/pandora_console/extras/demodata/graphs/3-network-usage-graph.prd @@ -0,0 +1,27 @@ +[graph_data] + +name="Network Usage" +group="Demo servers" +description="This is a demo custom graph for linux and windows agents Network Usage" +type="s_area" +periodicity="86400" + +[graph_items] + +agent_name[1]="linux-1" +module[1]="Network Usage" + +agent_name[2]="linux-2" +module[2]="Network Usage" + +agent_name[3]="linux-3" +module[3]="Network Usage" + +agent_name[4]="linux-4" +module[4]="Network Usage" + +agent_name[5]="windows-1" +module[5]="Network Usage" + +agent_name[6]="windows-2" +module[6]="Network Usage" \ No newline at end of file diff --git a/pandora_console/extras/demodata/network_maps/1-networkmap.prd b/pandora_console/extras/demodata/network_maps/1-networkmap.prd new file mode 100644 index 0000000000..6a85d3625a --- /dev/null +++ b/pandora_console/extras/demodata/network_maps/1-networkmap.prd @@ -0,0 +1,143 @@ +[map_data] + +name="Demo network map" +group="Demo network" +description="This is a demo network map" +node_radius="40" +generation_method="circular" + +[map_items] + +agent_name[1]="cisco-1" +x[1]="854" +y[1]="221" + +agent_name[2]="freebsd-1" +x[2]="1184" +y[2]="-25" +parent[2]="1" + +agent_name[3]="macos-1" +x[3]="1268" +y[3]="235" +parent[3]="1" + +agent_name[4]="windows-1" +x[4]="528" +y[4]="-37" +parent[4]="1" + +agent_name[5]="windows-2" +x[5]="514" +y[5]="389" +parent[5]="1" + +agent_name[6]="linux-1" +x[6]="342" +y[6]="-273" +parent[6]="4" + +agent_name[7]="linux-2" +x[7]="240" +y[7]="-7" +parent[7]="4" + +agent_name[8]="linux-3" +x[8]="214" +y[8]="275" +parent[8]="5" + +agent_name[9]="linux-4" +x[9]="226" +y[9]="595" +parent[9]="5" + +agent_name[10]="cisco-2" +x[10]="1036" +y[10]="711" +parent[10]="1" + +agent_name[11]="freebsd-2" +x[11]="892" +y[11]="-47" +parent[11]="1" + +agent_name[12]="macos-2" +x[12]="1150" +y[12]="409" +parent[12]="1" + +agent_name[13]="windows-3" +x[13]="686" +y[13]="875" +parent[13]="10" + +agent_name[14]="windows-4" +x[14]="1452" +y[14]="847" +parent[14]="10" + +agent_name[15]="linux-5" +x[15]="314" +y[15]="845" +parent[15]="13" + +agent_name[16]="linux-6" +x[16]="474" +y[16]="1043" +parent[16]="13" + +agent_name[17]="linux-7" +x[17]="1812" +y[17]="1011" +parent[17]="14" + +agent_name[18]="linux-8" +x[18]="1828" +y[18]="723" +parent[18]="14" + +agent_name[19]="cisco-3" +x[19]="1824" +y[19]="285" +parent[19]="3" + +agent_name[20]="freebsd-3" +x[20]="-82" +y[20]="583" +parent[20]="9" + +agent_name[21]="macos-3" +x[21]="-140" +y[21]="299" +parent[21]="20" + +agent_name[22]="windows-5" +x[22]="-390" +y[22]="385" +parent[22]="20" + +agent_name[23]="windows-6" +x[23]="-470" +y[23]="671" +parent[23]="20" + +agent_name[24]="linux-9" +x[24]="-296" +y[24]="899" +parent[24]="20" + +agent_name[25]="linux-10" +x[25]="-25" +y[25]="961" +parent[25]="20" + +agent_name[26]="linux-11" +x[26]="1683" +y[26]="13" +parent[26]="19" + +agent_name[27]="linux-12" +x[27]="2135" +y[27]="51" +parent[27]="19" \ No newline at end of file diff --git a/pandora_console/extras/demodata/network_maps/2-sunburst-networkmap.prd b/pandora_console/extras/demodata/network_maps/2-sunburst-networkmap.prd new file mode 100644 index 0000000000..4bdac3ce97 --- /dev/null +++ b/pandora_console/extras/demodata/network_maps/2-sunburst-networkmap.prd @@ -0,0 +1,9 @@ +[map_data] + +name="Demo sunburst network map" +group="Demo servers" +description="This is a demo sunburst network map" +node_radius="40" +generation_method="radial_dynamic" + +[map_items] \ No newline at end of file diff --git a/pandora_console/extras/demodata/reports/1-linux-report.prd b/pandora_console/extras/demodata/reports/1-linux-report.prd new file mode 100644 index 0000000000..7a274eb968 --- /dev/null +++ b/pandora_console/extras/demodata/reports/1-linux-report.prd @@ -0,0 +1,84 @@ +[report_data] + +name="Linux report" +group="Demo servers" +description="This is a demo report for linux agents" + +[report_items] + +name[1]="Linux CPU Load graph" +type[1]="custom_graph" +graph_name[1]="Linux CPU Load" +periodicity[1]="86400" + +name[2]="linux-1 httpd" +type[2]="SLA" +agent_name[2]="linux-1" +module[2]="Service httpd" +periodicity[2]="86400" + +name[3]="linux-1 mysqld" +type[3]="SLA" +agent_name[3]="linux-1" +module[3]="Service mysqld" +periodicity[3]="86400" + +name[4]="linux-1 CPU Load graph" +type[4]="simple_graph" +agent_name[4]="linux-1" +module[4]="CPU Load" +periodicity[4]="86400" + +name[5]="linux-2 httpd" +type[5]="SLA" +agent_name[5]="linux-2" +module[5]="Service httpd" +periodicity[5]="86400" + +name[6]="linux-2 mysqld" +type[6]="SLA" +agent_name[6]="linux-2" +module[6]="Service mysqld" +periodicity[6]="86400" + +name[7]="linux-2 CPU Load graph" +type[7]="simple_graph" +agent_name[7]="linux-2" +module[7]="CPU Load" +periodicity[7]="86400" + +name[8]="linux-3 httpd" +type[8]="SLA" +agent_name[8]="linux-3" +module[8]="Service httpd" +periodicity[8]="86400" + +name[9]="linux-3 mysqld" +type[9]="SLA" +agent_name[9]="linux-3" +module[9]="Service mysqld" +periodicity[9]="86400" + +name[10]="linux-3 CPU Load graph" +type[10]="simple_graph" +agent_name[10]="linux-3" +module[10]="CPU Load" +periodicity[10]="86400" + +name[11]="linux-4 httpd" +type[11]="SLA" +agent_name[11]="linux-4" +module[11]="Service httpd" +periodicity[11]="86400" + +name[12]="linux-4 mysqld" +type[12]="SLA" +agent_name[12]="linux-4" +module[12]="Service mysqld" +periodicity[12]="86400" + +name[13]="linux-4 CPU Load graph" +type[13]="simple_graph" +agent_name[13]="linux-4" +module[13]="CPU Load" +periodicity[13]="86400" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/1-mysql-service.prd b/pandora_console/extras/demodata/services/1-mysql-service.prd new file mode 100644 index 0000000000..23e366e44a --- /dev/null +++ b/pandora_console/extras/demodata/services/1-mysql-service.prd @@ -0,0 +1,26 @@ +[service_data] + +name="MySQL service" +group="Demo services" +description="This is a demo service for MySQL" +mode="smart" +critical="50" +warning="30" + +[service_items] + +type[1]="module" +agent_name[1]="linux-1" +module[1]="Service mysqld" + +type[2]="module" +agent_name[2]="linux-2" +module[2]="Service mysqld" + +type[3]="module" +agent_name[3]="linux-3" +module[3]="Service mysqld" + +type[4]="module" +agent_name[4]="linux-4" +module[4]="Service mysqld" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/2-http-service.prd b/pandora_console/extras/demodata/services/2-http-service.prd new file mode 100644 index 0000000000..2257797134 --- /dev/null +++ b/pandora_console/extras/demodata/services/2-http-service.prd @@ -0,0 +1,26 @@ +[service_data] + +name="HTTP service" +group="Demo services" +description="This is a demo service for HTTP" +mode="smart" +critical="50" +warning="30" + +[service_items] + +type[1]="module" +agent_name[1]="linux-1" +module[1]="Service httpd" + +type[2]="module" +agent_name[2]="linux-2" +module[2]="Service httpd" + +type[3]="module" +agent_name[3]="linux-3" +module[3]="Service httpd" + +type[4]="module" +agent_name[4]="linux-4" +module[4]="Service httpd" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/3-parent-service.prd b/pandora_console/extras/demodata/services/3-parent-service.prd new file mode 100644 index 0000000000..a31f669735 --- /dev/null +++ b/pandora_console/extras/demodata/services/3-parent-service.prd @@ -0,0 +1,16 @@ +[service_data] + +name="Web cluster service" +group="Demo services" +description="This is a demo service for a clustered web" +mode="smart" +critical="50" +warning="50" + +[service_items] + +type[1]="service" +service_name[1]="MySQL service" + +type[2]="service" +service_name[2]="HTTP service" \ No newline at end of file diff --git a/pandora_console/extras/demodata/visual_consoles/1-cisco-visual-console.prd b/pandora_console/extras/demodata/visual_consoles/1-cisco-visual-console.prd new file mode 100644 index 0000000000..075f0ea051 --- /dev/null +++ b/pandora_console/extras/demodata/visual_consoles/1-cisco-visual-console.prd @@ -0,0 +1,509 @@ +[visual_console_data] + +name="Cisco visual console" +group="Demo network" +background_color="#000000" +width="1680" +height="945" + +[visual_console_items] + +type[1]="box" +width[1]="720" +height[1]="290" +x[1]="100" +y[1]="20" +border_color[1]="#cacab3" +fill_color[1]="#cacab3" + +type[2]="box" +width[2]="720" +height[2]="290" +x[2]="860" +y[2]="20" +border_color[2]="#cacab3" +fill_color[2]="#cacab3" + +type[3]="box" +width[3]="266" +height[3]="150" +x[3]="100" +y[3]="362" +border_color[3]="#352e28" +fill_color[3]="#352e28" + +type[4]="box" +width[4]="266" +height[4]="150" +x[4]="403" +y[4]="362" +border_color[4]="#352e28" +fill_color[4]="#352e28" + +type[5]="box" +width[5]="266" +height[5]="150" +x[5]="708" +y[5]="362" +border_color[5]="#352e28" +fill_color[5]="#352e28" + +type[6]="box" +width[6]="266" +height[6]="150" +x[6]="1013" +y[6]="362" +border_color[6]="#352e28" +fill_color[6]="#352e28" + +type[7]="box" +width[7]="266" +height[7]="150" +x[7]="1313" +y[7]="362" +border_color[7]="#352e28" +fill_color[7]="#352e28" + +type[8]="box" +width[8]="460" +height[8]="362" +x[8]="100" +y[8]="564" +border_color[8]="#b3cdc1" +fill_color[8]="#b3cdc1" + +type[9]="box" +width[9]="460" +height[9]="362" +x[9]="1115" +y[9]="557" +border_color[9]="#b3cdc1" +fill_color[9]="#b3cdc1" + +type[10]="label" +label_position[10]="down" +width[10]="0" +height[10]="20" +x[10]="135" +y[10]="50" +label[10]='

CPU Usage

' +show_on_top[10]=true + +type[11]="label" +label_position[11]="down" +width[11]="0" +height[11]="20" +x[11]="895" +y[11]="50" +label[11]='

Ping / Latency

' +show_on_top[11]=true + +type[12]="label" +label_position[12]="down" +width[12]="0" +height[12]="20" +x[12]="135" +y[12]="382" +label[12]='

Gi0/0 InOctets

' +show_on_top[12]=true + +type[13]="label" +label_position[13]="down" +width[13]="0" +height[13]="20" +x[13]="438" +y[13]="382" +label[13]='

Gi0/1 InOctets

' +show_on_top[13]=true + +type[14]="label" +label_position[14]="down" +width[14]="0" +height[14]="20" +x[14]="743" +y[14]="382" +label[14]='

Gi0/2 InOctets

' +show_on_top[14]=true + +type[15]="label" +label_position[15]="down" +width[15]="0" +height[15]="20" +x[15]="1048" +y[15]="382" +label[15]='

Gi0/3 InOctets

' +show_on_top[15]=true + +type[16]="label" +label_position[16]="down" +width[16]="0" +height[16]="20" +x[16]="1349" +y[16]="382" +label[16]='

Gi0/4 InOctets

' +show_on_top[16]=true + +type[17]="label" +label_position[17]="down" +width[17]="100" +height[17]="15" +x[17]="126" +y[17]="573" +label[17]='

Min

' +show_on_top[17]=true + +type[18]="label" +label_position[18]="down" +width[18]="100" +height[18]="15" +x[18]="126" +y[18]="640" +label[18]='

Max

' +show_on_top[18]=true + +type[19]="label" +label_position[19]="down" +width[19]="100" +height[19]="15" +x[19]="1137" +y[19]="564" +label[19]='

Min

' +show_on_top[19]=true + +type[20]="label" +label_position[20]="down" +width[20]="100" +height[20]="15" +x[20]="1137" +y[20]="626" +label[20]='

Max

' +show_on_top[20]=true + +type[21]="value" +label_position[21]="down" +width[21]="0" +height[21]="20" +x[21]="609" +y[21]="50" +label[21]='

Avg. last 24 hours: (_value_)

' +show_on_top[21]=true +agent_name[21]="cisco-1" +module[21]="CPU Usage (5 min avg)" +process[21]="avg" +interval[21]="86400" + +type[22]="value" +label_position[22]="down" +width[22]="0" +height[22]="20" +x[22]="135" +y[22]="96" +label[22]='

(_value_)

' +show_on_top[22]=true +agent_name[22]="cisco-1" +module[22]="CPU Usage (5 min avg)" + +type[23]="value" +label_position[23]="down" +width[23]="0" +height[23]="20" +x[23]="1364" +y[23]="50" +label[23]='

Avg. last 24 hours: (_value_)

' +show_on_top[23]=true +agent_name[23]="cisco-1" +module[23]="Latency" +process[23]="avg" +interval[23]="86400" + +type[24]="value" +label_position[24]="down" +width[24]="0" +height[24]="20" +x[24]="895" +y[24]="96" +label[24]='

(_value_)

' +show_on_top[24]=true +agent_name[24]="cisco-1" +module[24]="Latency" + +type[25]="value" +label_position[25]="down" +width[25]="0" +height[25]="20" +x[25]="135" +y[25]="472" +label[25]='

Avg. last 24 hours (_value_)

' +show_on_top[25]=true +agent_name[25]="cisco-1" +module[25]="Gi0/0_ifInOctets" +process[25]="avg" +interval[25]="86400" + +type[26]="value" +label_position[26]="down" +width[26]="0" +height[26]="20" +x[26]="135" +y[26]="417" +label[26]='

(_value_)

' +show_on_top[26]=true +agent_name[26]="cisco-1" +module[26]="Gi0/0_ifInOctets" + +type[27]="value" +label_position[27]="down" +width[27]="0" +height[27]="20" +x[27]="438" +y[27]="472" +label[27]='

Avg. last 24 hours (_value_)

' +show_on_top[27]=true +agent_name[27]="cisco-1" +module[27]="Gi0/1_ifInOctets" +process[27]="avg" +interval[27]="86400" + +type[28]="value" +label_position[28]="down" +width[28]="0" +height[28]="20" +x[28]="438" +y[28]="417" +label[28]='

(_value_)

' +show_on_top[28]=true +agent_name[28]="cisco-1" +module[28]="Gi0/1_ifInOctets" + +type[29]="value" +label_position[29]="down" +width[29]="0" +height[29]="20" +x[29]="743" +y[29]="472" +label[29]='

Avg. last 24 hours (_value_)

' +show_on_top[29]=true +agent_name[29]="cisco-1" +module[29]="Gi0/2_ifInOctets" +process[29]="avg" +interval[29]="86400" + +type[30]="value" +label_position[30]="down" +width[30]="0" +height[30]="20" +x[30]="743" +y[30]="417" +label[30]='

(_value_)

' +show_on_top[30]=true +agent_name[30]="cisco-1" +module[30]="Gi0/2_ifInOctets" + +type[31]="value" +label_position[31]="down" +width[31]="0" +height[31]="20" +x[31]="1048" +y[31]="472" +label[31]='

Avg. last 24 hours (_value_)

' +show_on_top[31]=true +agent_name[31]="cisco-1" +module[31]="Gi0/3_ifInOctets" +process[31]="avg" +interval[31]="86400" + +type[32]="value" +label_position[32]="down" +width[32]="0" +height[32]="20" +x[32]="1048" +y[32]="417" +label[32]='

(_value_)

' +show_on_top[32]=true +agent_name[32]="cisco-1" +module[32]="Gi0/3_ifInOctets" + +type[33]="value" +label_position[33]="down" +width[33]="0" +height[33]="20" +x[33]="1349" +y[33]="472" +label[33]='

Avg. last 24 hours (_value_)

' +show_on_top[33]=true +agent_name[33]="cisco-1" +module[33]="Gi0/4_ifInOctets" +process[33]="avg" +interval[33]="86400" + +type[34]="value" +label_position[34]="down" +width[34]="0" +height[34]="20" +x[34]="1349" +y[34]="417" +label[34]='

(_value_)

' +show_on_top[34]=true +agent_name[34]="cisco-1" +module[34]="Gi0/4_ifInOctets" + +type[35]="value" +label_position[35]="down" +width[35]="0" +height[35]="20" +x[35]="124" +y[35]="602" +label[35]='

(_value_)

' +show_on_top[35]=true +agent_name[35]="cisco-1" +module[35]=ipInReceives +process[35]="min" +interval[35]="86400" + +type[36]="value" +label_position[36]="down" +width[36]="0" +height[36]="20" +x[36]="124" +y[36]="669" +label[36]='

(_value_)

' +show_on_top[36]=true +agent_name[36]="cisco-1" +module[36]=ipInReceives +process[36]="max" +interval[36]="86400" + +type[37]="value" +label_position[37]="down" +width[37]="0" +height[37]="20" +x[37]="1138" +y[37]="591" +label[37]='

(_value_)

' +show_on_top[37]=true +agent_name[37]="cisco-1" +module[37]=ipOutRequests +process[37]="min" +interval[37]="86400" + +type[38]="value" +label_position[38]="down" +width[38]="0" +height[38]="20" +x[38]="1138" +y[38]="658" +label[38]='

(_value_)

' +show_on_top[38]=true +agent_name[38]="cisco-1" +module[38]=ipOutRequests +process[38]="max" +interval[38]="86400" + +type[39]="static_image" +image[39]="dot" +width[39]="30" +height[39]="36" +x[39]="701" +y[39]="595" +label[39]='

_module_

' +label_position[39]="right" +agent_name[39]="cisco-1" +module[39]="Gi0/0_ifOperStatus" + +type[40]="static_image" +image[40]="dot" +width[40]="30" +height[40]="36" +x[40]="701" +y[40]="655" +label[40]='

_module_

' +label_position[40]="right" +agent_name[40]="cisco-1" +module[40]="Gi0/1_ifOperStatus" + +type[41]="static_image" +image[41]="dot" +width[41]="30" +height[41]="36" +x[41]="701" +y[41]="713" +label[41]='

_module_

' +label_position[41]="right" +agent_name[41]="cisco-1" +module[41]="Gi0/2_ifOperStatus" + +type[42]="static_image" +image[42]="dot" +width[42]="30" +height[42]="36" +x[42]="701" +y[42]="771" +label[42]='

_module_

' +label_position[42]="right" +agent_name[42]="cisco-1" +module[42]="Gi0/3_ifOperStatus" + +type[43]="static_image" +image[43]="dot" +width[43]="30" +height[43]="36" +x[43]="701" +y[43]="828" +label[43]='

_module_

' +label_position[43]="right" +agent_name[43]="cisco-1" +module[43]="Gi0/4_ifOperStatus" + +type[44]="module_graph" +width[44]="652" +height[44]="110" +x[44]="135" +y[44]="166" +agent_name[44]="cisco-1" +module[44]="CPU Usage (5 min avg)" +image[44]="transparent" +graph_type[44]="area" +interval[44]="86400" +show_on_top[44]=true + +type[45]="module_graph" +width[45]="295" +height[45]="87" +x[45]="895" +y[45]="189" +agent_name[45]="cisco-1" +module[45]="Host Alive" +image[45]="transparent" +graph_type[45]="area" +interval[45]="86400" +show_on_top[45]=true + +type[46]="module_graph" +width[46]="295" +height[46]="87" +x[46]="1252" +y[46]="189" +agent_name[46]="cisco-1" +module[46]="Latency" +image[46]="transparent" +graph_type[46]="area" +interval[46]="86400" +show_on_top[46]=true + +type[47]="odometer" +width[47]="412" +height[47]="11" +x[47]="123" +y[47]="719" +agent_name[47]="cisco-1" +module[47]="ipInReceives" +show_on_top[47]=true + +type[48]="odometer" +width[48]="412" +height[48]="11" +x[48]="1142" +y[48]="710" +agent_name[48]="cisco-1" +module[48]="ipOutRequests" +show_on_top[48]=true \ No newline at end of file diff --git a/pandora_console/extras/demodata/visual_consoles/2-linux-visual-console.prd b/pandora_console/extras/demodata/visual_consoles/2-linux-visual-console.prd new file mode 100644 index 0000000000..975dfe7944 --- /dev/null +++ b/pandora_console/extras/demodata/visual_consoles/2-linux-visual-console.prd @@ -0,0 +1,295 @@ +[visual_console_data] + +name="Linux visual console" +group="Demo servers" +background_color="#f2f3f3" +width="1680" +height="945" + +[visual_console_items] + +type[1]="box" +width[1]="1205" +height[1]="560" +x[1]="30" +y[1]="30" +border_color[1]="#ffffff" +fill_color[1]="#ffffff" + +type[2]="box" +width[2]="386" +height[2]="560" +x[2]="1264" +y[2]="30" +border_color[2]="#ffffff" +fill_color[2]="#ffffff" + +type[3]="box" +width[3]="390" +height[3]="205" +x[3]="30" +y[3]="650" +border_color[3]="#eaf0ff" +fill_color[3]="#eaf0ff" + +type[4]="box" +width[4]="390" +height[4]="205" +x[4]="441" +y[4]="650" +border_color[4]="#fef1ea" +fill_color[4]="#fef1ea" + +type[5]="box" +width[5]="390" +height[5]="205" +x[5]="850" +y[5]="650" +border_color[5]="#d8daff" +fill_color[5]="#d8daff" + +type[6]="box" +width[6]="390" +height[6]="205" +x[6]="1264" +y[6]="650" +border_color[6]="#d4edd7" +fill_color[6]="#d4edd7" + +type[7]="label" +label_position[7]="down" +width[7]="239" +height[7]="20" +x[7]="60" +y[7]="60" +label[7]='

Network usage

' +show_on_top[7]=true + +type[8]="label" +label_position[8]="down" +width[8]="239" +height[8]="20" +x[8]="1282" +y[8]="48" +label[8]='

Performance

' +show_on_top[8]=true + +type[9]="label" +label_position[9]="down" +width[9]="239" +height[9]="20" +x[9]="60" +y[9]="680" +label[9]='

Service httpd

' +show_on_top[9]=true + +type[10]="label" +label_position[10]="down" +width[10]="239" +height[10]="20" +x[10]="470" +y[10]="680" +label[10]='

CPU Load

' +show_on_top[10]=true + +type[11]="label" +label_position[11]="down" +width[11]="239" +height[11]="20" +x[11]="880" +y[11]="680" +label[11]='

Memory usage

' +show_on_top[11]=true + +type[12]="label" +label_position[12]="down" +width[12]="239" +height[12]="20" +x[12]="1294" +y[12]="680" +label[12]='

Disk usage

' +show_on_top[12]=true + +type[13]="label" +label_position[13]="down" +width[13]="181" +height[13]="16" +x[13]="63" +y[13]="158" +label[13]='

Min. today

' +show_on_top[13]=true + +type[14]="label" +label_position[14]="down" +width[14]="181" +height[14]="16" +x[14]="469" +y[14]="158" +label[14]='

Avg. today

' +show_on_top[14]=true + +type[15]="label" +label_position[15]="down" +width[15]="181" +height[15]="16" +x[15]="879" +y[15]="158" +label[15]='

Max. today

' +show_on_top[15]=true + +type[16]="value" +label_position[16]="down" +width[16]="400" +height[16]="50" +x[16]="60" +y[16]="100" +label[16]='

(_value_)

' +show_on_top[16]=true +agent_name[16]="linux-1" +module[16]="Network Usage" +process[16]="min" +interval[16]="86400" + +type[17]="value" +label_position[17]="down" +width[17]="400" +height[17]="50" +x[17]="468" +y[17]="100" +label[17]='

(_value_)

' +show_on_top[17]=true +agent_name[17]="linux-1" +module[17]="Network Usage" +process[17]="avg" +interval[17]="86400" + +type[18]="value" +label_position[18]="down" +width[18]="400" +height[18]="50" +x[18]="876" +y[18]="100" +label[18]='

(_value_)

' +show_on_top[18]=true +agent_name[18]="linux-1" +module[18]="Network Usage" +process[18]="max" +interval[18]="86400" + +type[19]="value" +label_position[19]="down" +width[19]="330" +height[19]="30" +x[19]="470" +y[19]="722" +label[19]='

(_value_)

' +show_on_top[19]=true +agent_name[19]="linux-1" +module[19]="CPU Load" + +type[20]="value" +label_position[20]="down" +width[20]="330" +height[20]="30" +x[20]="880" +y[20]="722" +label[20]='

(_value_)

' +show_on_top[20]=true +agent_name[20]="linux-1" +module[20]="Memory Usage" + +type[21]="value" +label_position[21]="down" +width[21]="330" +height[21]="30" +x[21]="1294" +y[21]="722" +label[21]='

(_value_)

' +show_on_top[21]=true +agent_name[21]="linux-1" +module[21]="Disk Usage" + +type[22]="percentile" +width[22]="330" +height[22]="100" +x[22]="470" +y[22]="790" +show_on_top[22]=true +agent_name[22]="linux-1" +module[22]="CPU Load" +min[22]="0" +max[22]="100" + +type[23]="percentile" +width[23]="330" +height[23]="100" +x[23]="880" +y[23]="790" +show_on_top[23]=true +agent_name[23]="linux-1" +module[23]="Memory Usage" +min[23]="0" +max[23]="100" + +type[24]="percentile" +width[24]="330" +height[24]="100" +x[24]="1294" +y[24]="790" +show_on_top[24]=true +agent_name[24]="linux-1" +module[24]="Disk Usage" +min[24]="0" +max[24]="100" + +type[25]="module_graph" +width[25]="1150" +height[25]="320" +x[25]="58" +y[25]="196" +agent_name[25]="linux-1" +module[25]="Network Usage" +image[25]="transparent" +graph_type[25]="line" +interval[25]="86400" +show_on_top[25]=true + +type[26]="basic_chart" +width[26]="325" +height[26]="110" +x[26]="1294" +y[26]="100" +agent_name[26]="linux-1" +module[26]="CPU Load" +interval[26]="86400" +show_on_top[26]=true + +type[27]="basic_chart" +width[27]="325" +height[27]="110" +x[27]="1294" +y[27]="268" +agent_name[27]="linux-1" +module[27]="Memory Usage" +interval[27]="86400" +show_on_top[27]=true + +type[28]="basic_chart" +width[28]="325" +height[28]="110" +x[28]="1294" +y[28]="432" +agent_name[28]="linux-1" +module[28]="Disk Usage" +interval[28]="86400" +show_on_top[28]=true + +type[29]="event_history" +width[29]="330" +height[29]="103" +x[29]="60" +y[29]="713" +show_on_top[29]=true +agent_name[29]="linux-1" +module[29]="Service httpd" +interval[29]="86400" \ No newline at end of file diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index f4fb6698e4..62c5617d45 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -1,5 +1,380 @@ START TRANSACTION; +CREATE TABLE IF NOT EXISTS `tdemo_data` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `item_id` INT UNSIGNED NULL DEFAULT NULL, + `table_name` VARCHAR(64) NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +SET @class_name = 'AgentHive'; +SET @unique_name = 'AgentHive'; +SET @description = 'Agents hive'; +SET @page = 'AgentHive.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'AvgSumMaxMinModule'; +SET @unique_name = 'AvgSumMaxMinModule'; +SET @description = 'Avg|Sum|Max|Min Module Data'; +SET @page = 'AvgSumMaxMinModule.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'BasicChart'; +SET @unique_name = 'BasicChart'; +SET @description = 'Basic chart'; +SET @page = 'BasicChart.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'BlockHistogram'; +SET @unique_name = 'BlockHistogram'; +SET @description = 'Block histogram'; +SET @page = 'BlockHistogram.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ColorModuleTabs'; +SET @unique_name = 'ColorModuleTabs'; +SET @description = 'Color tabs modules'; +SET @page = 'ColorModuleTabs.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'DataMatrix'; +SET @unique_name = 'DataMatrix'; +SET @description = 'Data Matrix'; +SET @page = 'DataMatrix.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'EventCardboard'; +SET @unique_name = 'EventCardboard'; +SET @description = 'Event cardboard'; +SET @page = 'EventCardboard.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'GroupedMeterGraphs'; +SET @unique_name = 'GroupedMeterGraphs'; +SET @description = 'Grouped meter graphs'; +SET @page = 'GroupedMeterGraphs.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModulesByStatus'; +SET @unique_name = 'ModulesByStatus'; +SET @description = 'Modules by status'; +SET @page = 'ModulesByStatus.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'AgentModuleWidget'; +SET @unique_name = 'agent_module'; +SET @description = 'Agent/Module View'; +SET @page = 'agent_module.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'AlertsFiredWidget'; +SET @unique_name = 'alerts_fired'; +SET @description = 'Triggered alerts report'; +SET @page = 'alerts_fired.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ClockWidget'; +SET @unique_name = 'clock'; +SET @description = 'Clock'; +SET @page = 'clock.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'CustomGraphWidget'; +SET @unique_name = 'custom_graph'; +SET @description = 'Defined custom graph'; +SET @page = 'custom_graph.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'EventsListWidget'; +SET @unique_name = 'events_list'; +SET @description = 'List of latest events'; +SET @page = 'events_list.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'WelcomeWidget'; +SET @unique_name = 'example'; +SET @description = 'Welcome message to Pandora FMS'; +SET @page = 'example.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'GraphModuleHistogramWidget'; +SET @unique_name = 'graph_module_histogram'; +SET @description = 'Module histogram'; +SET @page = 'graph_module_histogram.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'GroupsStatusWidget'; +SET @unique_name = 'groups_status'; +SET @description = 'General group status'; +SET @page = 'groups_status.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'GroupsStatusMapWidget'; +SET @unique_name = 'groups_status_map'; +SET @description = 'Group status map'; +SET @page = 'groups_status_map.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'HeatmapWidget'; +SET @unique_name = 'heatmap'; +SET @description = 'Heatmap'; +SET @page = 'heatmap.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'InventoryWidget'; +SET @unique_name = 'inventory'; +SET @description = 'Inventory'; +SET @page = 'inventory.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'MapsMadeByUser'; +SET @unique_name = 'maps_made_by_user'; +SET @description = 'Visual Console'; +SET @page = 'maps_made_by_user.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'MapsStatusWidget'; +SET @unique_name = 'maps_status'; +SET @description = 'General visual maps report'; +SET @page = 'maps_status.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModuleIconWidget'; +SET @unique_name = 'module_icon'; +SET @description = 'Icon and module value'; +SET @page = 'module_icon.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModuleStatusWidget'; +SET @unique_name = 'module_status'; +SET @description = 'Module status'; +SET @page = 'module_status.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModuleTableValueWidget'; +SET @unique_name = 'module_table_value'; +SET @description = 'Module in a table'; +SET @page = 'module_table_value.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModuleValueWidget'; +SET @unique_name = 'module_value'; +SET @description = 'Module value'; +SET @page = 'module_value.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'MonitorHealthWidget'; +SET @unique_name = 'monitor_health'; +SET @description = 'Global health info'; +SET @page = 'monitor_health.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'Netflow'; +SET @unique_name = 'netflow'; +SET @description = 'Netflow'; +SET @page = 'netflow.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'NetworkMapWidget'; +SET @unique_name = 'network_map'; +SET @description = 'Network map'; +SET @page = 'network_map.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'OsQuickReportWidget'; +SET @unique_name = 'os_quick_report'; +SET @description = 'OS quick report'; +SET @page = 'os_quick_report.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'PostWidget'; +SET @unique_name = 'post'; +SET @description = 'Panel with a message'; +SET @page = 'post.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ReportsWidget'; +SET @unique_name = 'reports'; +SET @description = 'Custom report'; +SET @page = 'reports.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ServiceMapWidget'; +SET @unique_name = 'service_map'; +SET @description = 'Service map'; +SET @page = 'service_map.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ServiceViewWidget'; +SET @unique_name = 'service_view'; +SET @description = 'Services view'; +SET @page = 'service_view.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'SingleGraphWidget'; +SET @unique_name = 'single_graph'; +SET @description = 'Agent module graph'; +SET @page = 'single_graph.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'SLAPercentWidget'; +SET @unique_name = 'sla_percent'; +SET @description = 'SLA percentage'; +SET @page = 'sla_percent.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'SystemGroupStatusWidget'; +SET @unique_name = 'system_group_status'; +SET @description = 'Groups status'; +SET @page = 'system_group_status.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TacticalWidget'; +SET @unique_name = 'tactical'; +SET @description = 'Tactical view'; +SET @page = 'tactical.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TopNWidget'; +SET @unique_name = 'top_n'; +SET @description = 'Top N of agent modules'; +SET @page = 'top_n.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TopNEventByGroupWidget'; +SET @unique_name = 'top_n_events_by_group'; +SET @description = 'Top N events by agent'; +SET @page = 'top_n_events_by_group.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TopNEventByModuleWidget'; +SET @unique_name = 'top_n_events_by_module'; +SET @description = 'Top N events by module'; +SET @page = 'top_n_events_by_module.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TreeViewWidget'; +SET @unique_name = 'tree_view'; +SET @description = 'Tree view'; +SET @page = 'tree_view.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'UrlWidget'; +SET @unique_name = 'url'; +SET @description = 'URL content'; +SET @page = 'url.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'WuxWidget'; +SET @unique_name = 'wux_transaction'; +SET @description = 'Agent WUX transaction'; +SET @page = 'wux_transaction.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'WuxStatsWidget'; +SET @unique_name = 'wux_transaction_stats'; +SET @description = 'WUX transaction stats'; +SET @page = 'wux_transaction_stats.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'SecurityHardening'; +SET @unique_name = 'security_hardening'; +SET @description = 'Security Hardening'; +SET @page = 'security_hardening.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + DELETE FROM `tconfig` WHERE `token` LIKE 'translate_string_extension_installed'; CREATE TABLE IF NOT EXISTS `textension_translate_string` ( diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index a32b9dadc3..2c6661c1f6 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -498,6 +498,9 @@ if ($access_console_node === true) { $sub2['godmode/setup/setup§ion=welcome_tips']['text'] = __('Welcome Tips'); $sub2['godmode/setup/setup§ion=welcome_tips']['refr'] = 0; + $sub2['godmode/setup/setup§ion=demo_data']['text'] = __('Demo data'); + $sub2['godmode/setup/setup§ion=demo_data']['refr'] = 0; + if ((bool) $config['activate_gis'] === true) { $sub2['godmode/setup/setup§ion=gis']['text'] = __('Map conections GIS'); } diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php new file mode 100644 index 0000000000..29dc997ea4 --- /dev/null +++ b/pandora_console/godmode/setup/demo.php @@ -0,0 +1,878 @@ + 'graphs', + DEMO_NETWORK_MAP => 'network_maps', + DEMO_GIS_MAP => 'gis_maps', + DEMO_SERVICE => 'services', + DEMO_REPORT => 'reports', + DEMO_DASHBOARD => 'dashboards', + DEMO_VISUAL_CONSOLE => 'visual_consoles', +]; + +$enabled_items = [ + 'graphs' => (int) get_parameter('enable_cg', $def_value), + 'network_maps' => (int) get_parameter('enable_nm', $def_value), + 'gis_maps' => (int) get_parameter('enable_gis', $def_value), + 'services' => (int) get_parameter('enable_services', $def_value), + 'reports' => (int) get_parameter('enable_rep', $def_value), + 'dashboards' => (int) get_parameter('enable_dashboards', $def_value), + 'visual_consoles' => (int) get_parameter('enable_vc', $def_value), + 'enable_history' => (int) get_parameter('enable_history', 0), +]; + +$generate_hist = (int) get_parameter('enable_history', $def_value); + +$plugin_agent = get_parameter('plugin_agent', 'demo-global-agent-1'); +$traps_target_ip = get_parameter('traps_target_ip', '127.0.0.1'); +$traps_community = get_parameter('traps_community', 'public'); +$tentacle_target_ip = get_parameter('tentacle_target_ip', '127.0.0.1'); +$tentacle_port = get_parameter('tentacle_port', '41121'); +$tentacle_extra_options = get_parameter('tentacle_extra_options', ''); + +$demo_items_count = (int) db_get_value('count(*)', 'tdemo_data'); + +$current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', + false, + false +); + +$current_progress_val_delete = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_delete_progress'], + 'AND', + false, + false +); + +$running_create = ($current_progress_val > 0 && $current_progress_val < 100); +$running_delete = ($current_progress_val_delete > 0 && $current_progress_val_delete < 100); + +// Real time loading. +if ($display_loading === true || $running_create === true || $running_delete) { + $table_load = new stdClass(); + $table_load->id = 'table-demo'; + $table_load->class = 'filter-table-adv'; + $table_load->width = '100%'; + $table_load->data = []; + $table_load->size = []; + $table_load->size[0] = '50%'; + $table_load->size[1] = '50%'; + + $table_load->data['row0'][] = progress_bar( + 0, + 100, + 20, + '', + 0, + false, + ((int) 0 !== -1) ? false : '#f3b200', + [ + 'class' => 'progress_bar', + 'id' => 'progress_bar', + ] + ).html_print_input_hidden('js_timer_'.$operation['id'], 0, true); + + if ($create_data === true || $running_create === true) { + // Map demo item ID to display name in page. + $items_ids_text_map = [ + DEMO_AGENT => 'agents', + DEMO_SERVICE => 'services', + DEMO_NETWORK_MAP => 'network maps', + DEMO_GIS_MAP => 'GIS maps', + DEMO_CUSTOM_GRAPH => 'custom graphs', + DEMO_REPORT => 'custom reports', + DEMO_VISUAL_CONSOLE => 'visual consoles', + DEMO_DASHBOARD => 'dashboards', + ]; + + if ((bool) $adv_options_is_enabled === true) { + $enabled_keys = array_keys(array_filter($enabled_items)); + $items_ids_text_map = array_filter( + $items_ids_text_map, + function ($k) use ($dir_item_id_map, $enabled_keys) { + return in_array($dir_item_id_map[$k], $enabled_keys); + }, + ARRAY_FILTER_USE_KEY + ); + } + + if (enterprise_installed() === false) { + unset($items_ids_text_map[DEMO_SERVICE]); + } + + $items_ids_text_map[DEMO_PLUGIN] = 'plugin'; + $items_ids_text_map = ([DEMO_AGENT => 'agents'] + $items_ids_text_map); + + $list_mkup = ''; + } + + echo '
'; + echo '
'; + echo ''.__('Progress').''; + html_print_table($table_load); + echo $list_mkup; + + echo '
'; + + if ($create_data === true || $running_create === true) { + $btn_span = __('View summary'); + $icon = 'next'; + } else { + $btn_span = __('Back'); + $icon = 'back'; + } + + + $action_btns = html_print_action_buttons( + html_print_submit_button( + $btn_span, + 'redirect_button', + false, + [ + 'icon' => $icon, + ], + true + ), + [], + true + ); + + // Only rendered when data creation has been completed. + html_print_div( + [ + 'id' => 'action-btns-loading-done', + 'class' => 'invisible', + 'content' => $action_btns, + ] + ); + + echo '
'; +} else { + // Configuration. + if ($demo_items_count === 0) { + $table_aux = new stdClass(); + $table_aux->id = 'table-demo'; + $table_aux->class = 'filter-table-adv'; + $table_aux->width = '100%'; + $table_aux->data = []; + $table_aux->size = []; + $table_aux->size[0] = '50%'; + $table_aux->size[1] = '50%'; + + $agent_sel_values = [ + 30 => '30', + 50 => '50', + 500 => '500', + 1000 => '1000', + 2000 => '2000', + ]; + + $agent_num = (int) get_parameter('agents_num'); + + $otherData = []; + $table_aux->data['row1'][] = html_print_label_input_block( + __('Agents').ui_print_help_tip(__('You may need to increase the value of the plugin_timeout parameter in your server configuration to get all your agents data updated'), true), + html_print_div( + [ + 'class' => '', + 'content' => html_print_select( + $agent_sel_values, + 'agents_num', + $agents_num, + '', + '', + 30, + true, + false, + true, + 'w80px' + ), + ], + true + ) + ); + + $table_aux->data['row2'][] = html_print_label_input_block( + __('Advanced options'), + html_print_checkbox_switch( + 'toggle_adv_opts', + 1, + false, + true + ) + ); + + $table_adv = new stdClass(); + $table_adv->id = 'table-adv'; + $table_adv->class = 'filter-table-adv'; + $table_adv->width = '100%'; + $table_adv->data = []; + $table_adv->size = []; + $table_adv->size[0] = '50%'; + $table_adv->size[1] = '50%'; + + $interval_select = html_print_extended_select_for_time( + 'interval', + $interval, + '', + '', + '0', + 10, + true, + false, + true, + 'w20p' + ); + + $table_adv->data['row0'][] = html_print_label_input_block( + __('Agents interval'), + $interval_select + ); + + $table_adv->data['row1'][] = html_print_label_input_block( + __('Generate historical data for all agents'), + html_print_checkbox_switch( + 'enable_history', + 1, + (bool) $generate_hist, + true + ) + ); + + $table_adv->data['row2'][] = html_print_label_input_block( + __('Days of historical data to insert in the agent data'), + html_print_input_text( + 'days_hist_data', + $days_hist_data, + '', + 10, + 20, + true, + false, + false, + '', + 'w80px' + ) + ); + + if (enterprise_installed() === true) { + $table_adv->data['row3'][] = html_print_label_input_block( + __('Create services'), + html_print_checkbox_switch( + 'enable_services', + 1, + $enabled_items['services'], + true + ) + ); + + + + /* + $table_adv->data['row4'][] = html_print_label_input_block( + __('Services agent name').ui_print_help_tip(__('If not set, %s will be used as the default agent', 'demo-global-agent-1'), true), + html_print_input_text( + 'service_agent_name', + $service_agent_name, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + */ + } + + $table_adv->data['row5'][] = html_print_label_input_block( + __('Create network maps'), + html_print_checkbox_switch( + 'enable_nm', + 1, + $enabled_items['network_maps'], + true + ) + ); + + $table_adv->data['row6'][] = html_print_label_input_block( + __('Create GIS maps'), + html_print_checkbox_switch( + 'enable_gis', + 1, + $enabled_items['gis_maps'], + true + ) + ); + + $table_adv->data['row7'][] = html_print_label_input_block( + __('Create custom graphs'), + html_print_checkbox_switch( + 'enable_cg', + 1, + $enabled_items['graphs'], + true + ) + ); + + $table_adv->data['row8'][] = html_print_label_input_block( + __('Create reports'), + html_print_checkbox_switch( + 'enable_rep', + 1, + $enabled_items['reports'], + true + ) + ); + + $table_adv->data['row9'][] = html_print_label_input_block( + __('Create visual consoles'), + html_print_checkbox_switch( + 'enable_vc', + 1, + $enabled_items['visual_consoles'], + true + ) + ); + + $table_adv->data['row10'][] = html_print_label_input_block( + __('Create dashboards'), + html_print_checkbox_switch( + 'enable_dashboards', + 1, + $enabled_items['dashboards'], + true + ) + ); + + /* + $table_adv->data['row11'][] = html_print_label_input_block( + __('Demo data plugin agent'), + html_print_input_text( + 'plugin_agent', + $plugin_agent, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + */ + + $table_adv->data['row12'][] = html_print_label_input_block( + __('Traps target IP').ui_print_help_tip(__('All demo traps are generated using version 1'), true), + html_print_input_text( + 'traps_target_ip', + $traps_target_ip, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + $table_adv->data['row13'][] = html_print_label_input_block( + __('Traps community'), + html_print_input_text( + 'traps_community', + $traps_community, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + $table_adv->data['row14'][] = html_print_label_input_block( + __('Tentacle target IP'), + html_print_input_text( + 'tentacle_target_ip', + $tentacle_target_ip, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + $table_adv->data['row15'][] = html_print_label_input_block( + __('Tentacle port'), + html_print_input_text( + 'tentacle_port', + $tentacle_port, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + $table_adv->data['row16'][] = html_print_label_input_block( + __('Tentacle extra options'), + html_print_input_text( + 'tentacle_extra_options', + $tentacle_extra_options, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + echo '
'; + echo '
'; + echo ''.__('Configure demo data').''; + html_print_input_hidden('create_data', 1); + html_print_input_hidden('display_loading', 1); + html_print_table($table_aux); + html_print_div( + [ + 'class' => 'invisible', + 'content' => html_print_table($table_adv), + ], + true + ); + echo '
'; + + $actionButtons = []; + + $actionButtons[] = html_print_submit_button( + __('Create demo data'), + 'create_button', + false, + [ + 'icon' => 'update', + 'fixed_id' => 'btn-create-demo-data', + ], + true + ); + + // echo ''; + + echo '
'; + } else { + // Summary data. + $demo_agents_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); + $demo_services_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tservice'); + $demo_nm_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tmap'); + $demo_gis_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tgis_map'); + $demo_cg_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tgraph'); + $demo_rep_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'treport'); + $demo_vc_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tlayout'); + $demo_dashboards_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tdashboard'); + + $table_summary = new stdClass(); + $table_summary->id = 'table-summary'; + $table_summary->class = 'filter-table-adv'; + $table_summary->width = '100%'; + $table_summary->data = []; + $table_summary->size = []; + $table_summary->size[0] = '50%'; + $table_summary->size[1] = '50%'; + + $i = 0; + $table_summary->data[$i][0] = __('Agents'); + $table_summary->data[$i][1] = ($demo_agents_count > 0) ? $demo_agents_count : '-'; + $i++; + + if (enterprise_installed() === true) { + $table_summary->data[$i][0] = __('Services'); + $table_summary->data[$i][1] = ($demo_services_count > 0) ? $demo_services_count : '-'; + $i++; + } + + $i++; + $table_summary->data[$i][0] = __('Network maps'); + $table_summary->data[$i][1] = ($demo_nm_count > 0) ? $demo_nm_count : '-'; + $i++; + $table_summary->data[$i][0] = __('GIS maps'); + $table_summary->data[$i][1] = ($demo_gis_count > 0) ? $demo_gis_count : '-'; + $i++; + $table_summary->data[$i][0] = __('Custom graphs'); + $table_summary->data[$i][1] = ($demo_cg_count > 0) ? $demo_cg_count : '-'; + $i++; + $table_summary->data[$i][0] = __('Custom reports'); + $table_summary->data[$i][1] = ($demo_rep_count > 0) ? $demo_rep_count : '-'; + $i++; + $table_summary->data[$i][0] = __('Visual consoles'); + $table_summary->data[$i][1] = ($demo_vc_count > 0) ? $demo_vc_count : '-'; + $i++; + $table_summary->data[$i][0] = __('Dashboards'); + $table_summary->data[$i][1] = ($demo_dashboards_count > 0) ? $demo_dashboards_count : '-'; + + echo '
'; + echo '
'; + echo ''.__('Active demo data summary').''; + html_print_table($table_summary); + echo '
'; + + html_print_input_hidden('delete_data', 1); + html_print_input_hidden('display_loading', 1); + + html_print_action_buttons( + html_print_submit_button( + __('Delete all demo data'), + 'delete_button', + false, + [ + 'icon' => 'delete', + 'mode' => 'secondary', + 'fixed_id' => 'btn-delete-demo-data', + ], + true + ) + ); + echo '
'; + } +} + + +?> + + \ No newline at end of file diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 1de74e1123..df6dcc1eb6 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -243,6 +243,11 @@ $buttons['welcome_tips'] = [ 'text' => ''.html_print_image('images/inventory.png', true, ['title' => __('Welcome tips'), 'class' => 'invert_filter']).'', ]; +$buttons['demo_data'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/demo_data.png', true, ['title' => __('Demo data'), 'class' => 'invert_filter']).'', +]; + if ($config['activate_gis']) { $buttons['gis'] = [ 'active' => false, @@ -351,6 +356,12 @@ switch ($section) { $help_header = ''; break; + case 'demo_data': + $buttons['demo_data']['active'] = true; + $subpage = __('Demo data'); + $help_header = ''; + break; + case 'enterprise': $buttons['enterprise']['active'] = true; $subpage = __('Enterprise'); @@ -470,6 +481,10 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/welcome_tips.php'; break; + case 'demo_data': + include_once $config['homedir'].'/godmode/setup/demo.php'; + break; + default: enterprise_hook('setup_enterprise_select_tab', [$section]); break; diff --git a/pandora_console/images/demo_data.png b/pandora_console/images/demo_data.png new file mode 100644 index 0000000000..edc30ceaf6 Binary files /dev/null and b/pandora_console/images/demo_data.png differ diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php new file mode 100644 index 0000000000..5f5818cf58 --- /dev/null +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -0,0 +1,3706 @@ + $file], $current_parsed_ini); + } + } + } + + if (enterprise_installed() === false) { + unset($parsed_ini['services']); + } + + $total_agents_to_create = (int) get_parameter('agents_num', 30); + $total_items_count = count($parsed_ini); + + if ($total_agents_to_create > 0) { + $agents_to_create = 0; + $agents_created_count = []; + $agents_last_ip = []; + + // First loop over agents to get the total agents to be created and init agent created count for each agent. + foreach ($parsed_ini['agents'] as $ini_agent_data) { + if (isset($ini_agent_data['agent_data']['agents_number']) === true + && $ini_agent_data['agent_data']['agents_number'] > 0 + ) { + $agents_to_create += (int) $ini_agent_data['agent_data']['agents_number']; + $agents_created_count[$ini_agent_data['agent_data']['agent_alias']] = 0; + $agents_last_ip[$ini_agent_data['agent_data']['agent_alias']] = null; + } + } + + $agent_created_total = 0; + $agent_data_values_buffer = []; + // TRAPS HISTORY: Removed due to performance issues + //$agent_traps_values_buffer = []; + + if ($total_agents_to_create > 0 && $agents_to_create > 0) { + while ($agent_created_total < ($total_agents_to_create - 1)) { + if (count($parsed_ini['agents']) === 0) { + register_error(DEMO_AGENT, __('No configuration files found or failed to parse files')); + break; + } + + // Get first server: general value for all created modules. . + $server_name = db_get_value('name', 'tserver', 'id_server', 1); + + // Traverse agent ini files and create agents. + foreach ($parsed_ini['agents'] as $ini_agent_data) { + $filename = $ini_agent_data['filename']; + $agent_data = $ini_agent_data['agent_data']; + + if (isset($agent_data['agents_number']) === true + && !((int) $agent_data['agents_number'] > 0) + ) { + // No agents are specified to be created for this agent. + continue; + } + + if (isset($agent_data['agent_name']) === false + || is_string($agent_data['agent_name']) === false + || isset($agent_data['agent_alias']) === false + || is_string($agent_data['agent_alias']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: name and/or alias is not specified or does not have a valid format. Skipping agent creation', $filename), + true + ); + continue; + } + + $iter_agents_to_create = $agent_data['agents_number']; + + if (($agent_created_total + $iter_agents_to_create) >= $total_agents_to_create) { + // Total agents limit specified by user has been reached. + break; + } else { + // Calculate max number of agents that can be created in this iteration until max number specified by user is reached. + $max_agents_to_limit = ($total_agents_to_create - ($agent_created_total + $iter_agents_to_create)); + } + + $modules_data = $ini_agent_data['modules']; + $inventory = $ini_agent_data['inventory']; + $inventory_values = $ini_agent_data['inventory_values']; + $traps = $ini_agent_data['traps']; + + $address_network = $agent_data['address_network']; + + if (isset($agent_data['mac']) === true && is_string($agent_data['mac']) === true) { + $mac = $agent_data['mac']; + if ($agent_data['mac'] === '__randomMAC__') { + $mac = generateRandomMacAddress(); + } + } + + if (isset($address_network) === false || is_string($address_network) === false) { + // Agent address is not specified or not valid. + register_error( + DEMO_AGENT, + __('Error in %s: address is not specified or does not have a valid format. Skipping agent creation', $filename), + true + ); + continue; + } + + $os_versions = $agent_data['os_versions']; + $os_name = $agent_data['os_name']; + $group_name = $agent_data['group']; + + // Get OS id given OS name. + $id_os = db_get_value_filter('id_os', 'tconfig_os', ['name' => $os_name]); + + if ($id_os === false) { + // Create OS if does not exist. + $values = ['name' => $os_name]; + $id_os = db_process_sql_insert('tconfig_os', $values); + + if ($id_os === false) { + // Could not create OS. Skip agent creation. + register_error( + DEMO_AGENT, + __('Error in %s: failed to create the specified operating system. Skipping agent creation', $filename), + true + ); + continue; + } + + if ($id_os > 0) { + // Register created OS in tdemo_data. + $values = [ + 'item_id' => $id_os, + 'table_name' => 'tconfig_os', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback OS creation if could not be registered in tdemo_data. + db_process_sql_delete('tconfig_os', ['id_os' => $id_os]); + continue; + } + } + } + + $group_id = get_group_or_create_demo_group($group_name); + + $agent_interval = ($adv_options_is_enabled === true) ? $interval : 300; + + $iter_agents_created = 0; + + // Create agents (remaining number of agents to reach number specified by user). + for ($i = 0; $i < min($iter_agents_to_create, $max_agents_to_limit); $i++) { + $curr_ip_address = ($agents_last_ip[$agent_data['agent_alias']] !== null) ? $agents_last_ip[$agent_data['agent_alias']] : $address_network; + $next_ip_address = calculateNextHostAddress($curr_ip_address); + $host_address = explode('/', $next_ip_address)[0]; + $agents_last_ip[$agent_data['agent_alias']] = $next_ip_address; + + $os_version = current($os_versions); + next($os_versions); + + if (current($os_versions) === false) { + reset($os_versions); + } + + $latitude = 0; + $longitude = 0; + $altitude = 0; + + if (isset($agent_data['latitude']) === true) { + $gis_parsed = explode(';', $agent_data['latitude']); + if ((string) $gis_parsed[0] === 'RANDOM') { + $latitude = rand($gis_parsed[1], $gis_parsed[2]); + } else { + $latitude = $agent_data['latitude']; + } + } + + if (isset($agent_data['longitude']) === true) { + $gis_parsed = explode(';', $agent_data['longitude']); + if ((string) $gis_parsed[0] === 'RANDOM') { + $longitude = rand($gis_parsed[1], $gis_parsed[2]); + } else { + $longitude = $agent_data['longitude']; + } + } + + if (isset($agent_data['altitude']) === true) { + $gis_parsed = explode(';', $agent_data['altitude']); + if ((string) $gis_parsed[0] === 'RANDOM') { + $altitude = rand($gis_parsed[1], $gis_parsed[2]); + } else { + $altitude = $agent_data['altitude']; + } + } + + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + + $values = [ + 'server_name' => $server_name, + 'id_os' => $id_os, + 'os_version' => $os_version, + 'ultimo_contacto' => $current_date_time, + 'ultimo_contacto_remoto' => $current_date_time, + ]; + + $create_alias = $agent_data['agent_alias'].'-'.($agents_created_count[$agent_data['agent_alias']] + 1); + $created_agent_id = agents_create_agent( + $create_alias, + $group_id, + $agent_interval, + $host_address, + $values, + true + ); + + if ($created_agent_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_agent_id, + 'table_name' => 'tagente', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback agent creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente', ['id_agente' => $created_agent_id]); + + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create agent %s', $filename, $create_alias), + true + ); + + continue; + } + } else { + // Could not create agent. Skip. + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create agent %s', $filename, $create_alias), + true + ); + continue; + } + + // Register GIS data + $values = [ + 'tagente_id_agente' => $created_agent_id, + 'current_longitude' => $longitude, + 'current_latitude' => $latitude, + 'current_altitude' => $altitude, + 'stored_longitude' => $longitude, + 'stored_latitude' => $latitude, + 'stored_altitude' => $altitude, + 'number_of_packages' => 1, + 'manual_placement' => 1, + ]; + $result = db_process_sql_insert('tgis_data_status', $values); + + if ($result !== false) { + $values = [ + 'item_id' => $created_agent_id, + 'table_name' => 'tgis_data_status', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback GIS data creation if could not be registered in tdemo_data. + db_process_sql_delete('tgis_data_status', ['tagente_id_agente' => $created_agent_id]); + } + } + + + $agents_created_count[$agent_data['agent_alias']]++; + + $iter_agents_created++; + + // Create agent modules. + $module_access_idx = 1; + + while (1) { + $modules_array = []; + foreach ($modules_data as $key => $value) { + $modules_array[$key] = ($value[$module_access_idx] ?? null); + } + + $module_access_idx++; + + $test_empty_array = array_filter($modules_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($modules_array['name']) === false + || is_string($modules_array['name']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: all modules must have a name. Skipping creation of item with index %d', $filename, ($module_access_idx - 1)), + true + ); + continue; + } + + if (isset($modules_array['type']) === false + || is_string($modules_array['type']) === false + ) { + // Module type not defined. + register_error( + DEMO_AGENT, + __('Error in %s: module type is not specified or does not have a valid format (%s). Skipping creation of item with index %d', $filename, ($module_access_idx - 1)), + true + ); + continue; + } + + $id_tipo = db_get_value_filter('id_tipo', 'ttipo_modulo', ['nombre' => $modules_array['type']]); + + if (!($id_tipo > 0)) { + register_error( + DEMO_AGENT, + __('Error in %s: the specified module type is not defined in the system (%s). Skipping creation of item with index %d', $filename, $modules_array['name'], ($module_access_idx - 1)), + true + ); + continue; + } + + $module_description = ''; + + if (isset($modules_array['description']) === true && is_string($modules_array['description']) === true) { + $module_description = str_replace('_mac_', $mac, $modules_array['description']); + } + + $values = [ + 'unit' => $modules_array['unit'], + 'descripcion' => $module_description, + 'id_tipo_modulo' => $id_tipo, + 'id_module_group' => ($modules_array['group'] ?? 0), + 'id_modulo' => 1, + ]; + + $created_mod_id = modules_create_agent_module( + $created_agent_id, + io_safe_input($modules_array['name']), + $values + ); + + if ($created_mod_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_mod_id, + 'table_name' => 'tagente_modulo', + ]; + + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback agent module creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $created_mod_id]); + + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create module with index %d', $filename, ($module_access_idx - 1)), + true + ); + + continue; + } + + // Insert module data. + $parsed = explode(';', $modules_array['values']); + + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + $back_periods = 1; + + if ($adv_options_is_enabled === false + || ($adv_options_is_enabled === true && $history_is_enabled === true) + ) { + $back_periods = round(($days_hist_data * SECONDS_1DAY) / $interval); + } + + + $utimestamp = time(); + + // Generate back_periods amounts of tagente_datos rows each period_mins minutes back in time. + for ($p = 0; $p < $back_periods; $p++) { + $new_status = 0; + if ((string) $parsed[0] === 'RANDOM') { + $data = rand($parsed[1], $parsed[2]); + } else if ((string) $parsed[0] === 'PROC') { + $probability = (int) $parsed[1]; + + $data = 1; + + if ($probability > 0) { + $randomNumber = rand(1, 100); + + if ($randomNumber <= $probability) { + // Set to 0 with a certain probability. + $data = 0; + + // Set to critical status if 0. + $new_status = 1; + } + } + } + + $agent_data_values = [ + 'id_agente_modulo' => $created_mod_id, + 'datos' => $data, + 'utimestamp' => $utimestamp, + ]; + + if ($p === 0) { + // Insert current module data right away so module status is initialized with such value. + $created_data_res = db_process_sql_insert('tagente_datos', $agent_data_values); + + if ($created_data_res === false) { + continue; + } + + // Proceed to update module status. + $status_values = [ + 'datos' => $data, + 'estado' => $new_status, + 'known_status' => 0, + 'timestamp' => $current_date_time, + 'utimestamp' => $utimestamp, + 'last_status' => 0, + 'last_known_status' => 0, + 'current_interval' => $agent_interval, + ]; + + $status_id = db_get_value( + 'id_agente_estado', + 'tagente_estado', + 'id_agente_modulo', + $created_mod_id + ); + + $update_status_res = db_process_sql_update( + 'tagente_estado', + $status_values, + ['id_agente_estado' => $status_id] + ); + + if ($update_status_res !== false) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $status_id, + 'table_name' => 'tagente_estado', + ]; + + $result = db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_estado', ['id_agente_estado' => $status_id]); + } + } + } else { + // Buffer history data for later bulk insertion (performance reasons). + $agent_data_values_buffer[] = $agent_data_values; + } + + if ($adv_options_is_enabled === false + || ($adv_options_is_enabled === true && $history_is_enabled === true) + ) { + $utimestamp -= $interval; + } + } + } else { + // Could not create module. + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create module with index %d', $filename, ($module_access_idx - 1)), + true + ); + + continue; + } + } + + // Create inventory modules. + $module_access_idx = 1; + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + + while (1) { + // Insert in tmodule_inventory. + $modules_array = []; + foreach ($inventory as $key => $value) { + $modules_array[$key] = ($value[$module_access_idx] ?? null); + } + + $module_access_idx++; + + $test_empty_array = array_filter($modules_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($modules_array['name']) === false + || is_string($modules_array['name']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: all inventory modules must have a name. Skipping creation of item with index %d', $filename, ($module_access_idx - 1)), + true + ); + } + + if (isset($modules_array['format']) === false + || is_string($modules_array['format']) === false + || isset($modules_array['values']) === false + || is_string($modules_array['values']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: one or more required fields (format, values) were not found for inventory module %s. Skipping creation of item with index %d', $filename, $modules_array['name'], ($module_access_idx - 1)), + true + ); + continue; + } + + $values = [ + 'name' => $modules_array['name'], + 'data_format' => $modules_array['format'], + 'id_os' => $id_os, + ]; + + $created_inventory_mod_id = inventory_create_inventory_module($values); + + if ($created_inventory_mod_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_inventory_mod_id, + 'table_name' => 'tmodule_inventory', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete('tmodule_inventory', ['id_module_inventory' => $created_inventory_mod_id]); + + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create inventory module with index %d', $filename, ($module_access_idx - 1)), + true + ); + + continue; + } + } else { + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create inventory module with index %d', $filename, ($module_access_idx - 1)), + true + ); + + continue; + } + + // Insert in tagent_module_inventory and tagente_datos_inventory. + $field_idx = 1; + $values_array = explode(';', $modules_array['values']); + + $selected_inventory_values = array_filter( + $inventory_values, + function ($key) use ($values_array) { + return in_array($key, $values_array); + }, + ARRAY_FILTER_USE_KEY + ); + + $data_lines = []; + while (1) { + $line_values = array_column($selected_inventory_values, $field_idx); + + if (empty(array_filter($line_values)) === true) { + break; + } + + $data_lines[] = implode(';', $line_values); + $field_idx++; + } + + $data_str = implode('\n', $data_lines); + + $values = [ + 'id_agente' => $created_agent_id, + 'id_module_inventory' => $created_inventory_mod_id, + 'interval' => 300, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + 'data' => $data_str, + ]; + + $created_module_inventory_id = db_process_sql_insert('tagent_module_inventory', $values); + + if ($created_module_inventory_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_module_inventory_id, + 'table_name' => 'tagent_module_inventory', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete('tagent_module_inventory', ['id_agent_module_inventory' => $created_module_inventory_id]); + continue; + } + } + + $inventory_data_values = [ + 'id_agent_module_inventory' => $created_module_inventory_id, + 'data' => $data_str, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + ]; + + db_process_sql_insert('tagente_datos_inventory', $inventory_data_values); + } + + // Create traps. + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + $back_periods = 1; + + if ($adv_options_is_enabled === false + || ($adv_options_is_enabled === true && $history_is_enabled === true) + ) { + $back_periods = round(($days_hist_data * SECONDS_1DAY) / $interval); + } + + + $utimestamp = time(); + + // TRAPS HISTORY: Removed due to performance issues + /*for ($p = 0; $p < $back_periods; $p++) { + $trap_access_idx = 1; + + while (1) { + $traps_array = []; + + foreach ($traps as $key => $value) { + $traps_array[$key] = ($value[$trap_access_idx] ?? null); + } + + $trap_access_idx++; + $test_empty_array = array_filter($traps_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($traps_array['oid']) === false || is_string($traps_array['oid']) === false + || isset($traps_array['value']) === false || is_string($traps_array['value']) === false + || isset($traps_array['snmp_type']) === false || is_string($traps_array['snmp_type']) === false + || isset($traps_array['chance_percent']) === false || is_string($traps_array['chance_percent']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: all traps must have the following required fields: oid, value, snmp_type, chance_percent. Skipping creation of item with index %d', $filename, ($trap_access_idx - 1)), + true + ); + continue; + } + + $create_trap = false; + + $trap_creation_prob = (int) $traps_array['chance_percent']; + + if ($trap_creation_prob > 0) { + $randomNumber = rand(1, 100); + if ($randomNumber <= $trap_creation_prob) { + $create_trap = true; + } + } + + if ($create_trap === false) { + continue; + } + + $parsed = explode(';', $traps_array['value']); + + $data = ''; + if ((string) $parsed[0] === 'RANDOM') { + $data = rand($parsed[1], $parsed[2]); + } + + $values = [ + 'oid' => $traps_array['oid'], + 'source' => $host_address, + 'value' => $data, + 'type' => $traps_array['snmp_type'], + 'timestamp' => $current_date_time, + 'utimestamp' => $utimestamp, + ]; + + // Buffer history traps for later bulk insertion (performance reasons). + $agent_traps_values_buffer[] = $values; + } + + if ($adv_options_is_enabled === false + || ($adv_options_is_enabled === true && $history_is_enabled === true) + ) { + $date_time->sub(new DateInterval("PT{$interval}S")); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + $utimestamp -= $interval; + } + } + */ + } + + update_progress($total_items_count, $total_agents_to_create, $iter_agents_created); + } + + $agent_created_total = array_sum($agents_created_count); + + if ($agent_created_total === 0) { + // Stop traversing agent files if no agent could be created after first round. + break; + } + } + + $agent_data_values_buffer_chunks = array_chunk($agent_data_values_buffer, 100000); + // TRAPS HISTORY: Removed due to performance issues + //$agent_traps_values_buffer_chunks = array_chunk($agent_traps_values_buffer, 100000); + + foreach ($agent_data_values_buffer_chunks as $chunk) { + // Bulk inserts (insert batches of up to 100,000 as a performance limit). + mysql_db_process_sql_insert_multiple( + 'tagente_datos', + $chunk, + false + ); + } + + // Get last trap in database. + /*$id_trap_begin = db_get_value( + 'MAX(id_trap)', + 'ttrap', + 1, + 1, + false, + false + ); + + if ($id_trap_begin === false) { + $id_trap_begin = 0; + } + + // TRAPS HISTORY: Removed due to performance issues + /* + foreach ($agent_traps_values_buffer_chunks as $chunk) { + // Bulk inserts (insert batches of up to 100,000 as a performance limit). + mysql_db_process_sql_insert_multiple( + 'ttrap', + $chunk, + false + ); + } + + // Get last trap in database after insertion. + $id_trap_end = db_get_value( + 'MAX(id_trap)', + 'ttrap', + 1, + 1, + false, + false + ); + + if ($id_trap_end === false) { + $id_trap_end = 0; + } + + $agent_traps_demo_registry_buffer = []; + for ($i = ($id_trap_begin + 1); $i <= $id_trap_end; $i++) { + // Get batches to be stored in tdemo_data. + $agent_traps_demo_registry_buffer[] = [ + 'item_id' => $i, + 'table_name' => 'ttrap', + ]; + } + + $agent_traps_demo_registry_buffer_chunks = array_chunk($agent_traps_demo_registry_buffer, 100000); + + foreach ($agent_traps_demo_registry_buffer_chunks as $chunk) { + // Bulk inserts (insert batches of up to 100,000 as a performance limit). + mysql_db_process_sql_insert_multiple( + 'tdemo_data', + $chunk, + false + ); + }*/ + + update_item_checked(DEMO_AGENT); + } + } + + $services_count = count($parsed_ini['services'] ?? []); + if ($services_count > 0) { + // Create services. + foreach ($parsed_ini['services'] as $ini_service_data) { + $filename = $ini_service_data['filename']; + $service_data = $ini_service_data['service_data']; + $service_items = $ini_service_data['service_items']; + + // Check for mandatory fields. + if (isset($service_data['name']) === false + || is_string($service_data['name']) === false + || isset($service_data['group']) === false + || is_string($service_data['group']) === false + ) { + register_error( + DEMO_SERVICE, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping service creation', $filename) + ); + continue; + } + + // Check whether services default agent exists in the system. Try to get default agent if not. + $matched_agents = agents_get_agents( + ['nombre' => $service_agent_name], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + + $matched_agent = $matched_agents[0]['id_agente']; + + if (isset($matched_agent) === true && $matched_agent > 0) { + $service_agent_id = $matched_agent; + } else { + // Skip element creation if agent does not exist. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified services agent does not exist in the system: %s. Skipping service creation', $filename, $service_agent_name) + ); + continue; + } + + $id_group = get_group_or_create_demo_group($service_data['group']); + + if ($id_group === false) { + // Group could not be created. Skip service creation. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping service creation', $filename) + ); + continue; + } + + $service_values = []; + + $service_values['name'] = io_safe_input($service_data['name']); + $service_values['description'] = io_safe_input($service_data['description']); + $service_values['id_group'] = $id_group; + $service_values['critical'] = $service_data['critical']; + $service_values['warning'] = $service_data['warning']; + $service_values['auto_calculate'] = (isset($service_data['mode']) === true && (string) $service_data['mode'] === 'smart') ? 1 : 0; + + if (isset($service_data['show_sunburst']) === true && $service_data['show_sunburst'] === true) { + $service_values['enable_sunburst'] = 1; + } + + $created_service_id = db_process_sql_insert('tservice', $service_values); + + $service_module_values = []; + $service_module_values['flag'] = 0; + $service_module_values['module_interval'] = 300; + $service_module_values['custom_integer_1'] = $created_service_id; + $service_module_values['prediction_module'] = 2; + $service_module_values['id_modulo'] = 5; + $service_module_values['id_module_group'] = 1; + + if ($created_service_id > 0) { + // Register created service in tdemo_data. + $values = [ + 'item_id' => $created_service_id, + 'table_name' => 'tservice', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback service creation if could not be registered in tdemo_data. + db_process_sql_delete('tservice', ['id' => $created_service_id]); + + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service %s', $filename, $service_values['name']) + ); + + continue; + } + + $service_module_values['id_tipo_modulo'] = 22; + $service_module_values['min_warning'] = $service_data['warning']; + $service_module_values['min_critical'] = $service_data['critical']; + + $created_service_module_id = modules_create_agent_module( + $service_agent_id, + io_safe_input($service_data['name'].'_service'), + $service_module_values + ); + + if ($created_service_module_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_service_module_id, + 'table_name' => 'tagente_modulo', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $created_service_module_id]); + + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service module %s', $filename, $service_module_values['nombre']) + ); + + continue; + } + + $service_module_values['id_tipo_modulo'] = 21; + $created_sla_service_module_id = modules_create_agent_module( + $service_agent_id, + io_safe_input($service_data['name'].'_SLA_service'), + $service_module_values + ); + + if ($created_sla_service_module_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_sla_service_module_id, + 'table_name' => 'tagente_modulo', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $created_sla_service_module_id]); + + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service SLA module %s', $filename, $service_module_values['nombre']) + ); + + continue; + } + + $service_module_values['id_tipo_modulo'] = 22; + $created_sla_val_service_module_id = modules_create_agent_module( + $service_agent_id, + io_safe_input($service_data['name'].'_SLA_Value_service'), + $service_module_values + ); + + if ($created_sla_val_service_module_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_sla_val_service_module_id, + 'table_name' => 'tagente_modulo', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $created_sla_val_service_module_id]); + + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service SLA value module %s', $filename, $service_module_values['nombre']) + ); + + continue; + } + } else { + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service SLA value module %s', $filename, $service_module_values['nombre']) + ); + + continue; + } + } else { + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service SLA module %s', $filename, $service_module_values['nombre']) + ); + + continue; + } + + $update_service_module_ids = db_process_sql_update( + 'tservice', + [ + 'id_agent_module' => $created_service_module_id, + 'sla_id_module' => $created_sla_service_module_id, + 'sla_value_id_module' => $created_sla_val_service_module_id, + ], + ['id' => $created_service_id] + ); + + if ($update_service_module_ids === false) { + continue; + } + } else { + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service module %s', $filename, $service_module_values['nombre']) + ); + + continue; + } + } else { + // Service could not be created. Skip creation of map. + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service %s', $filename, $service_values['name']) + ); + + continue; + } + + if (count($service_items) > 0) { + $item_access_idx = 1; + while (1) { + $items_array = []; + foreach ($service_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($items_array['type']) === false) { + // Service element type must be specified. + register_error( + DEMO_SERVICE, + __('Error in %s: all service items must have the following required fields: type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + + $element_values = []; + + $element_values = ['id_service' => $created_service_id]; + + $element_type = (string) $items_array['type']; + + if (in_array($element_type, ['agent', 'module', 'dynamic', 'service']) === false) { + // Skip element creation if type not valid. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified type of service item is not valid. All service items must have one of the following types: agent, module, dynamic, service. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + + if (in_array($element_type, ['agent', 'module']) === true) { + // Get agent ID and module ID. + $matched_agents = agents_get_agents( + ['nombre' => io_safe_input($items_array['agent_name'])], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + + $matched_agent = $matched_agents[0]['id_agente']; + + if (isset($matched_agent) === true && $matched_agent > 0) { + $element_values['id_agent'] = $matched_agent; + } else { + // Skip element creation if agent does not exist. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified agent does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['agent_name'], ($item_access_idx - 1)) + ); + continue; + } + } + + if (in_array($element_type, ['module']) === true) { + if ($element_values['id_agent'] > 0) { + $module_id = db_get_value_sql('SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = "'.io_safe_input($items_array['module']).'" AND id_agente = '.$element_values['id_agent']); + + if ($module_id > 0) { + $element_values['id_agente_modulo'] = $module_id; + } else { + // Skip element creation if agent module does not exist. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified agent module does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['module'], ($item_access_idx - 1)) + ); + continue; + } + } else { + continue; + } + } + + if ($element_type === 'dynamic') { + if ($service_values['auto_calculate'] === 1) { + if (isset($items_array['match']) === false + || ($items_array['match'] !== 'agent' && $items_array['match'] !== 'module') + ) { + // If failed to provide match value, 'agent' is assigned by default. + $match_value = 'agent'; + } else { + $match_value = $items_array['match']; + } + + if (isset($items_array['group']) === true) { + $group_id_value = get_group_or_create_demo_group($items_array['group']); + + if ($group_id_value === false) { + $group_id_value = -1; + } + } else { + $group_id_value = -1; + } + + $element_values['id_agent'] = 0; + $element_values['id_agente_modulo'] = 0; + + $rules_arr = [ + 'dynamic_type' => $match_value, + 'group' => $group_id_value, + 'agent_name' => (isset($items_array['agent_name']) === true) ? $items_array['agent_name'] : '', + 'module_name' => (isset($items_array['module']) === true) ? $items_array['module'] : '', + 'regex_mode' => (isset($items_array['regex']) === true) ? $items_array['regex'] : false, + 'custom_fields' => [], + ]; + + $element_values['rules'] = base64_encode(json_encode($rules_arr)); + } + } + + if ($element_type === 'service') { + if (isset($items_array['service_name']) === true + && is_string($items_array['service_name']) === true + ) { + $services = services_get_services(['name' => io_safe_input($items_array['service_name'])]); + + $service_id = $services[0]['id']; + + if ($service_id > 0) { + $element_values['id_service_child'] = $service_id; + } else { + // Skip element creation if specified service does not exist. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified service does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['service_name'], ($item_access_idx - 1)) + ); + continue; + } + } else { + // Skip element creation if service name was not provided. + continue; + } + } + + $id = db_process_sql_insert('tservice_element', $element_values); + + if ($id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $id, + 'table_name' => 'tservice_element', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback service element if could not be registered in tdemo_data. + db_process_sql_delete('tservice_element', ['id' => $id]); + + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $services_count, $services_count); + update_item_checked(DEMO_SERVICE); + } else { + register_error(DEMO_SERVICE, __('No configuration files found or failed to parse files')); + } + + $nm_count = count($parsed_ini['network_maps'] ?? []); + if ($nm_count > 0) { + // Create network maps. + foreach ($parsed_ini['network_maps'] as $ini_nm_data) { + $filename = $ini_nm_data['filename']; + $map_data = $ini_nm_data['map_data']; + $map_items = $ini_nm_data['map_items']; + + if (isset($map_data['name']) === false + || is_string($map_data['name']) === false + || isset($map_data['group']) === false + || is_string($map_data['group']) === false + ) { + register_error( + DEMO_NETWORK_MAP, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping network map creation', $filename) + ); + continue; + } + + $map_types = [ + 'circular' => 0, + 'radial_dynamic' => 6, + ]; + + $nm_name = $map_data['name']; + $nm_group = $map_data['group']; + $nm_description = (isset($map_data['description']) === true) ? $map_data['description'] : ''; + $nm_node_radius = (isset($map_data['node_radius']) === true) ? $map_data['node_radius'] : '40'; + $nm_generation_method = (isset($map_data['generation_method']) === true && isset($map_types[$map_data['generation_method']]) === true) ? $map_types[$map_data['generation_method']] : '0'; + + $nm_id_group = get_group_or_create_demo_group($nm_group); + + if ($nm_id_group === false) { + // Group could not be created. Skip network map creation. + register_error( + DEMO_NETWORK_MAP, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping service creation', $filename) + ); + continue; + } + + $values = []; + $new_map_filter = []; + $new_map_filter['dont_show_subgroups'] = 0; + $new_map_filter['node_radius'] = $nm_node_radius; + $new_map_filter['x_offs'] = 0; + $new_map_filter['y_offs'] = 0; + $new_map_filter['z_dash'] = '0.5'; + $new_map_filter['node_sep'] = '0.25'; + $new_map_filter['rank_sep'] = '0.25'; + $new_map_filter['mindist'] = 1; + $new_map_filter['kval'] = '0.3'; + $values['filter'] = json_encode($new_map_filter); + $values['description'] = io_safe_input($nm_description); + $values['id_group'] = $nm_id_group; + $values['id_group_map'] = $nm_id_group; + $values['source_data'] = $nm_id_group; + $values['name'] = io_safe_input($nm_name); + $values['refresh_time'] = 300; + $values['generation_method'] = $nm_generation_method; + + $id_map = db_process_sql_insert('tmap', $values); + + if ($id_map > 0) { + // Register created map in tdemo_data. + $values = [ + 'item_id' => $id_map, + 'table_name' => 'tmap', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tmap', ['id' => $id_map]); + + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map %s', $filename, $nm_name) + ); + + continue; + } + } else { + // Network map group could not be created. Skip creation of map. + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map %s', $filename, $nm_name) + ); + continue; + } + + if (count($map_items) > 0) { + $item_access_idx = 1; + $map_id_index = []; + + while (1) { + $items_array = []; + foreach ($map_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $item_values = []; + + $item_values['id_map'] = $id_map; + + if (isset($items_array['agent_name']) === true || is_string($items_array['agent_name']) === false) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + [ + 'id_agente', + 'id_os', + 'alias', + ], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + + $matched_agent = $matched_agents[0]['id_agente']; + $alias = $matched_agents[0]['alias']; + if (isset($matched_agent) === true && $matched_agent > 0) { + $item_values['source_data'] = $matched_agent; + if (isset($matched_agents[0]['id_agente']) === true && $matched_agents[0]['id_os']) { + $agent_os_id = $matched_agents[0]['id_os']; + $icon_name = db_get_value('icon_name', 'tconfig_os', 'id_os', $agent_os_id); + } + } else { + // Skip report item creation if agent does not exist. + register_error( + DEMO_NETWORK_MAP, + __('Error in %s: the specified agent does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['agent_name'], ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_NETWORK_MAP, + __('Error in %s: all network map items must have the following required fields: agent_name. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + + $style_values = [ + 'shape' => 'circle', + 'image' => 'images/networkmap/'.$icon_name, + 'width' => null, + 'height' => null, + 'label' => $alias, + ]; + + $item_values['style'] = json_encode($style_values); + $item_values['x'] = (isset($items_array['x']) === true) ? $items_array['x'] : '0'; + $item_values['y'] = (isset($items_array['y']) === true) ? $items_array['y'] : '0'; + + $created_nm_item_id = db_process_sql_insert('titem', $item_values); + + if ($created_nm_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_nm_item_id, + 'table_name' => 'titem', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('titem', ['id' => $created_nm_item_id]); + + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + + $map_id_index[($item_access_idx - 1)] = $created_nm_item_id; + + if (isset($items_array['parent']) === true && (int) $items_array['parent'] > 0) { + $parent_nm_id = $map_id_index[(int) $items_array['parent']]; + $parent_nm_source_data = db_get_value('source_data', 'titem', 'id', $parent_nm_id); + + $rel_values = [ + 'id_parent' => $parent_nm_id, + 'id_child' => $created_nm_item_id, + 'id_map' => $id_map, + 'id_parent_source_data' => $parent_nm_source_data, + 'id_child_source_data' => $item_values['source_data'], + ]; + + $created_nm_rel_item_id = db_process_sql_insert('trel_item', $rel_values); + + if ($created_nm_rel_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_nm_rel_item_id, + 'table_name' => 'trel_item', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('trel_item', ['id' => $created_nm_rel_item_id]); + + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } + } + } else { + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $nm_count, $nm_count); + update_item_checked(DEMO_NETWORK_MAP); + } else { + register_error(DEMO_NETWORK_MAP, __('No configuration files found or failed to parse files')); + } + + $gis_count = count($parsed_ini['gis_maps'] ?? []); + if ($gis_count > 0) { + // Enable GIS features + $token = 'activate_gis'; + $activate_gis = db_get_value_filter('value', 'tconfig', ['token' => $token]); + if ($activate_gis === false) { + config_create_value($token, 1); + } else { + config_update_value($token, 1); + } + + // Create GIS maps. + foreach ($parsed_ini['gis_maps'] as $ini_gis_data) { + $filename = $ini_gis_data['filename']; + $gis_data = $ini_gis_data['gis_data']; + $gis_layers = $ini_gis_data['gis_layers']; + + if (isset($gis_data['name']) === false + || is_string($gis_data['name']) === false + || isset($gis_data['group']) === false + || is_string($gis_data['group']) === false + ) { + register_error( + DEMO_GIS_MAP, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping GIS map creation', $filename) + ); + continue; + } + + $gis_name = $gis_data['name']; + $gis_group = $gis_data['group']; + $gis_zoom_level = (isset($gis_data['zoom_level']) === true) ? $gis_data['zoom_level'] : '6'; + $gis_initial_latitude = (isset($gis_data['initial_latitude']) === true) ? $gis_data['initial_latitude'] : '0'; + $gis_initial_longitude = (isset($gis_data['initial_longitude']) === true) ? $gis_data['initial_longitude'] : '0'; + $gis_initial_altitude = (isset($gis_data['initial_altitude']) === true) ? $gis_data['initial_altitude'] : '0'; + $gis_default_latitude = (isset($gis_data['default_latitude']) === true) ? $gis_data['default_latitude'] : '0'; + $gis_default_longitude = (isset($gis_data['default_longitude']) === true) ? $gis_data['default_longitude'] : '0'; + $gis_default_altitude = (isset($gis_data['default_altitude']) === true) ? $gis_data['default_altitude'] : '0'; + + $gis_id_group = get_group_or_create_demo_group($gis_group); + + if ($gis_id_group === false) { + // Group could not be created. Skip GIS map creation. + register_error( + DEMO_GIS_MAP, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping GIS map creation', $filename) + ); + continue; + } + + $values = []; + $values['map_name'] = io_safe_input($gis_name); + $values['group_id'] = $gis_id_group; + $values['zoom_level'] = $gis_zoom_level; + $values['initial_latitude'] = $gis_initial_latitude; + $values['initial_longitude'] = $gis_initial_longitude; + $values['initial_altitude'] = $gis_initial_altitude; + $values['default_latitude'] = $gis_default_latitude; + $values['default_longitude'] = $gis_default_longitude; + $values['default_altitude'] = $gis_default_altitude; + + $id_map = db_process_sql_insert('tgis_map', $values); + + if ($id_map > 0) { + // Register created map in tdemo_data. + $values = [ + 'item_id' => $id_map, + 'table_name' => 'tgis_map', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tgis_map', ['id_tgis_map' => $id_map]); + + register_error( + DEMO_GIS_MAP, + __('Uncaught error (source %s): could not create GIS map %s', $filename, $gis_name) + ); + + continue; + } + } else { + // Network map group could not be created. Skip creation of map. + register_error( + DEMO_GIS_MAP, + __('Uncaught error (source %s): could not create GIS map %s', $filename, $gis_name) + ); + continue; + } + + $values = []; + $values['tgis_map_id_tgis_map'] = $id_map; + $values['tgis_map_con_id_tmap_con'] = 1; + + db_process_sql_insert('tgis_map_has_tgis_map_con', $values); + + if (count($gis_layers) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($gis_layers as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $item_values = []; + + $layer_order = $item_access_idx - 2; + + $item_values['tgis_map_id_tgis_map'] = $id_map; + $item_values['layer_stack_order'] = $layer_order; + $item_values['tgrupo_id_grupo'] = -1; + $item_values['view_layer'] = 1; + $item_values['layer_name'] = io_safe_input((isset($items_array['name']) === true) ? $items_array['name'] : 'layer-'-$layer_order); + + if (isset($items_array['group']) === true) { + $layer_id_group = get_group_or_create_demo_group($items_array['group']); + if ($layer_id_group !== false) { + $item_values['tgrupo_id_grupo'] = $layer_id_group; + } + } + + $created_gis_layer_id = db_process_sql_insert('tgis_map_layer', $item_values); + + if ($created_gis_layer_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_gis_layer_id, + 'table_name' => 'tgis_map_layer', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('tgis_map_layer', ['id_tmap_layer' => $created_gis_layer_id]); + + register_error( + DEMO_GIS_MAP, + __('Uncaught error (source %s): could not create GIS map item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_GIS_MAP, + __('Uncaught error (source %s): could not create GIS map item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $gis_count, $gis_count); + update_item_checked(DEMO_GIS_MAP); + } else { + register_error(DEMO_GIS_MAP, __('No configuration files found or failed to parse files')); + } + + $cg_count = count($parsed_ini['graphs'] ?? []); + if ($cg_count > 0) { + // Create graphs. + foreach ($parsed_ini['graphs'] as $ini_graph_data) { + // Constant graph types. + $graph_types = [ + 'line' => 2, + 'area' => 0, + 's_line' => 3, + 's_area' => 1, + 'h_bars' => 6, + 'v_bars' => 7, + 'gauge' => 5, + 'pie' => 8, + ]; + + $filename = $ini_graph_data['filename']; + $graph_data = $ini_graph_data['graph_data']; + $graph_items = $ini_graph_data['graph_items']; + + $graph_name = $graph_data['name']; + $graph_group = $graph_data['group']; + $graph_description = $graph_data['description']; + $graph_type = (isset($graph_types[$graph_data['type']]) === true) ? $graph_types[$graph_data['type']] : 0; + $graph_periodicity = $graph_data['periodicity']; + + $graph_id_group = get_group_or_create_demo_group($graph_group); + + if ($graph_id_group === false) { + // Group could not be created. Skip graph creation. + register_error( + DEMO_CUSTOM_GRAPH, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping service creation', $filename) + ); + continue; + } + + $values = []; + $values['description'] = io_safe_input($graph_description); + $values['id_group'] = $graph_id_group; + $values['name'] = io_safe_input($graph_name); + $values['period'] = $graph_periodicity; + $values['stacked'] = $graph_type; + + $id_graph = db_process_sql_insert('tgraph', $values); + + if ($id_graph > 0) { + // Register created graph in tdemo_data. + $values = [ + 'item_id' => $id_graph, + 'table_name' => 'tgraph', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback graph creation if could not be registered in tdemo_data. + db_process_sql_delete('tgraph', ['id_graph' => $id_graph]); + + register_error( + DEMO_CUSTOM_GRAPH, + __('Uncaught error (source %s): could not create custom graph %s', $filename, $graph_name) + ); + + continue; + } + } else { + // Graph could not be created. Skip creation of graph. + register_error( + DEMO_CUSTOM_GRAPH, + __('Uncaught error (source %s): could not create custom graph %s', $filename, $graph_name) + ); + continue; + } + + if (count($graph_items) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($graph_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $item_values = []; + + if (isset($items_array['agent_name']) === false + || is_string($items_array['agent_name']) === false + || isset($items_array['module']) === false + || is_string($items_array['module']) === false + ) { + // Agent and module must be defined. Skip graph item creation. + register_error( + DEMO_CUSTOM_GRAPH, + __('Error in %s: one or more required fields (agent_name, module) were not found for custom graph item with index %d. Skipping creation of item with index %d', $filename, $item_access_idx, ($item_access_idx - 1)) + ); + continue; + } + + + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + register_error( + DEMO_CUSTOM_GRAPH, + __('Error in %s: the specified agent does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['agent_name'], ($item_access_idx - 1)) + ); + continue; + } + + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + register_error( + DEMO_CUSTOM_GRAPH, + __('Error in %s: the specified agent module does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['module'], ($item_access_idx - 1)) + ); + continue; + } + + $item_values = [ + 'id_graph' => $id_graph, + 'id_agent_module' => $module_id, + 'weight' => 1, + ]; + + $created_graph_item_id = db_process_sql_insert('tgraph_source', $item_values); + + if ($created_graph_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_graph_item_id, + 'table_name' => 'tgraph_source', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('tgraph_source', ['id_gs' => $created_graph_item_id]); + + register_error( + DEMO_CUSTOM_GRAPH, + __('Uncaught error (source %s): could not create custom graph item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_CUSTOM_GRAPH, + __('Uncaught error (source %s): could not create custom graph item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $cg_count, $cg_count); + update_item_checked(DEMO_CUSTOM_GRAPH); + } else { + register_error(DEMO_CUSTOM_GRAPH, __('No configuration files found or failed to parse files')); + } + + $rep_count = count($parsed_ini['reports'] ?? []); + if ($rep_count > 0) { + // Create reports. + foreach ($parsed_ini['reports'] as $ini_report_data) { + $filename = $ini_report_data['filename']; + $report_data = $ini_report_data['report_data']; + $report_items = $ini_report_data['report_items']; + + // Check for mandatory fields. + if (isset($report_data['name']) === false + || is_string($report_data['name']) === false + || isset($report_data['group']) === false + || is_string($report_data['group']) === false + ) { + register_error( + DEMO_REPORT, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping custom report creation', $filename) + ); + } + + $group_id = get_group_or_create_demo_group($report_data['group']); + + if ($group_id === false) { + // Could not create group. Skip report creation. + register_error( + DEMO_REPORT, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping service creation', $filename) + ); + continue; + } + + $report_values = []; + $report_values['id_group'] = $group_id; + $report_values['name'] = io_safe_input($report_data['name']); + $report_values['description'] = io_safe_input($report_data['description']); + + $created_report_id = db_process_sql_insert('treport', $report_values); + + if ($created_report_id > 0) { + // Register created graph in tdemo_data. + $values = [ + 'item_id' => $created_report_id, + 'table_name' => 'treport', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback report creation if could not be registered in tdemo_data. + db_process_sql_delete('treport', ['id_report' => $created_report_id]); + + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report %s', $filename, $report_data['name']) + ); + + continue; + } + } else { + // Report could not be created. Skip creation of map. + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report %s', $filename, $report_data['name']) + ); + continue; + } + + if (count($report_items) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($report_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($items_array['name']) === false + || is_string($items_array['name']) === false + || isset($items_array['type']) === false + || is_string($items_array['type']) === false + ) { + // All report items must have a type. + register_error( + DEMO_REPORT, + __('Error in %s: all custom report items must have the following required fields: name, type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + + $item_values = []; + + $item_values['id_report'] = $created_report_id; + $item_values['name'] = io_safe_input($items_array['name']); + $item_values['type'] = $items_array['type']; + + if (isset($items_array['agent_name']) === true) { + if (isset($items_array['module']) === false + || is_string($items_array['module']) === false + ) { + continue; + } + + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + + $matched_agent = $matched_agents[0]['id_agente']; + if (isset($matched_agent) === true && $matched_agent > 0) { + $item_values['id_agent'] = $matched_agent; + } else { + // Skip report item creation if agent does not exist. + register_error( + DEMO_REPORT, + __('Error in %s: the specified agent does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['agent_name'], ($item_access_idx - 1)) + ); + continue; + } + } + + if (isset($items_array['module']) === true) { + if (is_string($items_array['module']) === false) { + // Module wrong data type read. Skip. + continue; + } + + if ($item_values['id_agent'] > 0) { + $module_id = db_get_value_sql('SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = "'.io_safe_input($items_array['module']).'" AND id_agente = '.$item_values['id_agent']); + + if ($module_id > 0) { + $item_values['id_agent_module'] = $module_id; + } else { + // Skip report item creation if agent module does not exist. + register_error( + DEMO_REPORT, + __('Error in %s: the specified agent module does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['module'], ($item_access_idx - 1)) + ); + continue; + } + } else { + continue; + } + } + + if (isset($items_array['graph_name']) === true && is_string($items_array['graph_name']) === true) { + $id_custom_graph = reset(custom_graphs_search('', $items_array['graph_name']))['id_graph']; + + if ($id_custom_graph > 0) { + $item_values['id_gs'] = $id_custom_graph; + } else { + // Skip report item creation if specified custom graph does not exist. + register_error( + DEMO_REPORT, + __('Error in %s: the specified custom graph does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['graph_name'], ($item_access_idx - 1)) + ); + continue; + } + } + + if ($items_array['type'] === 'simple_graph') { + $item_values['style'] = '{"show_in_same_row":0,"hide_notinit_agents":0,"priority_mode":1,"dyn_height":"250","percentil":0,"fullscale":0,"image_threshold":0,"label":""}'; + } + + if ($items_array['type'] === 'custom_graph') { + $item_values['style'] = '{"show_in_same_row":0,"hide_notinit_agents":0,"priority_mode":"1","dyn_height":"250"}'; + } + + $item_values['period'] = (isset($items_array['periodicity']) === true) ? $items_array['periodicity'] : 300; + + $created_report_item_id = db_process_sql_insert('treport_content', $item_values); + + if ($created_report_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_report_item_id, + 'table_name' => 'treport_content', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback report item if could not be registered in tdemo_data. + db_process_sql_delete('treport_content', ['id_rc' => $created_report_item_id]); + + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + + if ($items_array['type'] === 'SLA') { + $sla_values = [ + 'id_report_content' => $created_report_item_id, + 'id_agent_module' => $item_values['id_agent_module'], + 'sla_limit' => 95, + ]; + + $created_report_content_sla_id = db_process_sql_insert('treport_content_sla_combined', $sla_values); + + if ($created_report_content_sla_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_report_content_sla_id, + 'table_name' => 'treport_content_sla_combined', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback report item if could not be registered in tdemo_data. + db_process_sql_delete('treport_content_sla_combined', ['id' => $created_report_content_sla_id]); + + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } + } else { + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $rep_count, $rep_count); + update_item_checked(DEMO_REPORT); + } else { + register_error(DEMO_REPORT, __('No configuration files found or failed to parse files')); + } + + $vc_count = count($parsed_ini['visual_consoles'] ?? []); + if ($vc_count > 0) { + // Create visual consoles. + foreach ($parsed_ini['visual_consoles'] as $ini_data) { + $filename = $ini_data['filename']; + $data = $ini_data['visual_console_data']; + $items = $ini_data['visual_console_items']; + + // Check for mandatory fields. + if (isset($data['name']) === false + || isset($data['group']) === false + ) { + // Name and group fields must be specified for vc. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping visual console creation', $filename) + ); + continue; + } + + $id_group = get_group_or_create_demo_group($data['group']); + + if ($id_group === false) { + // Group could not be created. Skip dashboard creation. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping visual console creation', $filename) + ); + continue; + } + + $insert_values = []; + + $insert_values['name'] = io_safe_input($data['name']); + $insert_values['id_group'] = $id_group; + $insert_values['background'] = (isset($data['background']) === true) ? $data['background'] : 'None.png'; + $insert_values['background_color'] = (isset($data['background_color']) === true) ? $data['background_color'] : '#ffffff'; + $insert_values['width'] = (isset($data['width']) === true) ? $data['width'] : 1024; + $insert_values['height'] = (isset($data['height']) === true) ? $data['height'] : 768; + + $created_id = db_process_sql_insert('tlayout', $insert_values); + + if ($created_id > 0) { + // Register created item in tdemo_data. + $values = [ + 'item_id' => $created_id, + 'table_name' => 'tlayout', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tlayout', ['id' => $created_id]); + + register_error( + DEMO_VISUAL_CONSOLE, + __('Uncaught error (source %s): could not create visual console %s', $filename, $insert_values['name']) + ); + + continue; + } + } else { + // VC could not be created. Skip creation of item. + register_error( + DEMO_VISUAL_CONSOLE, + __('Uncaught error (source %s): could not create visual console %s', $filename, $insert_values['name']) + ); + continue; + } + + if (count($items) > 0) { + $item_access_idx = 1; + while (1) { + $items_array = []; + foreach ($items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($items_array['type']) === false) { + // All visual console items must have a type. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: all visual console items must have the following required fields: type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + + // Map used types. + $types = [ + 'static_image' => 0, + 'module_graph' => 1, + 'custom_graph' => 1, + 'value' => 2, + 'percentile' => 3, + 'label' => 4, + 'icon' => 5, + 'bubble' => 9, + 'box' => 12, + 'event_history' => 14, + 'circular_progress_bar' => 15, + 'circular_progress_bar_int' => 16, + 'color_cloud' => 20, + 'odometer' => 22, + 'basic_chart' => 23, + ]; + + $value_process_types = [ + 'max' => 6, + 'min' => 7, + 'avg' => 8, + ]; + + // Get ID of item type. Skip if it does not exist. + if (isset($types[$items_array['type']]) === false) { + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: the specified type is not a valid one. It must be one of the following values: static_image, module_graph, custom_graph, value, label, icon. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + + $element_values = []; + + $element_values['type'] = $types[$items_array['type']]; + if ($items_array['type'] == 'value') { + if (isset($items_array['process']) === true && isset($value_process_types[$items_array['process']])) { + $element_values['type'] = $value_process_types[$items_array['process']]; + + if (isset($items_array['interval']) === true) { + $element_values['period'] = $items_array['interval']; + } + } + } + + $element_values['id_layout'] = $created_id; + + if ($items_array['type'] === 'static_image') { + if (isset($items_array['image']) === false + || is_string($items_array['image']) === false + ) { + // The above fields are required for this item. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: image field must be specified for static image item type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + + $element_values['image'] = $items_array['image']; + + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + + if (isset($items_array['visual_console']) === true) { + $id_vc = db_get_value('id', 'tlayout', 'name', $items_array['visual_console']); + + if (!($id_vc > 0)) { + continue; + } + + $element_values['id_layout_linked'] = $id_vc; + } + } + + if ($items_array['type'] === 'module_graph') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + + if (isset($items_array['interval']) === true) { + $element_values['period'] = $items_array['interval']; + } + + if (isset($items_array['graph_type']) === true) { + $element_values['type_graph'] = $items_array['graph_type']; + } + + if (isset($items_array['image']) === true) { + $element_values['image'] = $items_array['image']; + } + } + + if ($items_array['type'] === 'custom_graph') { + + if (isset($items_array['graph_name']) === true + && is_string($items_array['graph_name']) === true + ) { + $id_custom_graph = reset(custom_graphs_search('', $items_array['graph_name']))['id_graph']; + + if ($id_custom_graph > 0) { + $element_values['id_custom_graph'] = $id_custom_graph; + } else { + continue; + } + } + + if (isset($items_array['interval']) === true) { + $element_values['period'] = $items_array['interval']; + } + + if (isset($items_array['image']) === true) { + $element_values['image'] = $items_array['image']; + } + } + + if ($items_array['type'] === 'basic_chart') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + + if (isset($items_array['interval']) === true) { + $element_values['period'] = $items_array['interval']; + } + } + + if ($items_array['type'] === 'event_history') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + + if (isset($items_array['interval']) === true) { + $element_values['period'] = $items_array['interval']; + } + } + + if ($items_array['type'] === 'odometer') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + } + + if ($items_array['type'] === 'color_cloud') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + } + + if ($items_array['type'] === 'box') { + if (isset($items_array['border_color']) === true) { + $element_values['border_color'] = $items_array['border_color']; + } + + if (isset($items_array['fill_color']) === true) { + $element_values['fill_color'] = $items_array['fill_color']; + } + } + + if ($items_array['type'] === 'icon') { + if (isset($items_array['image']) === false + || is_string($items_array['image']) === false + ) { + // The above fields are required for this item. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: image field must be specified for icon item type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + + $element_values['image'] = $items_array['image']; + + if (isset($items_array['visual_console']) === true) { + $id_vc = db_get_value('id', 'tlayout', 'name', $items_array['visual_console']); + + if (!($id_vc > 0)) { + continue; + } + + $element_values['id_layout_linked'] = $id_vc; + } + } + + if ($items_array['type'] === 'value') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + } + + if (isset($items_array['label']) === true) { + $element_values['label'] = io_safe_input($items_array['label']); + } + + if (isset($items_array['label_position']) === true) { + $element_values['label_position'] = $items_array['label_position']; + } + + if (isset($items_array['x']) === true) { + $element_values['pos_x'] = $items_array['x']; + } + + if (isset($items_array['y']) === true) { + $element_values['pos_y'] = $items_array['y']; + } + + if (isset($items_array['width']) === true) { + $element_values['width'] = $items_array['width']; + } + + if (isset($items_array['height']) === true) { + $element_values['height'] = $items_array['height']; + } + + $element_values['show_on_top'] = (isset($items_array['show_on_top']) === true && $items_array['show_on_top'] === true) ? 1 : 0; + + // Check here percentile items as height is used for max value + if ($items_array['type'] === 'percentile' || $items_array['type'] === 'bubble' || $items_array['type'] === 'circular_progress_bar' || $items_array['type'] === 'circular_progress_bar_int') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + + $element_values['border_width'] = 0; + if (isset($items_array['min']) === true) { + $element_values['border_width'] = $items_array['min']; + } + + $element_values['height'] = 100; + if (isset($items_array['max']) === true) { + $element_values['height'] = $items_array['max']; + } + + $element_values['image'] = 'percent'; + } + + $id = db_process_sql_insert('tlayout_data', $element_values); + + if ($id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $id, + 'table_name' => 'tlayout_data', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('tlayout_data', ['id' => $id]); + + register_error( + DEMO_VISUAL_CONSOLE, + __('Uncaught error (source %s): could not create visual console item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_VISUAL_CONSOLE, + __('Uncaught error (source %s): could not create visual console item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $vc_count, $vc_count); + update_item_checked(DEMO_VISUAL_CONSOLE); + } else { + register_error(DEMO_VISUAL_CONSOLE, __('No configuration files found or failed to parse files')); + } + + $dashboards_count = count($parsed_ini['dashboards'] ?? []); + if ($dashboards_count > 0) { + // Create dashboards. + foreach ($parsed_ini['dashboards'] as $ini_data) { + $data = $ini_data['dashboard_data']; + $items = $ini_data['dashboard_items']; + + // Check for mandatory fields. + if (isset($data['name']) === false + || isset($data['group']) === false + ) { + // Name and group fields must be specified for dashbaord. + continue; + } + + $id_group = get_group_or_create_demo_group($data['group']); + + if ($id_group === false) { + // Group could not be created. Skip dashboard creation. + continue; + } + + $insert_values = []; + + $insert_values['name'] = io_safe_input($data['name']); + $insert_values['id_group'] = $id_group; + + $created_id = db_process_sql_insert('tdashboard', $insert_values); + + if ($created_id > 0) { + // Register created item in tdemo_data. + $values = [ + 'item_id' => $created_id, + 'table_name' => 'tdashboard', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tdashboard', ['id' => $created_id]); + continue; + } + } else { + // Dashboard could not be created. Skip creation of item. + continue; + } + + if (count($items) > 0) { + $item_access_idx = 1; + $order = -1; + while (1) { + $items_array = []; + foreach ($items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($items_array['type']) === false || isset($items_array['title']) === false) { + // All dashboard widgets must have a type and a title. + continue; + } + + // Get ID of widget type. Skip if it does not exist. + $type_id = db_get_value('id', 'twidget', 'unique_name', $items_array['type']); + + if (!($type_id > 0)) { + continue; + } + + $title = io_safe_input($items_array['title']); + $element_values = []; + + if ($items_array['type'] === 'single_graph') { + if (isset($items_array['agent_name']) === false + || isset($items_array['module']) === false + ) { + // The above fields are required for this item. + continue; + } + + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'agentId' => "$agent_id", + 'metaconsoleId' => 0, + 'moduleId' => "$module_id", + 'period' => (isset($items_array['interval']) === true) ? $items_array['interval'] : '86400', + 'showLegend' => 1, + 'projection_switch' => false, + 'period_projection' => '300', + ]; + + $order++; + } + + if ($items_array['type'] === 'custom_graph') { + if (isset($items_array['graph_name']) === false + || isset($items_array['graph_type']) === false + ) { + // The above fields are required for this item. + continue; + } + + // Try to get graph and skip if not exists. + $id_graph = db_get_value('id_graph', 'tgraph', 'name', io_safe_input($items_array['graph_name'])); + + if (!($id_graph > 0)) { + continue; + } + + $graph_types = [ + 'line' => 2, + 'area' => 0, + 's_line' => 3, + 's_area' => 1, + 'h_bars' => 6, + 'v_bars' => 7, + 'gauge' => 5, + 'pie' => 8, + ]; + + if (isset($graph_types[$items_array['graph_type']]) === true) { + $graph_type_id = $items_array['graph_type']; + } else { + // Specified graph type is not a valid one. + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'id_graph' => $id_graph, + 'type' => $graph_type_id, + 'period' => (isset($items_array['interval']) === true) ? $items_array['interval'] : 86400, + 'showLegend' => 1, + ]; + + $order++; + } + + if ($items_array['type'] === 'reports') { + if (isset($items_array['report_name']) === false) { + // The above fields are required for this item. + continue; + } + + $id_report = reports_get_reports(['name' => io_safe_input($items_array['report_name'])], ['id_report'])[0]['id_report']; + + if (!($id_report > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'reportId' => $id_report, + ]; + + $order++; + } + + if ($items_array['type'] === 'network_map') { + if (isset($items_array['map_name']) === false) { + // The above fields are required for this item. + continue; + } + + $id_map = db_get_value('id', 'tmap', 'name', io_safe_input($items_array['map_name'])); + + if (!($id_map > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'networkmapId' => "$id_map", + 'xOffset' => '0', + 'yOffset' => '0', + 'zoomLevel' => 0.5, + ]; + + $order++; + } + + if ($items_array['type'] === 'service_map') { + if (isset($items_array['service_name']) === false) { + // The above fields are required for this item. + continue; + } + + $services = services_get_services(['name' => io_safe_input($items_array['service_name'])]); + + $service_id = $services[0]['id']; + + if (!($service_id > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'serviceId' => "$service_id", + 'sunburst' => (isset($items_array['show_sunburst']) === true && $items_array['show_sunburst'] === true) ? 1 : 0, + ]; + + $order++; + } + + if ($items_array['type'] === 'system_group_status') { + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'groupId' => ["0"], + 'status' => ["4,1,0,2"], + 'sunburst' => false, + ]; + + $order++; + } + + if ($items_array['type'] === 'graph_module_histogram') { + if (isset($items_array['agent_name']) === false + || isset($items_array['module']) === false + ) { + // The above fields are required for this item. + continue; + } + + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'agentId' => "$agent_id", + 'metaconsoleId' => 0, + 'moduleId' => "$module_id", + 'period' => (isset($items_array['interval']) === true) ? $items_array['interval'] : '86400', + 'sizeLabel' => 30 + ]; + + $order++; + } + + if ($items_array['type'] === 'events_list') { + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'eventType' => 0, + 'maxHours' => 8, + 'limit' => 20, + 'eventStatus' => -1, + 'severity' => -1, + 'groupId' => [""], + 'tagsId' => [""], + 'groupRecursion' => 0, + 'customFilter' => -1, + 'columns_events_widget' => ["mini_severity,evento,estado,agent_name,timestamp", ""] + ]; + + $order++; + } + + if ($items_array['type'] === 'top_n_events_by_group') { + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'amountShow' => 10, + 'maxHours' => 8, + 'groupId' => ["0"], + 'legendPosition' => "bottom", + 'show_total_data' => 0 + ]; + + $order++; + } + + if ($items_array['type'] === 'top_n') { + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'agent' => (isset($items_array['agent_name']) === true) ? $items_array['agent_name'] : '.*', + 'module' => (isset($items_array['module']) === true) ? $items_array['module'] : '.*', + 'period' => (isset($items_array['interval']) === true) ? $items_array['interval'] : '86400', + 'quantity' => '10', + 'order' => '2', + 'display' => '0', + 'type_graph' => 'bar_vertical', + 'legend' => 'agent_module' + ]; + + $order++; + } + + $item_x = $items_array['x']; + $item_y = $items_array['y']; + $item_width = $items_array['width']; + $item_height = $items_array['height']; + + $position_data = [ + 'x' => (isset($items_array['x']) === true) ? "$item_x" : "0", + 'y' => (isset($items_array['y']) === true) ? "$item_y" : "0", + 'width' => (isset($items_array['width']) === true) ? "$item_width" : "4", + 'height' => (isset($items_array['height']) === true) ? "$item_height" : "4", + ]; + + $element_values = [ + 'position' => json_encode($position_data), + 'options' => json_encode($options_data), + 'order' => $order, + 'id_dashboard' => $created_id, + 'id_widget' => $type_id, + 'prop_width' => $items_array['width'], + 'prop_height' => $items_array['height'], + ]; + + $id = db_process_sql_insert('twidget_dashboard', $element_values); + + if ($id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $id, + 'table_name' => 'twidget_dashboard', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('twidget_dashboard', ['id' => $id]); + continue; + } + } + } + } + } + + update_progress($total_items_count, $dashboards_count, $dashboards_count); + update_item_checked(DEMO_DASHBOARD); + } else { + register_error(DEMO_DASHBOARD, __('No configuration files found or failed to parse files')); + } + + // Register plugin. + $quit = false; + + // Check whether plugin agent exists in the system. Try to get default agent if not. + $matched_agents = agents_get_agents( + ['nombre' => $plugin_agent_name], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $matched_agent = $matched_agents[0]['id_agente']; + + if (isset($matched_agent) === true && $matched_agent > 0) { + $plugin_agent_id = $matched_agent; + } else { + // Skip element creation if agent does not exist. + register_error( + DEMO_PLUGIN, + __('Error in plugin creation: the specified agent for the plugin does not exist in the system: %s. Skipping plugin creation', $filename, $plugin_agent_name) + ); + + $quit = true; + } + + if ($quit === false) { + $values = [ + 'name' => io_safe_input('Pandora demo agents'), + 'description' => io_safe_input('Generate XML and traps for demo agents based on agents definition files.'), + 'max_timeout' => 300, + 'max_retries' => 0, + 'execute' => io_safe_input('perl /usr/share/pandora_server/util/plugin/pandora_demo_agents.pl'), + 'net_dst_opt' => '', + 'net_port_opt' => '', + 'user_opt' => '', + 'pass_opt' => '', + 'plugin_type' => 0, + 'macros' => '{\"1\":{\"macro\":\"_field1_\",\"desc\":\"Agents files folder path\",\"help\":\"\",\"value\":\"/usr/share/pandora_server/util/plugin/demodata_agents\",\"hide\":\"\"},\"2\":{\"macro\":\"_field2_\",\"desc\":\"Number of agents\",\"help\":\"\",\"value\":\"10\",\"hide\":\"\"},\"3\":{\"macro\":\"_field3_\",\"desc\":\"Traps target IP\",\"help\":\"\",\"value\":\"127.0.0.1\",\"hide\":\"\"},\"4\":{\"macro\":\"_field4_\",\"desc\":\"Traps community\",\"help\":\"\",\"value\":\"public\",\"hide\":\"\"},\"5\":{\"macro\":\"_field5_\",\"desc\":\"Tentacle target IP\",\"help\":\"\",\"value\":\"127.0.0.1\",\"hide\":\"\"},\"6\":{\"macro\":\"_field6_\",\"desc\":\"Tentacle port\",\"help\":\"\",\"value\":\"41121\",\"hide\":\"\"},\"7\":{\"macro\":\"_field7_\",\"desc\":\"Tentacle extra options\",\"help\":\"\",\"value\":\"\",\"hide\":\"\"}}', + 'parameters' => ''_field1_' '_field2_' '_interval_' '_field3_' '_field4_' '_field5_' '_field6_' '_field7_'', + 'no_delete' => 1, + ]; + + $created_plugin_id = db_process_sql_insert('tplugin', $values); + + if ($created_plugin_id > 0) { + // Register created item in tdemo_data. + $values = [ + 'item_id' => $created_plugin_id, + 'table_name' => 'tplugin', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tplugin', ['id' => $created_plugin_id]); + + register_error( + DEMO_PLUGIN, + __('Error in plugin creation: the plugin could not be registered. Skipping creation of plugin module') + ); + } else { + // Create plugin module. + $module_values = []; + + $module_values['id_tipo_modulo'] = db_get_value('id_tipo', 'ttipo_modulo', 'nombre', 'generic_proc'); + + if ($module_values['id_tipo_modulo'] === false) { + register_error( + DEMO_PLUGIN, + __('Error in plugin creation: module type "generic_proc" does not exist in the system. Skipping creation of plugin module') + ); + } else { + $module_values['module_interval'] = $interval; + $module_values['id_modulo'] = 4; + $module_values['id_plugin'] = $created_plugin_id; + $module_values['macros'] = '{"1":{"macro":"_field1_","desc":"Agents files folder path","help":"","value":"/usr/share/pandora_server/util/plugin/demodata_agents","hide":""},"2":{"macro":"_field2_","desc":"Number of agents","help":"","value":"'.$total_agents_to_create.'","hide":""},"3":{"macro":"_field3_","desc":"Traps target IP","help":"","value":"'.$traps_target_ip.'","hide":""},"4":{"macro":"_field4_","desc":"Traps community","help":"","value":"'.$traps_community.'","hide":""},"5":{"macro":"_field5_","desc":"Tentacle target IP","help":"","value":"'.$tentacle_target_ip.'","hide":""},"6":{"macro":"_field6_","desc":"Tentacle port","help":"","value":"'.$tentacle_port.'","hide":""},"7":{"macro":"_field7_","desc":"Tentacle extra options","help":"","value":"'.$tentacle_extra_options.'","hide":""}}'; + + $id_plugin_module = modules_create_agent_module( + $plugin_agent_id, + io_safe_input('Pandora demo data'), + $module_values + ); + + if ($id_plugin_module > 0) { + // Register created item in tdemo_data. + $values = [ + 'item_id' => $id_plugin_module, + 'table_name' => 'tagente_modulo', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $id_plugin_module]); + } + } + } + } + } else { + register_error( + DEMO_PLUGIN, + __('Error in plugin creation: the plugin could not be registered. Skipping creation of plugin module') + ); + } + } + + update_item_checked(DEMO_PLUGIN); + + $demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); + + echo json_encode(['agents_count' => $demo_agents_count]); + + return; +} + +if ($action === 'cleanup_demo_data') { + config_update_value('demo_data_load_progress', 0); + + $demo_items = db_get_all_rows_in_table('tdemo_data'); + + $module_items = array_filter( + $demo_items, + function ($item) { + return ($item['table_name'] === 'tagente_modulo'); + } + ); + + $inventory_module_items = array_filter( + $demo_items, + function ($item) { + return ($item['table_name'] === 'tagent_module_inventory'); + } + ); + + $items_delete_id_buffer = []; + + foreach ($inventory_module_items as $item) { + $items_delete_id_buffer[] = $item['item_id']; + } + + $in_clause = implode(',', $items_delete_id_buffer); + // Delete from tagente_datos_inventory. + db_process_sql('DELETE FROM tagente_datos_inventory where id_agent_module_inventory IN ('.$in_clause.')'); + + + $items_delete_id_buffer = []; + + foreach ($module_items as $item) { + $items_delete_id_buffer[] = $item['item_id']; + } + + $in_clause = implode(',', $items_delete_id_buffer); + // Delete from tagente_datos. + db_process_sql('DELETE FROM tagente_datos where id_agente_modulo IN ('.$in_clause.')'); + + $items_delete_id_buffer = []; + + $table_id_field_dict = [ + 'tconfig_os' => 'id_os', + 'tagente' => 'id_agente', + 'tgrupo' => 'id_grupo', + 'tagente_modulo' => 'id_agente_modulo', + 'tmodule_inventory' => 'id_module_inventory', + 'tagent_module_inventory' => 'id_agent_module_inventory', + 'tgraph' => 'id_graph', + 'tmap' => 'id', + 'treport' => 'id_report', + 'treport_content' => 'id_rc', + 'treport_content_sla_combined' => 'id', + 'tservice' => 'id', + 'tservice_element' => 'id', + 'ttrap' => 'id_trap', + 'titem' => 'id', + 'tgraph_source' => 'id_gs', + 'twidget_dashboard' => 'id', + 'tdashboard' => 'id', + 'tlayout' => 'id', + 'tlayout_data' => 'id', + 'tagente_estado' => 'id_agente_estado', + 'trel_item' => 'id', + 'tplugin' => 'id', + 'tgis_data_status' => 'tagente_id_agente', + 'tgis_map' => 'id_tgis_map', + 'tgis_map_layer' => 'id_tmap_layer', + ]; + + foreach ($demo_items as $item) { + $items_delete_id_buffer[$item['table_name']][] = $item['item_id']; + } + + foreach ($items_delete_id_buffer as $table_name => $ids_array) { + $all_success = true; + $in_clause = implode(',', $ids_array); + $table_id_field = $table_id_field_dict[$table_name]; + $all_success = db_process_sql('DELETE FROM '.$table_name.' WHERE '.$table_id_field.' IN ('.$in_clause.')'); + + if ($all_success !== false) { + // Delete tdemo_data registers if there were no errors when deleting the environment demo items. + db_process_sql('DELETE FROM tdemo_data WHERE table_name="'.$table_name.'" AND item_id IN ('.$in_clause.')'); + } + } + + echo 1; + return; +} + +if ($action === 'get_progress_bar') { + $operation = (string) get_parameter('operation'); + + if ($operation === 'create') { + $current_progress_val = db_get_value_filter('value', 'tconfig', ['token' => 'demo_data_load_progress']); + $demo_data_load_status = db_get_value_filter('value', 'tconfig', ['token' => 'demo_data_load_status']); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + $ret = [ + 'current_progress_val' => $current_progress_val, + 'demo_data_load_status' => json_decode(io_safe_output($demo_data_load_status), true), + ]; + } else if ($operation === 'cleanup') { + $demo_items_to_cleanup = (int) get_parameter('demo_items_to_cleanup'); + $count_current_demo_items = db_get_value('count(*)', 'tdemo_data'); + $current_progress_val = ((($demo_items_to_cleanup - $count_current_demo_items) * 100) / $demo_items_to_cleanup); + config_update_value('demo_data_delete_progress', $current_progress_val); + $ret = ['current_progress_val' => $current_progress_val]; + } + + echo json_encode($ret); + + return; +} + + +/** + * AUXILIARY FUNCTION: Calculate and return next host address within subnet given a CIDR-formatted address. + * + * @param string $ip CIDR IP address. + * + * @return string Next host address. + */ +function calculateNextHostAddress($ip) +{ + list($network, $subnet) = explode('/', $ip); + + // Convert the network address to an array of octets. + $octets = explode('.', $network); + + // Convert the last octet to an integer. + $lastOctet = (int) $octets[3]; + + // Increment the last octet, and wrap around if it exceeds 255. + $lastOctet = (($lastOctet + 1) % 256); + + // Assemble the next host address. + $nextHost = implode('.', [$octets[0], $octets[1], $octets[2], $lastOctet]); + + return $nextHost.'/'.$subnet; +} + + +/** + * AUXILIARY FUNCTION: Try to return the group ID of a group given its name or create + * and return its ID if it does not exist. + * + * @param string $name Group name. + * + * @return mixed group ID or false if group not found and could not be created. + */ +function get_group_or_create_demo_group($name) +{ + if (is_string($name) === false) { + return false; + } + + $id_group = db_get_value('id_grupo', 'tgrupo', 'nombre', io_safe_input($name)); + + if ($id_group > 0) { + return $id_group; + } else { + $id_group = groups_create_group( + io_safe_input($name), + [ + 'icon' => 'applications.png', + 'description' => '', + 'contact' => '', + 'other' => '', + ] + ); + + if ($id_group > 0) { + // Register created group in tdemo_data. + $values = [ + 'item_id' => $id_group, + 'table_name' => 'tgrupo', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo group creation if could not be registered in tdemo_data. + db_process_sql_delete('tgrupo', ['id_grupo' => $id_group]); + return false; + } + + return $id_group; + } else { + // Network map group could not be created. Skip creation of map. + return false; + } + } +} + + +/** + * AUXILIARY FUNCTION: Generate and return a randomly generated MAC address. + * + * @return string Random MAC address string. + */ +function generateRandomMacAddress() +{ + $macAddress = []; + + // Generate the remaining five octets. + for ($i = 0; $i < 6; $i++) { + $macAddress[] = str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT); + } + + // Join the octets with colons to form the MAC address. + $randomMacAddress = implode(':', $macAddress); + + return $randomMacAddress; +} + + +/** + * AUXILIARY FUNCTION: Update percentage progress. + * + * @param integer $total_items_count Global number of items to be created. + * @param integer $total_type_items_count Number of items of a specific type to be created. + * @param integer $created_num Number of items added to progress computation. + * + * @return void + */ +function update_progress($total_items_count, $total_type_items_count, $created_num=1) +{ + // Calculate progress. + $percentage_inc = (($created_num * 100) / ($total_type_items_count * $total_items_count)); + $current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', + false, + false + ); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + $new_val = ($current_progress_val + $percentage_inc); + + if ((int) round($new_val) === 100) { + $new_val = 100; + } + + config_update_value('demo_data_load_progress', $new_val); +} + + +/** + * AUXILIARY FUNCTION: Mark item as checked in the load process. + * + * @param integer $item_id Item id. + * + * @return void + */ +function update_item_checked($item_id) { + $current_load_status_data = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_status'], + 'AND', + false, + false + ); + + if ($current_load_status_data === false || $current_load_status_data === '{}') { + $current_load_data_arr = []; + } else { + $current_load_data_arr = json_decode(io_safe_output($current_load_status_data), true); + } + + $current_load_data_arr['checked_items'][] = $item_id; + + config_update_value('demo_data_load_status', json_encode($current_load_data_arr)); +} + + +/** + * AUXILIARY FUNCTION: Register error in database config info. + * + * @param integer $item_id Item id. + * @param string $error_msg Error text. + * @param boolean $search_for_repeated_msgs Increases the count of messages already stored if true. + * + * @return void + */ +function register_error( + $item_id, + $error_msg, + $search_for_repeated_msgs=false +) { + $current_load_status_data = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_status'], + 'AND', + false, + false + ); + + if ($current_load_status_data === false || $current_load_status_data === '{}') { + $current_load_data_arr = []; + } else { + $current_load_data_arr = json_decode(io_safe_output($current_load_status_data), true); + } + + if ($search_for_repeated_msgs === true && isset($current_load_data_arr['errors'][$item_id]) === true) { + $matching_string = null; + $msg_key = array_search($error_msg, $current_load_data_arr['errors'][$item_id]); + + if ($msg_key === false) { + foreach ($current_load_data_arr['errors'][$item_id] as $key => $string) { + // Use regular expression to check if the part after "(...) " matches the error string. + if (preg_match('/\s*\((.*?)\)\s*(.*)/', $string, $matches)) { + $rest_of_string = $matches[2]; + + if ($rest_of_string === $error_msg) { + $matching_string = $string; + $msg_key = $key; + break; + } + } + } + + if ($matching_string === null) { + // String not found. + $current_load_data_arr['errors'][$item_id][] = $error_msg; + } else { + // Count parentheses string was found, then replace number. + $new_error_msg = preg_replace_callback( + '/\((\d+)\)/', + function ($matches) { + $currentNumber = $matches[1]; + $newNumber = ($currentNumber + 1); + return "($newNumber)"; + }, + $matching_string + ); + $current_load_data_arr['errors'][$item_id][$msg_key] = $new_error_msg; + } + } else { + // String without count found. + $new_error_msg = '(2) '.$error_msg; + $current_load_data_arr['errors'][$item_id][$msg_key] = $new_error_msg; + } + } else { + $current_load_data_arr['errors'][$item_id][] = $error_msg; + } + + config_update_value('demo_data_load_status', json_encode($current_load_data_arr)); +} diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index 2e2e143a62..a7aa81b7f5 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -581,6 +581,7 @@ class WelcomeWindow extends Wizard ], ]; + $fields['load_demo_data'] = __('Load demo data'); $fields['wizard_agent'] = __('Agent installation wizard'); $fields['check_web'] = __('Create WEB monitoring'); $fields['check_connectivity'] = __('Create network monitoring'); @@ -698,6 +699,52 @@ class WelcomeWindow extends Wizard echo html_print_submit_button(__('Create'), 'create_goliat', false, ['icon' => 'next', 'style' => 'margin-top:15px; float:right;']); ?> +