8 Best Practices for writing Sensors
If you are reading this article, you should be familiar with Sensor authoring and the Tanium platform.
A class on content authoring (Advanced Content) is available through Tanium; it is highly encouraged for content developers - https://tanium.com/training
For details on how to create a Sensor, check out: Managing sensors (tanium.com)
Examples of parameterized Sensors: Example: Parameterized sensors (tanium.com)
Best practices
There's more to writing a good Tanium Sensor than just writing good code. Here are some best practices to consider whenever you write or evaluate a Sensor:
1. Make it quick. Ideally, a Sensor should be able to run in under 1 second on any system. It should definitely run in under 15 seconds. If your code isn't fast, or it could be slow under some conditions, write a Package or limit where a Sensor can execute (e.g. require the system to have 2 cores).Tip: VBscript is typically faster than Powershell.
2. Sensors query. They don't change the state of the endpoint. Don't change the registry, don't write files. Sensors are not designed to change state on endpoints. That's what Packages are for. Sensors can run multiple times (very quickly) when a question is asked and have short lives (your code will be killed if it runs too long). This makes it a bad candidate to make any change on the endpoint.
3. Do not make network calls. Sensors should not make any network calls (this means HTTP, FTP, ping, traceroute, calls to Active Directory, etc). If you can avoid it, don't call any local service that could be slow to respond either. Code may not seem to make any network connections, but in some conditions it could. This is why testing is important!
4. Do not reach out to remote file systems. If you create a parameterized Sensor, make sure the user can't reference a remote file (think symbolic links and network shares). Imagine what would happen if every endpoint tried to connect to a remote hosted file at the same time!
5. Use best coding practices. In VBScript this means use Option Explicit. It also means commenting your code and providing a meaningful description of what it does. Your colleagues will thank you. Follow your organization's process for good software development (case sensitivity, formatting, comments, error handling, etc).
6. Give your Sensor a good name. <CUSTOMER>-<WHATSENSORDOES> is a good example: AcmeCompany-QueryXYZ. This lets users know that it was developed by your company (not Tanium) and it queries XYZ (whatever that is).
7. Limit data returned (strings). Do you really need to return a timestamp? If not, don't add it. Tanium is lightning fast, but we try to limit how much network bandwidth we consume. The less output your Sensor can generate, the better.
8. Test. No really. Test. I can't believe this is at the bottom. Test your code on multiple types of systems (e.g. domain controllers and file servers). Don't assume that what works well in a few hundred systems is going to behave in the same way when you run it on hundreds of thousands of systems. You will find all manner of variants when you do. Don't move code to production without testing the code thoroughly just as you would with any SDLC. Consider a 4 eyes approach to get validation of content before moving it to production. Follow your organization's process for good software development promotion. When you run this code it will go at the speed of Tanium, so even when you finish testing, roll it out slowly in production. A good approach is to start with smaller or lower risk groups first, and then progressively expand to other groups.
More resources
There is a class for Custom Content. See the Tanium Learning Center Course Catalotg.
-
Coding best practices - while this is outside of this document's scope, reach out to development teams in your company to see what practices they have/require. This can be a good framework for writing code that is used at scale and speed of Tanium.