Skip to content

update examples

Oliver Gaida edited this page Dec 17, 2020 · 17 revisions
  • update a text-field with plain text

WSL-001@~$rusdc find nr "name = 'server1'" z_backup | jq -r '.[0]["z_backup"]'
this is old
text over
three lines.

create a shellscript update_z_backup.sh with content:

#!/usr/bin/env bash

for hostname in server1
do
        echo update $hostname
        export ciname=$hostname
        rusdc update_attr --plain-text nr $ciname z_backup "$(cat <(rusdc find nr "name = '$ciname'" z_backup | jq -r '.[0]["z_backup"]') <(echo "

----------------
this is some
new text ..."))"
done

run it

WSL-001@~$./update_z_backup.sh
update server1

test the result:

WSL-001@~$rusdc find nr "name = 'server1'" z_backup | jq -r '.[0]["z_backup"]'
this is old
text over
three lines.


----------------
this is some
new text ...
  • update a text-field

in this example i will update the field z_backup of the object nr :

host=my_server
# init value and overwrite text if already exist (for newlines use `\n`):
rusdc update_attr nr $host z_backup "first row\nsecond row"
# let's look
rusdc find nr "name like '$host'" z_backup --format mlr
z_backup
first row
second row
# now update the field and append new lines at the end of the
#   existing text (we use `jq` for some json specials):
rusdc find nr "name like '$host'" "@COMMON_NAME,z_backup" | jq \ 
'(.[0]|.+{z_backup:(.z_backup+"\nsome new\nlines")})|{nr:.}' \
| rusdc update
# let's look again
rusdc find nr "name like '$host'" z_backup --format mlr
z_backup
first row
second row
some new
lines
  • add a log-comment to an incident:

echo '{
  "alg": {
    "type": {
      "@COMMON_NAME": "Log Comment"
    },
    "analyst": {
      "@COMMON_NAME": "Gaida, Oliver "
    },
    "call_req_id": {
      "@COMMON_NAME": "I00001"
    },
    "description": "my description ..."
  }
}' | rusdc create
  • update field customer info set to false:

rusdc update_attr in I00001 z_cst_mail_flag 0
  • change the call_back_date of ticket

rusdc update_attr in I00001 call_back_date "2019-11-12 00:00:12 +0100"
  • bash-function for closing a ticket

If the ticket can not be closed, check the requirements for closing like workflows and required fields.

function close_ticket(){
  ticket=$1
  if [ ${ticket:0:1}==C ]
  then
    rusdc update_ref_attr chg $1 status "closed"
  else
    rusdc update_ref_attr in $1 status "closed"
  fi
}
# call with:
close_ticket C000001
close_ticket I00001

Clone this wiki locally