multinode-db1: Add logic and template to create userlists by department.

This commit is contained in:
Magnus Andersson 2024-08-30 08:57:17 +02:00 committed by Micke Nordin
parent 9ee7f6f7b8
commit 2f682f8bd8
Signed by untrusted user: Micke
GPG key ID: 0DA0A7A5708FE257
2 changed files with 11 additions and 21 deletions

View file

@ -18,6 +18,9 @@ class sunetdrive::multinode_db(){
notify { 'hostmessage': notify { 'hostmessage':
message => 'We are on multinode-db1. Set up statistics environment.', message => 'We are on multinode-db1. Set up statistics environment.',
} }
$custdata=$customers.reduce({}) |$memo, $value| {
$memo + {$value => lookup($value)}
}
$rclone_url = 'https://downloads.rclone.org/rclone-current-linux-amd64.deb' $rclone_url = 'https://downloads.rclone.org/rclone-current-linux-amd64.deb'
$local_path = '/tmp/rclone-current-linux-amd64.deb' $local_path = '/tmp/rclone-current-linux-amd64.deb'
exec { 'rclone_deb': exec { 'rclone_deb':
@ -44,5 +47,12 @@ class sunetdrive::multinode_db(){
group => 'root', group => 'root',
mode => '0700', mode => '0700',
} }
file { '/root/tasks/genusersondepartmentlists.sh':
ensure => file,
content => template('sunetdrive/mariadb/genuserdeplists.sh.erb'),
owner => 'root',
group => 'root',
mode => '0700',
}
} }
} }

View file

@ -1,10 +1,5 @@
#!/bin/bash #!/bin/bash
<% basedir="statistics:drive-server-coms" -%>
<% cupath="/opt/mariadb/statistics/users/" -%>
<% custdata="/opt/mariadb/statistics/custdata.json" -%>
status=0
<% @custdata.each do |cust,data| -%> <% @custdata.each do |cust,data| -%>
#Customer <%= cust %> has no billing departments. #Customer <%= cust %> has no billing departments.
<% if defined?(data[@environment]["billdomains"]) && data[@environment]["billdomains"] -%> <% if defined?(data[@environment]["billdomains"]) && data[@environment]["billdomains"] -%>
@ -12,21 +7,6 @@ mkdir -p /opt/mariadb/statistics/users/<%= cust %>
chmod '0700' /opt/mariadb/statistics/users/<%= cust %> chmod '0700' /opt/mariadb/statistics/users/<%= cust %>
<% data[@environment]["billdomains"].each do |dom| -%> <% data[@environment]["billdomains"].each do |dom| -%>
/root/tasks/listusersbydep.sh <%= cust %> <%= dom %> > /opt/mariadb/statistics/users/<%= cust %>/users-<%= dom.gsub(/[.]/, '-') %>.json /root/tasks/listusersbydep.sh <%= cust %> <%= dom %> > /opt/mariadb/statistics/users/<%= cust %>/users-<%= dom.gsub(/[.]/, '-') %>.json
if jq . <%= cupath + cust %>/users-<%= dom.gsub(/[.]/, '-') %>.json &>/dev/null
then
timeout 30s rclone copy -c --no-check-certificate --webdav-headers "Host,sunet.drive.sunet.se" --use-cookies <%= cupath + cust %>/users-<%= dom.gsub(/[.]/, '-') %>.json <%= basedir%>/<%= cust %>-<%= @environment%>/
[[ $? -eq 0 ]] || { status=1 ; echo "Error: Upload of user data failed." ; }
else
echo "Error in json data"
status=1
fi
<% end -%> <% end -%>
<% end -%> <% end -%>
<% end -%> <% end -%>
if [[ -f <%= custdata %> ]]
then
timeout 30s rclone copy -c --no-check-certificate --webdav-headers "Host,sunet.drive.sunet.se" --use-cookies <%= custdata %> <%= basedir%>/
fi
exit ${status}