Skip to content
Per Olofsson edited this page Jan 24, 2024 · 13 revisions

Archiving clients is available in MunkiReport 5.4.0 and above.

Archiving a machine is currently limited to the client tab page. A button is available that will archive or unarchive a machine. A Status item was also added to the Summary tab that will show "In use" or "Archived".

Archive Tab View

Archiving a machine will change the status of the archive_status column in the reportdata table. Once a machine checks in again, the status will automatically change to "In use".

Filtering

By default, archived machines are hidden from view. Users must select the filter and choose "Show archived" to view the archived machines along with unarchived. To view only archived machines, choose "Only show archived".

Archive Filter

API archiving endpoints

There are two archiving endpoints that MunkiReport uses internally:

Update status

You need to send a POST request to /archiver/update_status/[serial_number] with a parameter status and a value of 1 to archive and 0 to unarchive

Bulk update status

You need to send a POST request to /archiver/bulk_update_status with a parameter days and a value which is the number of days that the clients have to be inactive to get archived. The minimum number of days is 1.

In the webconsole you can also do

$.post('?/archiver/bulk_update_status', {'days': 30})

Auto-archiving

Currently there is not a built in way to automatically archive machines. An admin can use an event schedule in MySQL or a cronjob. The example scripts archive machines that have not checked in for 30 days.

Example MySQL script:

update reportdata set archive_status = 1
where timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY));

Example SQLite script:

update reportdata set archive_status = 1
where timestamp < strftime('%s','now','-30 days')

Save as archive_machines.sql and then call as a cron job with: (untested)

mysql -uusername -ppassword < /path/to/archive_machines.sql

Example using Event Schedule in MySQL:

SET GLOBAL event_scheduler = ON;

CREATE EVENT archive_machines
ON SCHEDULE EVERY 1 DAY
STARTS '2020-04-30 00:00:00'
DO
update reportdata set archive_status = 1 where timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY)) and archive_status != 1;

See the scheduled event:

mysql> show events

+-------------+------------------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
| Db          | Name             | Definer        | Time zone | Type      | Execute at | Interval value | Interval field | Starts              | Ends | Status  | Originator | character_set_client | collation_connection | Database Collation |
+-------------+------------------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+
| munkireport | archive_machines | root@localhost | SYSTEM    | RECURRING | NULL       | 1              | DAY            | 2020-04-30 00:00:00 | NULL | ENABLED |          0 | utf8                 | utf8_general_ci      | latin1_swedish_ci  |
+-------------+------------------+----------------+-----------+-----------+------------+----------------+----------------+---------------------+------+---------+------------+----------------------+----------------------+--------------------+

Show the content of the archive_machine event:

mysql> show create event archive_machines
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| Event            | sql_mode                                                                                                                                  | time_zone | Create Event                                                                                                                                                                                                                                                      | character_set_client | collation_connection | Database Collation |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| archive_machines | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | SYSTEM    | CREATE DEFINER=`root`@`localhost` EVENT `archive_machines` ON SCHEDULE EVERY 1 DAY STARTS '2020-04-30 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO update reportdata set archive_status = 1 where timestamp < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY)) | utf8                 | utf8_general_ci      | latin1_swedish_ci  |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+

Note that when enabling the event_scheduler, it does not persist through a MySQL restart. You must add event_scheduler=on somewhere under the [mysqld] section of your MySQL conf file (usually /etc/mysql/my.conf).

Clone this wiki locally