3 ELK_MAP_SUCCESS_RE="\"acknowledged\": *true"
6 echo -n "syntax: $(basename $0) "
12 echo "$(date +"%Y-%m-%d_%H-%M-%S") $1" >> ${POLICY_HOME}/logs/elk.log
16 function delete_index() {
17 if [[ $DEBUG == y ]]; then
18 echo "-- ${FUNCNAME[0]} $@ --"
22 COMMAND="curl --silent -X DELETE http://localhost:9200/policy"
23 OUTPUT="$(${COMMAND} 2>&1)"
26 log "${RC}: ${COMMAND}"
29 if [[ ${RC} != 0 ]] || [[ ! ${OUTPUT} =~ ${ELK_MAP_SUCCESS_RE} ]]; then
30 log "WARNING: curl: delete /policy: ${RC}"
34 log "OK: curl: delete /policy: ${OUTPUT}"
38 function create_index() {
39 if [[ $DEBUG == y ]]; then
40 echo "-- ${FUNCNAME[0]} $@ --"
44 COMMAND="curl --silent -X PUT http://localhost:9200/policy"
45 OUTPUT="$(${COMMAND} 2>&1)"
48 log "${RC}: ${COMMAND}"
51 if [[ ${RC} != 0 ]] || [[ ! ${OUTPUT} =~ ${ELK_MAP_SUCCESS_RE} ]]; then
52 log "ERROR: curl: put /policy: ${RC}"
56 log "OK: curl: put /policy."
60 function check_elk_status() {
61 if [[ $DEBUG == y ]]; then
62 echo "-- ${FUNCNAME[0]} $@ --"
66 ${POLICY_HOME}/etc/init.d/elk status
67 if [[ $? != 0 ]]; then
68 log "ERROR: elk is down. Aborting .."
73 function check_elk_policy_index() {
74 if [[ $DEBUG == y ]]; then
75 echo "-- ${FUNCNAME[0]} $@ --"
79 COMMAND="curl --silent -X GET http://localhost:9200/policy"
80 OUTPUT="$(${COMMAND} 2>&1)"
83 log "${RC}: ${COMMAND}"
85 if [[ ${RC} != 0 ]] || [[ ! ${OUTPUT} =~ policy ]]; then
86 log "ERROR: curl: get /policy: ${RC}"
90 log "OK: curl: get /policy."
94 #The Script will update the policy data on querying from database as a bulk to Elastic Database
96 if [[ $DEBUG == y ]]; then
97 echo "-- ${FUNCNAME[0]} $@ --"
103 if ! check_elk_policy_index; then
104 echo "policy index does not exist. So, Policy Index is created."
105 if ! create_index; then
106 echo "abort: policy index creation failed."
111 $JAVA_HOME/bin/java -cp $POLICY_HOME/servers/pap/webapps/pap/WEB-INF/lib/ECOMP-PAP-REST-*.jar:$POLICY_HOME/servers/pap/webapps/pap/WEB-INF/lib/*: -DPROPERTY_FILE=$POLICY_HOME/servers/pap/bin/policyelk.properties org.openecomp.policy.pap.xacml.rest.elk.client.ElasticSearchPolicyUpdate
114 #########################################################################
116 ## script execution body
118 #########################################################################
123 until [[ -z "$1" ]]; do
125 -d|--debug|debug) DEBUG=y
128 -a|--audit|audit) OPERATION=audit
137 # operation validation
140 *) echo "invalid operation (${OPERATION}).";
146 if [[ -z ${POLICY_HOME} ]]; then
147 echo "error: POLICY_HOME is unset."
151 log "**** $OPERATION ****"
153 if pidof -o %PPID -x $(basename $0) > /dev/null 2>&1; then
154 echo "WARNING: an $(basename $0) process is already running. Exiting."
162 *) echo "invalid operation (${OPERATION}).";