Clearing specific kinds of task types using SQL


  • Moderator

    Because a user that doesn’t know MySQL asked me how to do this, I’m putting this little post together.

    Here are all of FOG’s task types, I selected a few specific fields from the taskTypes table in the FOG database:

    MariaDB [fog]> select ttID, ttName,ttDescription from taskTypes;
    +------+-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | ttID | ttName                  | ttDescription                                                                                                                                                                                                                                                                                        |
    +------+-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    |    1 | Deploy                  | Deploy action will send an image saved on the FOG server to the client computer with all included snapins.                                                                                                                                                                                           |
    |    2 | Capture                 | Capture will pull an image from a client computer that will be saved on the server.                                                                                                                                                                                                                  |
    |    3 | Debug                   | Debug mode will load the boot image and load a prompt so you can run any commands you wish. When you are done, you must remember to remove the PXE file, by clicking on "Active Tasks" and clicking on the "Kill Task" button.                                                                       |
    |    4 | Memtest86+              | Memtest86+ loads Memtest86+ on the client computer and will have it continue to run until stopped. When you are done, you must remember to remove the PXE file, by clicking on "Active Tasks" and clicking on the "Kill Task" button.                                                                |
    |    5 | Test Disk               | Test Disk loads the testdisk utility that can be used to check a hard disk and recover lost partitions.                                                                                                                                                                                              |
    |    6 | Disk Surface Test       | Disk Surface Test checks the hard drive's surface sector by sector for any errors and reports back if errors are present.                                                                                                                                                                            |
    |    7 | Recover                 | Recover loads the photorec utility that can be used to recover lost files from a hard disk. When recovering files, make sure you save them to your NFS volume (ie: /images).                                                                                                                         |
    |    8 | Multi-Cast              | Deploy action will send an image saved on the FOG server to the client computer with all included snapins.                                                                                                                                                                                           |
    |   10 | Hardware Inventory      | The hardware inventory task will boot the client computer and pull basic hardware information from it and report it back to the FOG server.                                                                                                                                                          |
    |   11 | Password Reset          | Password reset will blank out a Windows user password that may have been lost or forgotten.                                                                                                                                                                                                          |
    |   12 | All Snapins             | This option allows you to send all the snapins to host without imaging the computer. (Requires FOG Client to be installed on client)                                                                                                                                                                 |
    |   13 | Single Snapin           | This option allows you to send a single snapin to a host. (Requires FOG Client to be installed on client)                                                                                                                                                                                            |
    |   14 | Wake-Up                 | Wake Up will attempt to send the Wake-On-LAN packet to the computer to turn the computer on. In switched environments, you typically need to configure your hardware to allow for this (iphelper).                                                                                                   |
    |   15 | Deploy - Debug          | Deploy - Debug mode allows FOG to setup the environment to allow you send a specific image to a computer, but instead of sending the image, FOG will leave you at a prompt right before sending. If you actually wish to send the image all you need to do is type "fog" and hit enter.              |
    |   16 | Capture - Debug         | Capture - Debug mode allows FOG to setup the environment to allow you capture a specific image from a computer, but instead of capturing the image, FOG will leave you at a prompt right before restoring. If you actually wish to capture the image all you need to do is type "fog" and hit enter. |
    |   17 | Deploy - No Snapins     | Deploy without snapins allows FOG to image the workstation, but after the task is complete any snapins linked to the host or group will NOT be sent.                                                                                                                                                 |
    |   18 | Fast Wipe               | Fast wipe will boot the client computer and wipe the first few sectors of data on the hard disk. Data will not be overwritten but the boot up of the disk and partition layout will no longer exist.                                                                                                 |
    |   19 | Normal Wipe             | Normal Wipe will boot the client computer and perform a simple disk wipe. This method writes one pass of zero's to the hard disk.                                                                                                                                                                    |
    |   20 | Full Wipe               | Full Wipe will boot the client computer and perform a full disk wipe. This method writes a few passes of random data to the hard disk.                                                                                                                                                               |
    |   21 | Virus Scan              | Anti-Virus loads Clam AV on the client boot image, updates the scanner and then scans the Windows partition.                                                                                                                                                                                         |
    |   22 | Virus Scan - Quarantine | Anti-Virus loads Clam AV on the client boot image, updates the scanner and then scans the Windows partition.                                                                                                                                                                                         |
    +------+-------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    

    The way you’d then clear all of any of those task type IDs (the ttID field) is with this SQL query:
    DELETE FROM tasks WHERE taskTypeID = 'x';
    Where x would be the task type ID you’re deleting.

    Most of those standard task types above are tasks that FOG does with FOS or directly with the webserver (like WOL).

    As you see below, power management tasks are stored in a different table, the powerManagement table.

    MariaDB [fog]> describe powerManagement;
    +------------+---------------------------------+------+-----+---------+----------------+
    | Field      | Type                            | Null | Key | Default | Extra          |
    +------------+---------------------------------+------+-----+---------+----------------+
    | pmID       | int(11)                         | NO   | PRI | NULL    | auto_increment |
    | pmHostID   | int(11)                         | NO   | MUL | NULL    |                |
    | pmMin      | varchar(50)                     | NO   |     | NULL    |                |
    | pmHour     | varchar(50)                     | NO   |     | NULL    |                |
    | pmDom      | varchar(50)                     | NO   |     | NULL    |                |
    | pmMonth    | varchar(50)                     | NO   |     | NULL    |                |
    | pmDow      | varchar(50)                     | NO   |     | NULL    |                |
    | pmAction   | enum('shutdown','reboot','wol') | NO   |     | NULL    |                |
    | pmOndemand | enum('0','1')                   | NO   |     | NULL    |                |
    +------------+---------------------------------+------+-----+---------+----------------+
    9 rows in set (0.01 sec)
    

    You can see all power management tasks with this query:
    select * from powerManagement;
    Here’s the output of that command on my test box, which only has one single power management task stored in it:

    MariaDB [fog]> select * from powerManagement;
    +------+----------+-------+--------+-------+---------+-------+----------+------------+
    | pmID | pmHostID | pmMin | pmHour | pmDom | pmMonth | pmDow | pmAction | pmOndemand |
    +------+----------+-------+--------+-------+---------+-------+----------+------------+
    |    1 |        5 | 0     | *      | *     | *       | *     | shutdown | 0          |
    +------+----------+-------+--------+-------+---------+-------+----------+------------+
    1 row in set (0.00 sec)
    

    The last is snapins and are a little more complicated. A single snapin job uses two tables. The tables where the snapin tasks are stored (not to be confused with the snapins themselves) are shown below, with one snapin task pending:

    MariaDB [fog]> select * from snapinJobs;
    +------+----------+-----------+---------------------+
    | sjID | sjHostID | sjStateID | sjCreateTime        |
    +------+----------+-----------+---------------------+
    |    1 |        5 |         1 | 2017-11-09 01:06:18 |
    +------+----------+-----------+---------------------+
    1 row in set (0.00 sec)
    
    MariaDB [fog]> select * from snapinTasks;
    +------+---------+---------+---------------------+---------------------+------------+--------------+-----------------+
    | stID | stJobID | stState | stCheckinDate       | stCompleteDate      | stSnapinID | stReturnCode | stReturnDetails |
    +------+---------+---------+---------------------+---------------------+------------+--------------+-----------------+
    |    1 |       1 |       1 | 2017-11-08 19:06:18 | 0000-00-00 00:00:00 |          2 |            0 |                 |
    +------+---------+---------+---------------------+---------------------+------------+--------------+-----------------+
    1 row in set (0.00 sec)
    

    That’s snapin ID 1 scheduled for an instant deployment to host ID 5. If we wanted to properly clear that task, we’d need to delete both of those entries. Something like this in this case:

    DELETE FROM snapinJobs WHERE sjID = '1';
    DELETE FROM snapinTasks WHERE stID = '1';
    

    Not much more to it than these.
    If you don’t like SQL, there’s always the FOG API, which you can script RESTful curl calls to:
    https://news.fogproject.org/simplified-api-documentation/


Log in to reply
 

430
Online

39.3k
Users

11.0k
Topics

104.4k
Posts

Looks like your connection to FOG Project was lost, please wait while we try to reconnect.