• Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
  • Recent
  • Unsolved
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login

How to create a FOG Event?

Scheduled Pinned Locked Moved
General
events hooks 1.5.5
3
12
551
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C
    CWDS @Sebastian Roth
    last edited by Mar 4, 2019, 11:48 PM

    @Sebastian-Roth The file+path is ‘/var/www/html/fog/lib/events/imagecomplete_ds_fw.event.php’

    1 Reply Last reply Reply Quote 0
    • S
      Sebastian Roth Moderator
      last edited by Mar 5, 2019, 6:39 AM

      @CWDS Usually when I don’t get the expected output I start messing around with the code just to make sure it even runs at all. So you might want to change file_put_contents to file_put_contents_does_not_exist and see if you get the expected errors in apache/php-fpm logs (see my signature).

      Beside that I often see that the log file needs to exist for this to work as apache can log to a file but might not have rights to create that file:

      touch ....../ds_fw.log
      chown www-data:www-data ......./ds_fw.log
      

      The user and group name depends on the Linux OS you have. This is specific for Debian.

      Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

      Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

      C 1 Reply Last reply Mar 5, 2019, 6:23 PM Reply Quote 0
      • C
        CWDS @Sebastian Roth
        last edited by Mar 5, 2019, 6:23 PM

        @Sebastian-Roth The extra _ did appear to be preventing it from loading, however, the event does not appear to be firing? I changed the file_put_contents to something that I knew would fail; and it threw an error in /var/log/httpd/ssl_error_log. However, when I fixed it back to file_put_contents (even tried other functions too, echo, print, var_dump), the file loads, but doesnt seem to execute the onEvent call. I even set php error_reporting to E_ALL, and all I get is an unrelated notice. I even changed from file_put_contents to fopen/fwrite/fclose; and attached ‘or die(“Some message”)’ to them, no errors, no messages, no death, no writing to the file either.

        1 Reply Last reply Reply Quote 0
        • S
          Sebastian Roth Moderator
          last edited by Sebastian Roth Mar 5, 2019, 12:54 PM Mar 5, 2019, 6:52 PM

          @CWDS Where/when do you expect the event to trigger? I just tested your code and it wrote to my log file just fine right at the end of an upload task. But be aware the events HOST_LIST_EVENT and HOST_IMAGEUP_COMPLETE don’t exist (anymore). So the only one you can see triggered using your code is the HOST_IMAGE_COMPLETE event fired when a task is finished (deploy, capture, …).

          If you want a full list of events defined in your FOG version use the commands I posted in another thread in our forums.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          C 2 Replies Last reply Mar 5, 2019, 7:00 PM Reply Quote 0
          • C
            CWDS @Sebastian Roth
            last edited by Mar 5, 2019, 7:00 PM

            @Sebastian-Roth Well that would certainly explain why I’m not seeing it then! I was testing using Hosts -> List. I added HOST_LIST_EVENT as a test, so that I wasnt having to do imaging all the time to test it.

            Can you/the rest of the mods/team please update the wiki?! Forum posts are great, but having to search and hope the information is correct kind of sucks. The wiki should be the central knowledge repo, not the forum. I mean, at one point while working with the API, I had to dive into the code in order to find the requirements each endpoint needed. Using an API shouldnt require code diving!

            I did find this list: https://forums.fogproject.org/assets/uploads/files/1545241373509-hooks_and_tie-ins.txt but it references 1.6, not 1.5.5

            T 1 Reply Last reply Mar 5, 2019, 8:07 PM Reply Quote 0
            • C
              CWDS @Sebastian Roth
              last edited by Mar 5, 2019, 7:08 PM

              @Sebastian-Roth Actually, the link I mentioned, doesnt have HOST_IMAGE_COMPLETE listed there. am I looking at the wrong type of things or is this event name changing soon?

              1 Reply Last reply Reply Quote 0
              • S
                Sebastian Roth Moderator
                last edited by Mar 5, 2019, 8:00 PM

                @CWDS said in How to create a FOG Event?:

                Can you/the rest of the mods/team please update the wiki?! Forum posts are great, but having to search and hope the information is correct kind of sucks. The wiki should be the central knowledge repo, not the forum.

                I can understand your frustration but there is just not enough people helping us to improve FOG (including the documentation)! Please get involved and make things better than they are right now.

                Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                1 Reply Last reply Reply Quote 0
                • T
                  Tom Elliott @CWDS
                  last edited by Mar 5, 2019, 8:07 PM

                  @CWDS Hooks and tie in’s are only the “hooks”. It does not go into Events.

                  There’s so little number of events currently (even in 1.6). Compared to hooks, events are simply triggers.

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  C 1 Reply Last reply Mar 8, 2019, 6:48 PM Reply Quote 0
                  • C
                    CWDS @Tom Elliott
                    last edited by CWDS Mar 8, 2019, 12:50 PM Mar 8, 2019, 6:48 PM

                    @Tom-Elliott Thanks, understood.

                    I was able to get my log file test writing out the $data info. I think I’m doing something else wrong now, trying to get the host object based on that data. Ideas?

                        public function onEvent($event, $data)
                        {
                    	$hostData["name"] = $data['HostName'];
                    	$iData = var_export($hostData,true);
                    	$hostObj = new Host($hostData);
                    	$macList = $hostObj->getMyMacs();
                    	$oData = var_export($macList,true);
                    	file_put_contents("/var/www/fog/ds_fw.log",$iData . "\n" . $oData);
                        }
                    }
                    

                    Based on my reading of the code; I can call ‘new Host()’ with an array that gets passed for searching for a host, and in return, I should get a Host object, for that host. I’ve tried every variation in the $hostData[] entry; ‘Name’, ‘name’, ‘hostName’, ‘HostName’.

                    Is there somewhere I can read about how these classes are supposed to act together, or how I’m supposed to actually initiate/call them?

                    (Edit:) - $macList returns an empty array. which leads me to believe I’m calling/loading Host() wrong (thus, my questions)

                    1 Reply Last reply Reply Quote 0
                    • C
                      CWDS
                      last edited by Mar 8, 2019, 9:10 PM

                      Update

                      Still unable to get the MACs from Host(), but I think I’m getting closer. I just dont know what I’m supposed to do with the output of a ->get() call.

                          public function onEvent($event, $data)
                          {
                              $hostData["name"] = $data['HostName'];
                              $iData = var_export($hostData,true);
                              $hostObj = new Host($hostData);
                              $hData = var_export($hostObj,true);
                              $primaryMac = $hostObj->get('primac')->get('mac');
                              $macList = array();
                      
                              foreach ((array)$hostObj->get('additionalMACs') as $ind => &$MAC) {
                                     	$macList[] = $MAC;
                              }
                              $oData1 = var_export($primaryMac,true);
                              $oData2 = var_export($macList,true);
                              file_put_contents("/var/www/fog/ds_fw.log",$iData . "\n" . $hData . "\n" . $oData1 . "\n" . $oData2);
                          }
                      }
                      

                      $primaryMac results in NULL, and $macList results in an empty array. I picked/adjusted the $macList loop from one of the pages code, so that ‘should’ theoretically work, as long as the get()'s actually return data.

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      1 / 1
                      • First post
                        12/12
                        Last post

                      155

                      Online

                      12.0k

                      Users

                      17.3k

                      Topics

                      155.2k

                      Posts
                      Copyright © 2012-2024 FOG Project