cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Tracking Activities and Statistics

No ratings

 

Setup user interfaces and ways to track events

 

GUIDE CONCEPT

 

Being able to view your logs is an important part of knowing what is happening in your system. You can't keep things secure if you don't know who is doing what.

 

These concepts and steps will allow you to focus on development of your application while still allowing the ability to utilize the power of ThingWorx!

 

We will teach you how to access the system in a way you might not have done much of before.

IoTProductMgmt_0-1667411637236.png
 

 

You'll learn how to

 

  • How to design and implement meaningful user interfaces
  • View different logs and search for data

NOTE: This guide's content aligns with ThingWorx 9.3. The estimated time to complete this guide is 30 minutes
 

Step 1: Example and Strategy

 

If you’d like to skip ahead, download the completed example of the Aerospace and Defense learning path attached: AerospaceEntitiesGuide1.zip. Import the .twx files included.

 

In an ever-changing world, you are going to need to protect everything that is considered private. In order to do this, you need to be able to track every bit of what is happening in your system.

ThingWorx does not provide an out of the box method to log when users open a Mashup window. What if this Mashup contains secure documents? Well, we can work with you on getting that logged and tracked.

 

Let us start working on securing our system by adding some Mashups that are simple, but we will add complexity around them. Before designing our Mashups, we will set permissions and go from there. 

 
 

Step 2: Setting Mashup Permissions

We will create a Mashup, but the focus will be the security of the Mashup, not the Design and UI itself. Follow the steps below to get started.

  1. In the ThingWorx Composer, click the + New at the top of the screen.

    select_new.png

  2. Select Mashup  in the dropdown.

create_new_mashup.png

3, Select Responsive for the layout option.

4. Click Ok.

create_mashup_template.png

 

5. Enter a name for the Mashup Template, such as SecureMashupExample.

secure_mashup_example_start.png

 

6. Click Save then click the Permissions tab.

7. On the Visibility tab, in the Search Organization text box, begin typing and select PTCDefenseDepartment. This allows anyone in the organization to be able to access this Mashup. 

 

secure_mashup_example_visibility.png

8. On the Runtime tab, in the Search Users and User Groups text box, begin typing and select Agency.IT.

 9. Set all permissions to Allow (check). This allows a User Group to run services during Runtime of your application. Keep in mind, this gives permissions to all parts of the Mashup (Events, Subscriptions, Services, Parameters).


secure_mashup_example_runtime1.png



10. If you would like to be more specific, in the Search Properties, Services, or Events text box, select a service, ie GetHomeMashup. In the text box that appears below for Users and User Groups, select Agency.HumanResources.

 11. On the Design Time tab, the Search Users and User Groups text box, begin typing and select Agency.IT.

 12. In the Search Users and User Groups text box, begin typing and select Agency.HumanResource.

13. For Agency.IT, set the permissions to allow Read, Update, and Delete. For the Agency.HumanResource User Groups allow Read and deny Update and Delete.

 

secure_mashup_example_design.png

You have just begun the process to securing the application from users looking to view specific secure pages. Next, let's create a simple page and show how we can log who accesses specific pages. 

 

 

Step 3: Designing Tracked Mashups

We will be creating a simple Mashup with the focus of showing how to add logging to a Mashup. Let's start by opening up the Mashup we just created.

 

  1. Open the SecureMashupExample Mashup and click on the Design tab.

  2. Click the Layout panel in the top left and add a Bottom Container.

    secure_mashup_add_layout.png

  3. In the Widgets panel, drag and drop a Blog Widget to the top container.
     

    secure_mashup_add_blog.png

  4. Drag and drop a Web Frame Widget to the bottom container.
     

    secure_mashup_add_frame.png

  5. Select the Blog Widget in the top container. In the Properties panel, update the Blog property to any existing or new Blog entity (there is a Blog in the provided download). 
     

    secure_mashup_set_blog.png

  6. Select the Web Frame Widget in the bottom container. In the Properties panel, update the URL field to a website you trust. In this case, I'll be using https://www.ptc.com/.
     

    secure_mashup_set_frame.png

  7. Click Save and View Mashup.

 

When accessing this Mashup, nothing is logged. We'll be changing that in the next steps with a service that will be called and log who is using the Mashup.

 

  1. In the ThingWorx Composer, click the + New at the top of the screen.
     

    select_new (1).png

  2. Select Thing in the dropdown.
     

    create_new_thing.png

  3. In the name field, enter SecureServices and select GenerticThing as the Base Thing Template.

    new_secure_thing.png

  4. Click Save and go to the Services and Alerts tab.

  5. Click the New button.

  6. Enter LogMashupAccess as the Service name.

    new_log_service.png

     

  7. Click the Input section and add a required String parameter named MashupName. Click Done and Add.
     

    new_log_service_add_param.png

  8. Add a second String parameter named Username that is required. Click Done.

    new_log_service_add_input.png

     

  9. Enter the below lines of code into the canvas. It will be a simple log statement for tracking. We can add a lot more to this method if we liked.
    logger.trace(MashupName  +  " accessed by " + Username);

  10. Click the green Save and Continue button to save your work.
     

    new_log_service_save.png

Add Log Service to Mashup

 

We'll now need to call this logging service to see whenever a user has logged into our secure page. Of course, this is a simplified example and much more could be done here.

  1. Go back to the SecureMashupExample Mashup.

  2. In the Data panel, click the + button to add a service.

    secure_mashup_click_add.png

  3. Search for our new SecureServices Entity, then add the LogMashupAccess service. Ensure the Execute on Load checkbox is checked. 

  4. Click Done.

    secure_mashup_add_service.png

  5. Select the LogMashupAccess service. In the Data Properties panel in the lower right.

  6. In the MashupName text box, enter SecureMashupExample.
     

    secure_mashup_set_name.png

  7. Select the User panel in the top right.

  8. Drag and drop the name field to the Username parameter.

secure_mashup_add_source.png

9. Click Save.

 

You now have a Mashup that will log the UI being opened and the user accessing that UI whenever it is opened. Click View Mashup and go to the ScriptLog in order to test. You filter will need to be set to All or at least Trace to see the log statement.

 

In the next section we'll see how we can test this and do a bit more.

 

 

Step 4: Viewing and Filtering Logs

 

Data logging and filtering is one of your most powerful tools not only in the ThingWorx environment, but in developing solutions. The next section of this learning path will go in depth about what each of these items in a Monitoring screen does. It will also cover tricks to help your search. For now, let's look at how we can view logs and filter them to find what we need.

 

log_view.png
No. ItemUsage 
1 Search Bar Search the log for key words and phrases.
2 Filter Button Provides a list of options to fine tune your search. This menu is very powerful.
3 Log Configurations Select what level of logging you'd like to see.
4 Date Range A date range filter to help limit or set your specific date options.
5 Max Row Count The max number of rows to search for and return. The search will continue until this number is met or your other search filters have been met (ie, date range).
 Apply/Reset Buttons Apply the changes for your date range and max account or reset these values to their defaults.
7 Refresh/Auto Refresh ButtonsAllow the log to continue based on your filters (if any) without you having to refresh. You can also refresh it on your own.
8 Log Header and List The logs that were found based on your filters or settings.
9 Selected Log View After selecting a log item in the list, it will be shown here.

 

The are some tricks to finding what you want and need faster. We dive into that in the next guide in this learning path.

 
 

Step 5: Next Steps

Congratulations! You've successfully completed the Tracking Activities and Stats guide, and learned how to use the ThingWorx Platform to help track what is happening in your application.

 

If you wish to return to the learning path, click Utilizing ThingWorx to Secure Your Aerospace and Defense Systems

 

Learn More

We recommend the following resources to continue your learning experience:

CapabilityGuide
BuildDesign Your Data Model
ManageData Model Implementation Guide

Additional Resources

If you have questions, issues, or need additional information, refer to:

ResourceLink
CommunityDeveloper Community Forum
SupportREST API Help Center

 

Version history
Last update:
‎Nov 16, 2022 04:38 PM
Updated by:
Labels (1)
Attachments
Contributors