This is an automated email from the ASF dual-hosted git repository.

rawlin pushed a commit to branch 4.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/4.1.x by this push:
     new 4737f94  Add ORT atstccfg log appending and logrotate (#4923) (#5073)
4737f94 is described below

commit 4737f9406bbda8c8a267b904752ad7bd85eac530
Author: Robert O Butts <[email protected]>
AuthorDate: Wed Sep 30 11:04:56 2020 -0600

    Add ORT atstccfg log appending and logrotate (#4923) (#5073)
    
    (cherry picked from commit 3cab2716d993d6fb27c61fa9cb48629da7a58ada)
---
 traffic_ops/build/traffic_ops_ort.spec   |  8 ++++++++
 traffic_ops/ort/README.md                |  6 ++++++
 traffic_ops/ort/atstccfg/atstccfg.go     | 11 +++++++++++
 traffic_ops/ort/build/atstccfg.logrotate | 26 ++++++++++++++++++++++++++
 traffic_ops/ort/traffic_ops_ort.pl       | 23 +++++++++++++----------
 5 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/traffic_ops/build/traffic_ops_ort.spec 
b/traffic_ops/build/traffic_ops_ort.spec
index 1147af9..7f68335 100644
--- a/traffic_ops/build/traffic_ops_ort.spec
+++ b/traffic_ops/build/traffic_ops_ort.spec
@@ -48,10 +48,15 @@ 
godir=src/github.com/apache/trafficcontrol/traffic_ops/ort/atstccfg
 
 %install
 mkdir -p ${RPM_BUILD_ROOT}/opt/ort
+mkdir -p "${RPM_BUILD_ROOT}"/etc/logrotate.d
+mkdir -p "${RPM_BUILD_ROOT}"/var/log/ort
+
 cp -p ${RPM_SOURCE_DIR}/traffic_ops_ort-%{version}/traffic_ops_ort.pl 
${RPM_BUILD_ROOT}/opt/ort
 cp -p ${RPM_SOURCE_DIR}/traffic_ops_ort-%{version}/supermicro_udev_mapper.pl 
${RPM_BUILD_ROOT}/opt/ort
 
 src=src/github.com/apache/trafficcontrol/traffic_ops/ort/atstccfg
+cp -p ${RPM_SOURCE_DIR}/traffic_ops_ort-%{version}/build/atstccfg.logrotate 
"${RPM_BUILD_ROOT}"/etc/logrotate.d/atstccfg
+touch ${RPM_BUILD_ROOT}/var/log/ort/atstccfg.log
 cp -p "$src"/atstccfg ${RPM_BUILD_ROOT}/opt/ort
 
 %clean
@@ -65,4 +70,7 @@ rm -rf ${RPM_BUILD_ROOT}
 /opt/ort/supermicro_udev_mapper.pl
 /opt/ort/atstccfg
 
+%config(noreplace) /etc/logrotate.d/atstccfg
+%config(noreplace) /var/log/ort/atstccfg.log
+
 %changelog
diff --git a/traffic_ops/ort/README.md b/traffic_ops/ort/README.md
index 62e6192..7457a0a 100644
--- a/traffic_ops/ort/README.md
+++ b/traffic_ops/ort/README.md
@@ -94,6 +94,12 @@ ORT verifies all devices in the file are owned by the owner 
listed in the file,
 
 ORT verifies all devices in the file do not have filesystems. If any device 
has a filesystem, ORT assumes it was a mistake to assign as an ATS storage 
device, and logs a fatal error.
 
+# Logging
+
+ORT outputs its immediate log to `stdout`, therefore it will log wherever you 
direct it. The recommended system location is `/var/log/ort/ort.log`.
+
+ORT uses the helper tool `atstccfg` to generate config files. Its log is 
output at `/var/log/ort/atstccfg.log`.
+
 # Trivia
 
 ORT stands for "Operational Readiness Test." The acronym is a legacy artifact 
and does not reflect the current purpose, which is to apply configuration from 
Traffic Ops.
diff --git a/traffic_ops/ort/atstccfg/atstccfg.go 
b/traffic_ops/ort/atstccfg/atstccfg.go
index 0a77c62..fb6b453 100644
--- a/traffic_ops/ort/atstccfg/atstccfg.go
+++ b/traffic_ops/ort/atstccfg/atstccfg.go
@@ -74,6 +74,17 @@ func main() {
                os.Exit(0)
        }
 
+       // Because logs will be appended, we want a "start" message, so 
individual runs are easily distinguishable.
+       // log the "start" message to each distinct logger.
+       startMsg := "Starting atstccfg"
+       log.Errorln(startMsg)
+       if cfg.WarningLog() != cfg.ErrorLog() {
+               log.Warnln(startMsg)
+       }
+       if cfg.InfoLog() != cfg.WarningLog() && cfg.InfoLog() != cfg.ErrorLog() 
{
+               log.Infoln(startMsg)
+       }
+
        plugins := plugin.Get(cfg)
        plugins.OnStartup(plugin.StartupData{Cfg: cfg})
 
diff --git a/traffic_ops/ort/build/atstccfg.logrotate 
b/traffic_ops/ort/build/atstccfg.logrotate
new file mode 100644
index 0000000..b461690
--- /dev/null
+++ b/traffic_ops/ort/build/atstccfg.logrotate
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+/var/log/ort/atstccfg.log {
+        compress
+        maxage 30
+        missingok
+        nomail
+        size 10M
+        rotate 5
+        copytruncate
+}
diff --git a/traffic_ops/ort/traffic_ops_ort.pl 
b/traffic_ops/ort/traffic_ops_ort.pl
index 86b8eb8..9805e62 100755
--- a/traffic_ops/ort/traffic_ops_ort.pl
+++ b/traffic_ops/ort/traffic_ops_ort.pl
@@ -167,7 +167,9 @@ if ($rev_proxy_disable != 0) {
 }
 
 my $TMP_BASE  = "/tmp/ort";
-my $atstccfg_log_path = $TMP_BASE . '/atstccfg.log';
+
+my $LOG_BASE  = "/var/log/ort"; # TODO add inferring ORT install location, and 
allowing / vs /opt install
+my $atstccfg_log_path = $LOG_BASE . '/atstccfg.log';
 
 # add any special yum options for your environment here; this variable is used 
with all yum commands
 my $YUM_OPTS = "";
@@ -763,7 +765,7 @@ sub send_update_to_trops {
                $reval_str='true';
        }
 
-       my $response = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null 
--set-queue-status=$upd_str --set-reval-status=$reval_str 2>$atstccfg_log_path`;
+       my $response = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null 
--set-queue-status=$upd_str --set-reval-status=$reval_str 
2>>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $ERROR ) && printf("ERROR sending update status 
with atstccfg (via Traffic Ops). See $atstccfg_log_path.\n");
@@ -773,7 +775,7 @@ sub send_update_to_trops {
 }
 
 sub get_update_status {
-       my $upd_ref = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=update-status 
2>$atstccfg_log_path`;
+       my $upd_ref = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=update-status 
2>>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $ERROR ) && printf("ERROR getting update status 
from atstccfg (via Traffic Ops). See $atstccfg_log_path.\n");
@@ -784,7 +786,7 @@ sub get_update_status {
 
        ##Some versions of Traffic Ops had the 1.3 API but did not have the 
use_reval_pending field.  If this field is not present, exit.
        if ( !defined( $upd_json->{'use_reval_pending'} ) ) {
-               my $info_ref = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=system-info 
2>$atstccfg_log_path`;
+               my $info_ref = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=system-info 
2>>$atstccfg_log_path`;
                my $atstccfg_exit_code = $?;
                if ($atstccfg_exit_code != 0) {
                        ( $log_level >> $ERROR ) && printf("ERROR Unable to get 
status of use_reval_pending parameter.  Stopping.\n");
@@ -839,7 +841,7 @@ sub check_revalidate_state {
                        ( $log_level >> $ERROR ) && print "ERROR Traffic Ops is 
signaling that no revalidations are waiting to be applied.\n";
                }
 
-               my $stj = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=statuses 
2>$atstccfg_log_path`;
+               my $stj = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=statuses 
2>>$atstccfg_log_path`;
                my $atstccfg_exit_code = $?;
                if ( $atstccfg_exit_code != 0 ) {
                        ( $log_level >> $ERROR ) && print "Statuses URL: 
returned $stj! Skipping creation of status file.\n";
@@ -958,7 +960,7 @@ sub check_syncds_state {
                        ( $log_level >> $ERROR ) && print "ERROR Traffic Ops is 
signaling that no update is waiting to be applied.\n";
                }
 
-               my $stj = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=statuses 
2>$atstccfg_log_path`;
+               my $stj = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=statuses 
2>>$atstccfg_log_path`;
                my $atstccfg_exit_code = $?;
                if ( $atstccfg_exit_code != 0 ) {
                        ( $log_level >> $ERROR ) && print "Statuses URL: 
returned $stj! Skipping creation of status file.\n";
@@ -1600,7 +1602,8 @@ sub get_cfg_file_list {
                $atstccfg_reval_arg = '--revalidate-only';
        }
 
-       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$host_name' $atstccfg_reval_arg --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null 2>$atstccfg_log_path`;
+       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$host_name' $atstccfg_reval_arg --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null 2>>$atstccfg_log_path`;
+
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $ERROR ) && printf("ERROR getting config files 
from atstccfg via Traffic Ops. See $atstccfg_log_path for details\n");
@@ -1676,7 +1679,7 @@ sub parse_multipart_config_files {
 sub get_header_comment {
        my $toolname;
 
-       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=system-info 
2>$atstccfg_log_path`;
+       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=system-info 
2>>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                        ( $log_level >> $ERROR ) && printf("ERROR Unable to get 
system info. Stopping.\n");
@@ -1851,7 +1854,7 @@ sub process_packages {
 
        my $proceed = 0;
 
-       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=packages 
2>$atstccfg_log_path`;
+       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=packages 
2>>$atstccfg_log_path`;
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {
                ( $log_level >> $FATAL ) && print "FATAL Error getting package 
list from Traffic Ops!\n";
@@ -2097,7 +2100,7 @@ sub process_chkconfig {
 
        my $proceed = 0;
 
-       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=chkconfig 
2>$atstccfg_log_path`;
+       my $result = `$atstccfg_cmd $atstccfg_timeout_arg 
$atstccfg_arg_disable_proxy --traffic-ops-user='$TO_USER' 
--traffic-ops-password='$TO_PASS' --traffic-ops-url='$TO_URL' 
--cache-host-name='$hostname_short' --log-location-error=stderr 
--log-location-warning=stderr --log-location-info=null --get-data=chkconfig 
2>>$atstccfg_log_path`;
 
        my $atstccfg_exit_code = $?;
        if ($atstccfg_exit_code != 0) {

Reply via email to