organzing for portfolio
This commit is contained in:
		
							
								
								
									
										33
									
								
								NetworkManagement/librenmsPollScripts/discoveryWrap.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								NetworkManagement/librenmsPollScripts/discoveryWrap.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| #!/bin/bash | ||||
| #wrapper script called from cron for observium polling. A lightweight wrapper around poller.php | ||||
|  | ||||
| #Source common functions/variables | ||||
| source /var/observium/CMDB/pollScripts/discoveryWrapControl | ||||
| source /var/observium/CMDB/pollScripts/discoveryWrapCommon.sh | ||||
|  | ||||
|  | ||||
| function discover() | ||||
| #Perform discovery of hosts with pattern passed in via $1 | ||||
| { | ||||
| logger "Performing discovery of node type: $1" | ||||
| /var/observium/observium/discovery.php -h *$1*  | ||||
| if [ $? -ne 0 ]; then | ||||
| error_out fatal "discovery.php run for $1 failed" | ||||
| fi | ||||
| } | ||||
|  | ||||
| function main() | ||||
| #Main execution body | ||||
| { | ||||
| for arg in "${commandline_args[@]}"; do | ||||
|  preflight "$arg" | ||||
|  touch /tmp/discovery-$arg.lock | ||||
|  discover "$arg" | ||||
|  rm -f /tmp/discovery-$arg.lock | ||||
| logger "Completed discovery." | ||||
| done | ||||
| } | ||||
|  | ||||
| #Kick it all off | ||||
| commandline_args=("$@") | ||||
| main | ||||
							
								
								
									
										26
									
								
								NetworkManagement/librenmsPollScripts/discoveryWrapCommon.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								NetworkManagement/librenmsPollScripts/discoveryWrapCommon.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| function error_out() | ||||
| #Handle error conditions | ||||
| #Takes two arguments: | ||||
| #Error type (fatal,nonfatal) | ||||
| #Error message | ||||
| { | ||||
| if [ $1 == "fatal" ]; then | ||||
| echo "$0 has experienced a fatal error condition and has aborted operation at $DATE. Please investigate and resolve. Details: $2" | mail -s "Observium discovery fatal error" -r $ERROR_FROM $ERROR_TO | ||||
| logger $0 has experienced a fatal error condition and has aborted operation at $DATE. Details: $2 | ||||
| exit 1 | ||||
| elif [ $1 == "nonfatal" ]; then | ||||
| echo "$0 has experienced a non fatal error condition and has continued operation at $DATE. Please investigate and resolve. \n Details: $2" | mail -s "Observium discovery non fatal error" -r $ERROR_FROM $ERROR_TO | ||||
| logger $0 has experienced a non fatal error condition and has continued operation at $DATE . Details: $2 | ||||
| fi | ||||
| } | ||||
|  | ||||
| function preflight() | ||||
| #Perform preflight checks for all scan types | ||||
| { | ||||
| logger "Performing preflight checks for discovery of node type: $1" | ||||
| echo "Performing preflight checks for discovery of node type: $1" | ||||
|  | ||||
| if [ -f /tmp/discovery-$1.lock ]; then | ||||
| error_out fatal "lock file /tmp/discovery-$1.lock exists. Bailing out." | ||||
| fi | ||||
| } | ||||
| @@ -0,0 +1,3 @@ | ||||
| DATE=$(date +%m/%d/%Y-%H:%M) | ||||
| ERROR_FROM="" | ||||
| ERROR_TO="" | ||||
							
								
								
									
										33
									
								
								NetworkManagement/librenmsPollScripts/pollerWrap.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								NetworkManagement/librenmsPollScripts/pollerWrap.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| #!/bin/bash | ||||
| #wrapper script called from cron for observium polling. A lightweight wrapper around poller.php | ||||
|  | ||||
| #Source common functions/variables | ||||
| source /var/observium/CMDB/pollScripts/pollerWrapControl | ||||
| source /var/observium/CMDB/pollScripts/pollerWrapCommon.sh | ||||
|  | ||||
|  | ||||
| function poller() | ||||
| #Perform scan | ||||
| { | ||||
| logger "Performing polling of node type: $1" | ||||
| /var/observium/observium/poller.php -h *$1*  | ||||
| if [ $? -ne 0 ]; then | ||||
| error_out fatal "poller.php run for $1 failed" | ||||
| fi | ||||
| } | ||||
|  | ||||
| function main() | ||||
| #Main execution body | ||||
| { | ||||
| for arg in "${commandline_args[@]}"; do | ||||
|  preflight "$arg" | ||||
|  touch /tmp/poll-$arg.lock | ||||
|  poller "$arg" | ||||
|  rm -f /tmp/poll-$arg.lock | ||||
| logger "Completed polling." | ||||
| done | ||||
| } | ||||
|  | ||||
| #Kick it all off | ||||
| commandline_args=("$@") | ||||
| main | ||||
							
								
								
									
										27
									
								
								NetworkManagement/librenmsPollScripts/pollerWrapCommon.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								NetworkManagement/librenmsPollScripts/pollerWrapCommon.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| function error_out() | ||||
| #Handle error conditions | ||||
| #Takes two arguments: | ||||
| #Error type (fatal,nonfatal) | ||||
| #Error message | ||||
| { | ||||
| if [ $1 == "fatal" ]; then | ||||
| echo "$0 has experienced a fatal error condition and has aborted operation at $DATE. Please investigate and resolve. Details: $2" | mail -s "Observium polling fatal error" -r $ERROR_FROM $ERROR_TO | ||||
| logger $0 has experienced a fatal error condition and has aborted operation at $DATE. Details: $2 | ||||
| exit 1 | ||||
| elif [ $1 == "nonfatal" ]; then | ||||
| echo "$0 has experienced a non fatal error condition and has continued operation at $DATE. Please investigate and resolve. \n Details: $2" | mail -s "Observium polling non fatal error" -r $ERROR_FROM $ERROR_TO | ||||
| logger $0 has experienced a non fatal error condition and has continued operation at $DATE . Details: $2 | ||||
| fi | ||||
| } | ||||
|  | ||||
| function preflight() | ||||
| #Perform preflight checks for all scan types | ||||
| { | ||||
| echo "Performing preflight checks for polling of: $1" | ||||
| logger "Performing preflight checks for polling of: $1" | ||||
|  | ||||
| if [ -f /tmp/poll-$1.lock ]; then | ||||
| error_out fatal "Poll lock file /tmp/poll-$1.lock exists." | ||||
| fi | ||||
|  | ||||
| } | ||||
							
								
								
									
										3
									
								
								NetworkManagement/librenmsPollScripts/pollerWrapControl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								NetworkManagement/librenmsPollScripts/pollerWrapControl
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| DATE=$(date +%m/%d/%Y-%H:%M) | ||||
| ERROR_FROM="" | ||||
| ERROR_TO="" | ||||
		Reference in New Issue
	
	Block a user