Trying to run a bash script in zabbix and automate the IP/Hostname

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Was wondering if you could help me out. I'm trying to run a bash script on a zabbix server that will pull running configs from hosts to a TFTP server. I have the following script and it works well. The only issue is that where it says hostIP=$1 and hostName=$2 it only works if i manually enter the IP and hostname either in the script or when I call it. Is there anyway I can run this script without having to manually enter the hostname and IP? I have like 3000 devices and would like this to actively pull as configs change.
Within Zabbix, under Confguration of Actions, I have the command running on the Zabbix server to run the bash script with HOST.IP HOST.HOST and was hoping this would pull the ip and hostname automatically from zabbix but doesn't seem to be the case. In Conditions, I have it such that whenever someone wr a configuration, it'll trigger an alarm and should run the script. Once it triggers the alarm, I'm hoping that there is some method that would allow me to pull the ip and hostname from the alert and run the script on that IP/host. Can anyone help me out?
#!/bin/bash
#accept host IP and TFTP-server from Zabbix
hostIP=$1
hostName=$2
tftp="x.x.x.x" (where this is an ip)
####iOS strings####
#execute copy run start
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 4 #This specifies
type of file to copy from (running config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 3 #This specifies
type of file to copy to (startup config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1 #This checks
for active status of table entry
#execute copy run tftp $tftp on host and transfer config to TFTP server
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.2.112 i 1 #This uses tftp
to push config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.112 i 4 #This specifies
type of file to copy from (running config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.112 i 1 #This specifies
type of file to copy to (network file)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.5.112 a $tftp
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.6.112 s $hostName #-
config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.112 i 1
####CatOS strings####
#execute copy run tftp $tftp on host and transfer config to TFTP server
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.1.0 s $tftp
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.2.0 s $hostName #-config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.3.0 i 1
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.4.0 i 3
#END
echo "Script completed successfully, please visit TFTP server to find
backup"
bash zabbix
add a comment |Â
up vote
0
down vote
favorite
Was wondering if you could help me out. I'm trying to run a bash script on a zabbix server that will pull running configs from hosts to a TFTP server. I have the following script and it works well. The only issue is that where it says hostIP=$1 and hostName=$2 it only works if i manually enter the IP and hostname either in the script or when I call it. Is there anyway I can run this script without having to manually enter the hostname and IP? I have like 3000 devices and would like this to actively pull as configs change.
Within Zabbix, under Confguration of Actions, I have the command running on the Zabbix server to run the bash script with HOST.IP HOST.HOST and was hoping this would pull the ip and hostname automatically from zabbix but doesn't seem to be the case. In Conditions, I have it such that whenever someone wr a configuration, it'll trigger an alarm and should run the script. Once it triggers the alarm, I'm hoping that there is some method that would allow me to pull the ip and hostname from the alert and run the script on that IP/host. Can anyone help me out?
#!/bin/bash
#accept host IP and TFTP-server from Zabbix
hostIP=$1
hostName=$2
tftp="x.x.x.x" (where this is an ip)
####iOS strings####
#execute copy run start
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 4 #This specifies
type of file to copy from (running config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 3 #This specifies
type of file to copy to (startup config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1 #This checks
for active status of table entry
#execute copy run tftp $tftp on host and transfer config to TFTP server
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.2.112 i 1 #This uses tftp
to push config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.112 i 4 #This specifies
type of file to copy from (running config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.112 i 1 #This specifies
type of file to copy to (network file)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.5.112 a $tftp
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.6.112 s $hostName #-
config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.112 i 1
####CatOS strings####
#execute copy run tftp $tftp on host and transfer config to TFTP server
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.1.0 s $tftp
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.2.0 s $hostName #-config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.3.0 i 1
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.4.0 i 3
#END
echo "Script completed successfully, please visit TFTP server to find
backup"
bash zabbix
Looks like your problem is not getting parameters passed as you expect. Please show the full line from the action command. As a test, make the script print positional parameters to a file. What does it get from Zabbix?
â Richlv
Nov 29 '17 at 21:34
Hi is this what you mean? /usr/lib/zabbix/externalscripts/testbackup.sh $HOST.IP$HOST.HOST. The other parameters are Step 1 to 1, Operation type is Remote Command, Target list is Current host, Type is Custom Script, Execute on Zabbix Server. its running v 3.0
â ksuzy31
Nov 29 '17 at 21:37
And so I'm not 100% how zabbix works, why its not working now, but theoretically if i do a wr on any host, I feel like it should be running this script and was hoping hostip and host.host were fields that would be autopopulated based on the host I did a wr on
â ksuzy31
Nov 29 '17 at 21:38
Did you test by printing the received parameters to a file? That would tell whether the script is invoked at all and what data it gets. Besides that, you are missing the space in "$HOST.IP$HOST.HOST", and I would recommend doublequoting both values, just in case.
â Richlv
Nov 29 '17 at 21:58
Hi so again, this works if i manually run the script like ./Backup.sh (Enter Host IP) (Enter hostname) but I don't want to keep manually running the script like this and enter hostip and hostname because i have like 3000 hosts to get through. is there anyway to change it such that the hostip and hostname gets automatically pulled from the switch i do a wr on the config
â ksuzy31
Dec 4 '17 at 17:38
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Was wondering if you could help me out. I'm trying to run a bash script on a zabbix server that will pull running configs from hosts to a TFTP server. I have the following script and it works well. The only issue is that where it says hostIP=$1 and hostName=$2 it only works if i manually enter the IP and hostname either in the script or when I call it. Is there anyway I can run this script without having to manually enter the hostname and IP? I have like 3000 devices and would like this to actively pull as configs change.
Within Zabbix, under Confguration of Actions, I have the command running on the Zabbix server to run the bash script with HOST.IP HOST.HOST and was hoping this would pull the ip and hostname automatically from zabbix but doesn't seem to be the case. In Conditions, I have it such that whenever someone wr a configuration, it'll trigger an alarm and should run the script. Once it triggers the alarm, I'm hoping that there is some method that would allow me to pull the ip and hostname from the alert and run the script on that IP/host. Can anyone help me out?
#!/bin/bash
#accept host IP and TFTP-server from Zabbix
hostIP=$1
hostName=$2
tftp="x.x.x.x" (where this is an ip)
####iOS strings####
#execute copy run start
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 4 #This specifies
type of file to copy from (running config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 3 #This specifies
type of file to copy to (startup config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1 #This checks
for active status of table entry
#execute copy run tftp $tftp on host and transfer config to TFTP server
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.2.112 i 1 #This uses tftp
to push config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.112 i 4 #This specifies
type of file to copy from (running config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.112 i 1 #This specifies
type of file to copy to (network file)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.5.112 a $tftp
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.6.112 s $hostName #-
config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.112 i 1
####CatOS strings####
#execute copy run tftp $tftp on host and transfer config to TFTP server
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.1.0 s $tftp
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.2.0 s $hostName #-config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.3.0 i 1
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.4.0 i 3
#END
echo "Script completed successfully, please visit TFTP server to find
backup"
bash zabbix
Was wondering if you could help me out. I'm trying to run a bash script on a zabbix server that will pull running configs from hosts to a TFTP server. I have the following script and it works well. The only issue is that where it says hostIP=$1 and hostName=$2 it only works if i manually enter the IP and hostname either in the script or when I call it. Is there anyway I can run this script without having to manually enter the hostname and IP? I have like 3000 devices and would like this to actively pull as configs change.
Within Zabbix, under Confguration of Actions, I have the command running on the Zabbix server to run the bash script with HOST.IP HOST.HOST and was hoping this would pull the ip and hostname automatically from zabbix but doesn't seem to be the case. In Conditions, I have it such that whenever someone wr a configuration, it'll trigger an alarm and should run the script. Once it triggers the alarm, I'm hoping that there is some method that would allow me to pull the ip and hostname from the alert and run the script on that IP/host. Can anyone help me out?
#!/bin/bash
#accept host IP and TFTP-server from Zabbix
hostIP=$1
hostName=$2
tftp="x.x.x.x" (where this is an ip)
####iOS strings####
#execute copy run start
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.111 i 4 #This specifies
type of file to copy from (running config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.111 i 3 #This specifies
type of file to copy to (startup config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.111 i 1 #This checks
for active status of table entry
#execute copy run tftp $tftp on host and transfer config to TFTP server
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.2.112 i 1 #This uses tftp
to push config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.3.112 i 4 #This specifies
type of file to copy from (running config)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.4.112 i 1 #This specifies
type of file to copy to (network file)
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.5.112 a $tftp
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.6.112 s $hostName #-
config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.9.96.1.1.1.1.14.112 i 1
####CatOS strings####
#execute copy run tftp $tftp on host and transfer config to TFTP server
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.1.0 s $tftp
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.2.0 s $hostName #-config
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.3.0 i 1
snmpset -c -v 1 $hostIP 1.3.6.1.4.1.9.5.1.5.4.0 i 3
#END
echo "Script completed successfully, please visit TFTP server to find
backup"
bash zabbix
edited Nov 29 '17 at 22:35
Hauke Laging
53.5k1282130
53.5k1282130
asked Nov 29 '17 at 21:01
ksuzy31
164
164
Looks like your problem is not getting parameters passed as you expect. Please show the full line from the action command. As a test, make the script print positional parameters to a file. What does it get from Zabbix?
â Richlv
Nov 29 '17 at 21:34
Hi is this what you mean? /usr/lib/zabbix/externalscripts/testbackup.sh $HOST.IP$HOST.HOST. The other parameters are Step 1 to 1, Operation type is Remote Command, Target list is Current host, Type is Custom Script, Execute on Zabbix Server. its running v 3.0
â ksuzy31
Nov 29 '17 at 21:37
And so I'm not 100% how zabbix works, why its not working now, but theoretically if i do a wr on any host, I feel like it should be running this script and was hoping hostip and host.host were fields that would be autopopulated based on the host I did a wr on
â ksuzy31
Nov 29 '17 at 21:38
Did you test by printing the received parameters to a file? That would tell whether the script is invoked at all and what data it gets. Besides that, you are missing the space in "$HOST.IP$HOST.HOST", and I would recommend doublequoting both values, just in case.
â Richlv
Nov 29 '17 at 21:58
Hi so again, this works if i manually run the script like ./Backup.sh (Enter Host IP) (Enter hostname) but I don't want to keep manually running the script like this and enter hostip and hostname because i have like 3000 hosts to get through. is there anyway to change it such that the hostip and hostname gets automatically pulled from the switch i do a wr on the config
â ksuzy31
Dec 4 '17 at 17:38
add a comment |Â
Looks like your problem is not getting parameters passed as you expect. Please show the full line from the action command. As a test, make the script print positional parameters to a file. What does it get from Zabbix?
â Richlv
Nov 29 '17 at 21:34
Hi is this what you mean? /usr/lib/zabbix/externalscripts/testbackup.sh $HOST.IP$HOST.HOST. The other parameters are Step 1 to 1, Operation type is Remote Command, Target list is Current host, Type is Custom Script, Execute on Zabbix Server. its running v 3.0
â ksuzy31
Nov 29 '17 at 21:37
And so I'm not 100% how zabbix works, why its not working now, but theoretically if i do a wr on any host, I feel like it should be running this script and was hoping hostip and host.host were fields that would be autopopulated based on the host I did a wr on
â ksuzy31
Nov 29 '17 at 21:38
Did you test by printing the received parameters to a file? That would tell whether the script is invoked at all and what data it gets. Besides that, you are missing the space in "$HOST.IP$HOST.HOST", and I would recommend doublequoting both values, just in case.
â Richlv
Nov 29 '17 at 21:58
Hi so again, this works if i manually run the script like ./Backup.sh (Enter Host IP) (Enter hostname) but I don't want to keep manually running the script like this and enter hostip and hostname because i have like 3000 hosts to get through. is there anyway to change it such that the hostip and hostname gets automatically pulled from the switch i do a wr on the config
â ksuzy31
Dec 4 '17 at 17:38
Looks like your problem is not getting parameters passed as you expect. Please show the full line from the action command. As a test, make the script print positional parameters to a file. What does it get from Zabbix?
â Richlv
Nov 29 '17 at 21:34
Looks like your problem is not getting parameters passed as you expect. Please show the full line from the action command. As a test, make the script print positional parameters to a file. What does it get from Zabbix?
â Richlv
Nov 29 '17 at 21:34
Hi is this what you mean? /usr/lib/zabbix/externalscripts/testbackup.sh $HOST.IP$HOST.HOST. The other parameters are Step 1 to 1, Operation type is Remote Command, Target list is Current host, Type is Custom Script, Execute on Zabbix Server. its running v 3.0
â ksuzy31
Nov 29 '17 at 21:37
Hi is this what you mean? /usr/lib/zabbix/externalscripts/testbackup.sh $HOST.IP$HOST.HOST. The other parameters are Step 1 to 1, Operation type is Remote Command, Target list is Current host, Type is Custom Script, Execute on Zabbix Server. its running v 3.0
â ksuzy31
Nov 29 '17 at 21:37
And so I'm not 100% how zabbix works, why its not working now, but theoretically if i do a wr on any host, I feel like it should be running this script and was hoping hostip and host.host were fields that would be autopopulated based on the host I did a wr on
â ksuzy31
Nov 29 '17 at 21:38
And so I'm not 100% how zabbix works, why its not working now, but theoretically if i do a wr on any host, I feel like it should be running this script and was hoping hostip and host.host were fields that would be autopopulated based on the host I did a wr on
â ksuzy31
Nov 29 '17 at 21:38
Did you test by printing the received parameters to a file? That would tell whether the script is invoked at all and what data it gets. Besides that, you are missing the space in "$HOST.IP$HOST.HOST", and I would recommend doublequoting both values, just in case.
â Richlv
Nov 29 '17 at 21:58
Did you test by printing the received parameters to a file? That would tell whether the script is invoked at all and what data it gets. Besides that, you are missing the space in "$HOST.IP$HOST.HOST", and I would recommend doublequoting both values, just in case.
â Richlv
Nov 29 '17 at 21:58
Hi so again, this works if i manually run the script like ./Backup.sh (Enter Host IP) (Enter hostname) but I don't want to keep manually running the script like this and enter hostip and hostname because i have like 3000 hosts to get through. is there anyway to change it such that the hostip and hostname gets automatically pulled from the switch i do a wr on the config
â ksuzy31
Dec 4 '17 at 17:38
Hi so again, this works if i manually run the script like ./Backup.sh (Enter Host IP) (Enter hostname) but I don't want to keep manually running the script like this and enter hostip and hostname because i have like 3000 hosts to get through. is there anyway to change it such that the hostip and hostname gets automatically pulled from the switch i do a wr on the config
â ksuzy31
Dec 4 '17 at 17:38
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f407825%2ftrying-to-run-a-bash-script-in-zabbix-and-automate-the-ip-hostname%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Looks like your problem is not getting parameters passed as you expect. Please show the full line from the action command. As a test, make the script print positional parameters to a file. What does it get from Zabbix?
â Richlv
Nov 29 '17 at 21:34
Hi is this what you mean? /usr/lib/zabbix/externalscripts/testbackup.sh $HOST.IP$HOST.HOST. The other parameters are Step 1 to 1, Operation type is Remote Command, Target list is Current host, Type is Custom Script, Execute on Zabbix Server. its running v 3.0
â ksuzy31
Nov 29 '17 at 21:37
And so I'm not 100% how zabbix works, why its not working now, but theoretically if i do a wr on any host, I feel like it should be running this script and was hoping hostip and host.host were fields that would be autopopulated based on the host I did a wr on
â ksuzy31
Nov 29 '17 at 21:38
Did you test by printing the received parameters to a file? That would tell whether the script is invoked at all and what data it gets. Besides that, you are missing the space in "$HOST.IP$HOST.HOST", and I would recommend doublequoting both values, just in case.
â Richlv
Nov 29 '17 at 21:58
Hi so again, this works if i manually run the script like ./Backup.sh (Enter Host IP) (Enter hostname) but I don't want to keep manually running the script like this and enter hostip and hostname because i have like 3000 hosts to get through. is there anyway to change it such that the hostip and hostname gets automatically pulled from the switch i do a wr on the config
â ksuzy31
Dec 4 '17 at 17:38